Skip to content

Commit 8d1c337

Browse files
committed
Merge branch 'master' of https://github.com/SRI-CSL/whole-program-llvm into SRI-CSL-master
2 parents c49a5ca + 6bbb085 commit 8d1c337

File tree

9 files changed

+506
-43
lines changed

9 files changed

+506
-43
lines changed

.travis/apache_clang.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ wget https://archive.apache.org/dist/httpd/httpd-${APACHE_VER}.tar.gz
1212

1313
tar xfz httpd-${APACHE_VER}.tar.gz
1414
mv httpd-${APACHE_VER} apache_clang
15+
1516
cd apache_clang
1617
CC=wllvm ./configure
1718
make

.travis/apache_dragonegg.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ export LLVM_DRAGONEGG_PLUGIN=/usr/lib/gcc/x86_64-linux-gnu/4.6/plugin/dragonegg.
1111

1212
export WLLVM_OUTPUT=WARNING
1313

14-
1514
APACHE_VER=2.4.18
1615
wget https://archive.apache.org/dist/httpd/httpd-${APACHE_VER}.tar.gz
1716

17+
1818
tar xfz httpd-${APACHE_VER}.tar.gz
1919
mv httpd-${APACHE_VER} apache_dragonegg
2020
cd apache_dragonegg

README.md

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,14 @@ utility to read the contents of the dedicated section and link all of
2222
the bitcode into a single whole-program bitcode file. This utility
2323
works for both executable and native libraries.
2424

25-
Currently, WLLVM works with either clang or the gcc dragonegg plugin.
26-
2725
This two-phase build process is necessary to be a drop-in replacement
2826
for gcc or g++ in any build system. Using the LTO framework in gcc
2927
and the gold linker plugin works in many cases, but fails in the
3028
presence of static libraries in builds. WLLVM's approach has the
3129
distinct advantage of generating working binaries, in case some part
3230
of a build process requires that.
3331

32+
WLLVM works with either clang or the gcc dragonegg plugin.
3433

3534
Usage
3635
=====
@@ -40,7 +39,7 @@ and `wllvm++` for C++, and an auxiliary tool `extract-bc`.
4039

4140
Three environment variables must be set to use these wrappers:
4241

43-
* `LLVM_COMPILER` should be set to either 'dragonegg' or 'clang'.
42+
* `LLVM_COMPILER` should be set to either `dragonegg` or `clang`.
4443
* `LLVM_GCC_PREFIX` should be set to the prefix for the version of gcc that should
4544
be used with dragonegg. This can be empty if there is no prefix. This variable is
4645
not used if `$LLVM_COMPILER == clang`.
@@ -50,8 +49,16 @@ Three environment variables must be set to use these wrappers:
5049
Once the environment is set up, just use `wllvm` and `wllvm++` as your C
5150
and C++ compilers, respectively.
5251

52+
5353
In addition to the above environment variables the following can be optionally used:
5454

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+
We also pay attention to the environment variables `LLVM_LINK_NAME` and `LLVM_AR_NAME` in an
60+
analagous way, since they too get adorned with suffixes in various Linux distributions.
61+
5562
* `LLVM_COMPILER_PATH` can be set to the absolute path to the folder that
5663
contains the compiler and other LLVM tools such as `llvm-link` to be used.
5764
This prevents searching for the compiler in your PATH environment variable.
@@ -62,7 +69,7 @@ In addition to the above environment variables the following can be optionally u
6269

6370
* `WLLVM_CONFIGURE_ONLY` can be set to anything. If it is set, `wllvm`
6471
and `wllvm++` behave like a normal C or C++ compiler. They do not
65-
the produce bitcode. Setting `WLLVM_CONFIGURE_ONLY` may prevent
72+
produce bitcode. Setting `WLLVM_CONFIGURE_ONLY` may prevent
6673
configuration errors caused by the unexpected production of hidden
6774
bitcode files.
6875

@@ -80,6 +87,9 @@ Building a bitcode module with clang
8087
# Produces pkg-config.bc
8188
extract-bc pkg-config
8289

