1
+
2
+ [ ![ Build Status] ( https://travis-ci.org/SRI-CSL/whole-program-llvm.svg?branch=master )] ( https://travis-ci.org/SRI-CSL/whole-program-llvm )
3
+
4
+
1
5
Introduction
2
6
============
3
7
4
- This is a small python-based wrapper around a GCC-compatible compiler
5
- to make it easy to build whole-program (or whole-library) LLVM bitcode
6
- files. The idea is that it first invokes the compiler as normal to
7
- build a real object file. It then invokes a bitcode compiler to
8
- generate the corresponding bitcode, recording the location of the
9
- bitcode file in an ELF section of the actual object file.
10
-
11
- When object files are linked together, the contents of non-special ELF
12
- sections are just concatenated (so we don't lose the locations of any
13
- of the constituent bitcode files).
14
-
15
- This package contains an extra utility, extract-bc, to read the
16
- contents of this ELF section and link all of the bitcode into a single
17
- whole-program bitcode file. This utility can also be used on built
18
- native static libraries to generate LLVM bitcode archives.
19
-
20
- This two-phase build process is slower and more elaborate than normal,
21
- but in practice is necessary to be a drop-in replacement for gcc in
22
- any build system. Approaches using the LTO framework in gcc and the
23
- gold linker plugin work for many cases, but fail in the presence of
24
- static libraries in builds. This approach has the distinct advantage
25
- of generating working binaries, in case some part of a build process
26
- actually requires that.
27
-
28
- Currently, this package only works using clang or the dragonegg plugin
29
- with gcc 4.5 (with the required patch for dragonegg).
8
+ This project, WLLVM, provides tools for building whole-program (or
9
+ whole-library) LLVM bitcode files from an unmodified C or C++
10
+ source package. It currently runs on ` *nix ` platforms such as Linux,
11
+ FreeBSD, and Mac OS X.
12
+
13
+ WLLVM provides python-based compiler wrappers that work in two
14
+ steps. The wrappers first invoke the compiler as normal. Then, for
15
+ each object file, they call a bitcode compiler to produce LLVM
16
+ bitcode. The wrappers also store the location of the generated bitcode
17
+ file in a dedicated section of the object file. When object files are
18
+ linked together, the contents of the dedicated sections are
19
+ concatenated (so we don't lose the locations of any of the constituent
20
+ bitcode files). After the build completes, one can use an WLLVM
21
+ utility to read the contents of the dedicated section and link all of
22
+ the bitcode into a single whole-program bitcode file. This utility
23
+ works for both executable and native libraries.
24
+
25
+ This two-phase build process is necessary to be a drop-in replacement
26
+ for gcc or g++ in any build system. Using the LTO framework in gcc
27
+ and the gold linker plugin works in many cases, but fails in the
28
+ presence of static libraries in builds. WLLVM's approach has the
29
+ distinct advantage of generating working binaries, in case some part
30
+ of a build process requires that.
31
+
32
+ WLLVM works with either clang or the gcc dragonegg plugin.
30
33
31
34
Usage
32
35
=====
33
36
34
- There are three environment variables that must be set to use this
35
- wrapper script:
37
+ WLLVM includes two python executables: ` wllvm ` for compiling C code
38
+ and ` wllvm++ ` for C++, and an auxiliary tool ` extract-bc ` .
36
39
37
- * ` LLVM_COMPILER ` should be set to 'dragonegg' or 'clang'.
40
+ Three environment variables must be set to use these wrappers:
41
+
42
+ * ` LLVM_COMPILER ` should be set to either ` dragonegg ` or ` clang ` .
38
43
* ` LLVM_GCC_PREFIX ` should be set to the prefix for the version of gcc that should
39
44
be used with dragonegg. This can be empty if there is no prefix. This variable is
40
45
not used if ` $LLVM_COMPILER == clang ` .
41
46
* ` LLVM_DRAGONEGG_PLUGIN ` should be the full path to the dragonegg plugin. This
42
47
variable is not used if ` $LLVM_COMPILER == clang ` .
43
48
44
- Once the environment is set up, just use wllvm and wllvm++ as your C
49
+ Once the environment is set up, just use ` wllvm ` and ` wllvm++ ` as your C
45
50
and C++ compilers, respectively.
46
51
52
+
47
53
In addition to the above environment variables the following can be optionally used:
48
54
55
+ * ` LLVM_CC_NAME ` can be set if your clang compiler is not called ` clang ` but
56
+ something like ` clang-3.7 ` . Similarly ` LLVM_CXX_NAME ` can be used to describe
57
+ what the C++ compiler is called. Note that in these sorts of cases, the environment
58
+ variable ` LLVM_COMPILER ` should still be set to ` clang ` not ` clang-3.7 ` etc.
59
+
49
60
* ` LLVM_COMPILER_PATH ` can be set to the absolute path to the folder that
50
61
contains the compiler and other LLVM tools such as ` llvm-link ` to be used.
51
62
This prevents searching for the compiler in your PATH environment variable.
@@ -54,8 +65,31 @@ In addition to the above environment variables the following can be optionally u
54
65
variable.
55
66
Example ` LLVM_COMPILER_PATH=/home/user/llvm_and_clang/Debug+Asserts/bin ` .
56
67
57
- Example building bitcode module
58
- ===============================
68
+ * ` WLLVM_CONFIGURE_ONLY ` can be set to anything. If it is set, ` wllvm `
69
+ and ` wllvm++ ` behave like a normal C or C++ compiler. They do not
70
+ produce bitcode. Setting ` WLLVM_CONFIGURE_ONLY ` may prevent
71
+ configuration errors caused by the unexpected production of hidden
72
+ bitcode files.
73
+
74
+
75
+ Building a bitcode module with clang
76
+ ====================================
77
+
78
+ export LLVM_COMPILER=clang
79
+
80
+ tar xf pkg-config-0.26.tar.gz
81
+ cd pkg-config-0.26
82
+ CC=wllvm ./configure
83
+ make
84
+
85
+ # Produces pkg-config.bc
86
+ extract-bc pkg-config
87
+
88
+ A gentler set of instructions on building apache can be found
89
+ [ here.] ( https://github.com/SRI-CSL/whole-program-llvm/blob/master/tutorial.md )
90
+
91
+ Building a bitcode module with dragonegg
92
+ ========================================
59
93
60
94
export LLVM_COMPILER=dragonegg
61
95
export LLVM_GCC_PREFIX=llvm-
@@ -69,8 +103,9 @@ Example building bitcode module
69
103
# Produces pkg-config.bc
70
104
extract-bc pkg-config
71
105
72
- Example building bitcode archive
73
- ================================
106
+
107
+ Building bitcode archive
108
+ ========================
74
109
75
110
export LLVM_COMPILER=clang
76
111
tar -xvf bullet-2.81-rev2613.tgz
@@ -82,11 +117,38 @@ Example building bitcode archive
82
117
# Produces src/LinearMath/libLinearMath.bca
83
118
extract-bc src/LinearMath/libLinearMath.a
84
119
85
- Example building an Operating System
120
+
121
+ Building an Operating System
122
+ ============================
123
+
124
+ To see how to build freeBSD 10.0 from scratch check out this
125
+ [ guide.] ( ../master/README-freeBSD.md )
126
+
127
+
128
+ Configuring without building bitcode
86
129
================================
87
130
88
- To see how to build freeBSD 10.0 from scratch check out the guide
89
- [ here.] ( ../master/README-freeBSD.md )
131
+
132
+ WLLVM_CONFIGURE_ONLY=1 CC=wllvm ./configure
133
+ CC=wllvm make
134
+
135
+
136
+ Building a bitcode archive then extracting the bitcode
137
+ ========================
138
+
139
+ export LLVM_COMPILER=clang
140
+ tar xvfz jansson-2.7.tar.gz
141
+ cd jansson-2.7
142
+ CC=wllvm ./configure
143
+ make
144
+ mkdir bitcode
145
+ cp src/.libs/libjansson.a bitcode
146
+ cd bitcode
147
+ extract-bc libjansson.a
148
+ llvm-ar x libjansson.bca
149
+ ls -la
150
+
151
+
90
152
91
153
Debugging
92
154
=========
@@ -104,6 +166,18 @@ For example
104
166
105
167
export WLLVM_OUTPUT=DEBUG
106
168
169
+
170
+ Sanity Checking
171
+ =========
172
+
173
+ Too many environment variables? Try doing a sanity check:
174
+
175
+ ```
176
+ wllvm-sanity-checker
177
+ ```
178
+ it might point out what is wrong.
179
+
180
+
107
181
License
108
182
=======
109
183
0 commit comments