90+
A gentler set of instructions on building apache can be found
91+
[here.](https://github.com/SRI-CSL/whole-program-llvm/blob/master/tutorial.md)
92+
8393
Building a bitcode module with dragonegg
8494
========================================
8595

@@ -125,6 +135,23 @@ Configuring without building bitcode
125135
CC=wllvm make
126136

127137

138+
Building a bitcode archive then extracting the bitcode
139+
========================
140+
141+
export LLVM_COMPILER=clang
142+
tar xvfz jansson-2.7.tar.gz
143+
cd jansson-2.7
144+
CC=wllvm ./configure
145+
make
146+
mkdir bitcode
147+
cp src/.libs/libjansson.a bitcode
148+
cd bitcode
149+
extract-bc libjansson.a
150+
llvm-ar x libjansson.bca
151+
ls -la
152+
153+
154+
128155
Debugging
129156
=========
130157

@@ -141,6 +168,18 @@ For example
141168

142169
export WLLVM_OUTPUT=DEBUG
143170

171+
172+
Sanity Checking
173+
=========
174+
175+
Too many environment variables? Try doing a sanity check:
176+
177+
```
178+
wllvm-sanity-checker
179+
```
180+
it might point out what is wrong.
181+
182+
144183
License
145184
=======
146185

driver/utils.py

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@
2525
elfSectionName='.llvm_bc'
2626

2727
# These are the MACH_O segment and section name
28-
darwinSegmentName='__LLVM'
28+
# The SegmentName was __LLVM. Changed to __WLLVM to avoid clashing
29+
# with a segment that ld now uses (since MacOS X 10.11.3?)
30+
darwinSegmentName='__WLLVM'
2931
darwinSectionName='__llvm_bc'
3032

3133

@@ -167,7 +169,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
167169
'-Ofast' : (0, ArgumentListFilter.compileUnaryCallback),
168170
'-Og' : (0, ArgumentListFilter.compileUnaryCallback),
169171
# Component-specifiers
170-
'-Xclang' : (1, ArgumentListFilter.defaultBinaryCallback),
172+
'-Xclang' : (1, ArgumentListFilter.compileBinaryCallback),
171173
'-Xpreprocessor' : (1, ArgumentListFilter.defaultBinaryCallback),
172174
'-Xassembler' : (1, ArgumentListFilter.defaultBinaryCallback),
173175
'-Xlinker' : (1, ArgumentListFilter.defaultBinaryCallback),
@@ -194,6 +196,12 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
194196
# dragonegg mystery argument
195197
'--64' : (0, ArgumentListFilter.compileUnaryCallback),
196198

199+
# binutils nonsense
200+
'-print-multi-directory' : (0, ArgumentListFilter.compileUnaryCallback),
201+
'-print-multi-lib' : (0, ArgumentListFilter.compileUnaryCallback),
202+
'-print-libgcc-file-name' : (0, ArgumentListFilter.compileUnaryCallback),
203+
204+
197205
#
198206
# BD: need to warn the darwin user that these flags will rain on their parade
199207
# (the Darwin ld is a bit single minded)
@@ -215,7 +223,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
215223
#
216224
# Patterns for other command-line arguments:
217225
# - inputFiles
218-
# - objecFiles (suffix .o)
226+
# - objectFiles (suffix .o)
219227
# - libraries + linker options as in -lxxx -Lpath or -Wl,xxxx
220228
# - preprocessor options as in -DXXX -Ipath
221229
# - compiler warning options: -W....
@@ -225,7 +233,7 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
225233
r'^.+\.(c|cc|cpp|C|cxx|i|s|S)$' : (0, ArgumentListFilter.inputFileCallback),
226234
#iam: the object file recogition is not really very robust, object files
227235
# should be determined by their existance and contents...
228-
r'^.+\.(o|lo|So|so|po|a)$' : (0, ArgumentListFilter.objectFileCallback),
236+
r'^.+\.(o|lo|So|so|po|a|dylib)$' : (0, ArgumentListFilter.objectFileCallback),
229237
#iam: library.so.4.5.6 probably need a similar pattern for .dylib too.
230238
r'^.+\.dylib(\.\d)+$' : (0, ArgumentListFilter.objectFileCallback),
231239
r'^.+\.(So|so)(\.\d)+$' : (0, ArgumentListFilter.objectFileCallback),
@@ -237,15 +245,17 @@ def __init__(self, inputList, exactMatches={}, patternMatches={}):
237245
r'^-W(?!l,).*$' : (0, ArgumentListFilter.compileUnaryCallback),
238246
r'^-f.+$' : (0, ArgumentListFilter.compileUnaryCallback),
239247
r'^-std=.+$' : (0, ArgumentListFilter.compileUnaryCallback),
248+
r'^-print-prog-name=.*$' : (0, ArgumentListFilter.compileUnaryCallback),
249+
r'^-print-file-name=.*$' : (0, ArgumentListFilter.compileUnaryCallback),
250+
240251
}
241252

242-
self.inputList = inputList
243-
244253
#iam: try and keep track of the files, input object, and output
254+
self.inputList = inputList
245255
self.inputFiles = []
246256
self.objectFiles = []
247257
self.outputFilename = None
248-
258+
249259
#iam: try and split the args into linker and compiler switches
250260
self.compileArgs = []
251261
self.linkArgs = []
@@ -546,16 +556,24 @@ def getBitcodeFileName(self, argFilter):
546556
class ClangBuilder(BuilderBase):
547557
def __init__(self, cmd, isCxx, prefixPath=None):
548558
super(ClangBuilder, self).__init__(cmd, isCxx, prefixPath)
549-
559+
550560
def getBitcodeCompiler(self):
551561
cc = self.getCompiler()
552562
return cc + ['-emit-llvm']
553563

554564
def getCompiler(self):
555565
if self.isCxx:
556-
return ['{0}clang++'.format(self.prefixPath)]
566+
cxx = os.getenv('LLVM_CXX_NAME')
567+
if cxx:
568+
return ['{0}{1}'.format(self.prefixPath, cxx)]
569+
else:
570+
return ['{0}clang++'.format(self.prefixPath)]
557571
else:
558-
return ['{0}clang'.format(self.prefixPath)]
572+
cc = os.getenv('LLVM_CC_NAME')
573+
if cc:
574+
return ['{0}{1}'.format(self.prefixPath, cc)]
575+
else:
576+
return ['{0}clang'.format(self.prefixPath)]
559577

560578
def getBitcodeArglistFilter(self):
561579
return ClangBitcodeArgumentListFilter(self.cmd)
@@ -569,7 +587,6 @@ def attachBitcode(self, argFilter):
569587
outFile = argFilter.getOutputFilename()
570588
attachBitcodePathToObject(bcname, outFile)
571589

572-
#iam: this should join the dodo soon, yes?
573590
class DragoneggBuilder(BuilderBase):
574591
def __init__(self, cmd, isCxx, prefixPath=None):
575592
super(DragoneggBuilder, self).__init__(cmd, isCxx, prefixPath)

0 commit comments

Comments
 (0)