Skip to content

Commit 83b89ac

Browse files
committed
Merge.
2 parents 5414f1e + 308c719 commit 83b89ac

25 files changed

+855
-136
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
*.pyc
2+
.idea

.travis.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
language: python
2+
python:
3+
- "3.3"
4+
- "2.7"
5+
- "2.6"
6+
7+
# command to install dependencies
8+
install:
9+
- sudo apt-get update
10+
- sudo apt-get install llvm-3.4 clang-3.4 libapr1-dev libaprutil1-dev
11+
- sudo apt-get install dragonegg llvm-3.0 llvm-gcc
12+
- export WLLVM_HOME=`pwd`
13+
14+
# command to run tests
15+
script:
16+
# build apache with clang (i.e. httpd-2.4.12)
17+
- ${WLLVM_HOME}/.travis/apache_clang.sh
18+
# build apache with gcc and dragonegg (i.e. httpd-2.4.12)
19+
- ${WLLVM_HOME}/.travis/apache_dragonegg.sh
20+
21+

.travis/apache_clang.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/bin/bash -x
2+
# Make sure we exit if there is a failure
3+
set -e
4+
5+
6+
export PATH=/usr/lib/llvm-3.4/bin:${WLLVM_HOME}:${PATH}
7+
export LLVM_COMPILER=clang
8+
export WLLVM_OUTPUT=WARNING
9+
10+
wget http://www.csl.sri.com/~iam/httpd-2.4.12.tar.gz
11+
tar xfz httpd-2.4.12.tar.gz
12+
mv httpd-2.4.12 apache_clang
13+
cd apache_clang
14+
CC=wllvm ./configure
15+
make
16+
extract-bc httpd
17+
18+
19+
if [ -s "httpd.bc" ]
20+
then
21+
echo "httpd.bc built."
22+
else
23+
exit 1
24+
fi
25+
26+
27+
28+
29+
30+

.travis/apache_dragonegg.sh

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/bin/bash -x
2+
# Make sure we exit if there is a failure
3+
set -e
4+
5+
export dragonegg_disable_version_check=true
6+
7+
export PATH=/usr/lib/llvm-3.0/bin:${WLLVM_HOME}:${PATH}
8+
export LLVM_COMPILER=dragonegg
9+
export LLVM_GCC_PREFIX=llvm-
10+
export LLVM_DRAGONEGG_PLUGIN=/usr/lib/gcc/x86_64-linux-gnu/4.6/plugin/dragonegg.so
11+
12+
export WLLVM_OUTPUT=WARNING
13+
14+
wget http://www.csl.sri.com/~iam/httpd-2.4.12.tar.gz
15+
tar xfz httpd-2.4.12.tar.gz
16+
mv httpd-2.4.12 apache_dragonegg
17+
cd apache_dragonegg
18+
CC=wllvm ./configure
19+
make
20+
extract-bc httpd
21+
22+
23+
if [ -s "httpd.bc" ]
24+
then
25+
echo "httpd.bc built."
26+
else
27+
exit 1
28+
fi
29+
30+
31+
32+
33+
34+

NOTES.txt

Lines changed: 0 additions & 23 deletions
This file was deleted.

README-freeBSD.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ to your shell startup (in '~/.profile' for bash):
6767

6868
export LLVM_HOME=/usr/local/llvm-3.3
6969

70-
Get LLVM and Clang version 3.5:
70+
Get LLVM and Clang version 3.3:
7171

7272
svn co http://llvm.org/svn/llvm-project/llvm/branches/release_33 llvm
7373
cd llvm/tools

README.md

Lines changed: 111 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,62 @@
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+
15
Introduction
26
============
37

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.
3033

3134
Usage
3235
=====
3336

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`.
3639

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`.
3843
* `LLVM_GCC_PREFIX` should be set to the prefix for the version of gcc that should
3944
be used with dragonegg. This can be empty if there is no prefix. This variable is
4045
not used if `$LLVM_COMPILER == clang`.
4146
* `LLVM_DRAGONEGG_PLUGIN` should be the full path to the dragonegg plugin. This
4247
variable is not used if `$LLVM_COMPILER == clang`.
4348

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
4550
and C++ compilers, respectively.
4651

52+
4753
In addition to the above environment variables the following can be optionally used:
4854

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+
4960
* `LLVM_COMPILER_PATH` can be set to the absolute path to the folder that
5061
contains the compiler and other LLVM tools such as `llvm-link` to be used.
5162
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
5465
variable.
5566
Example `LLVM_COMPILER_PATH=/home/user/llvm_and_clang/Debug+Asserts/bin`.
5667

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+
========================================
5993

6094
export LLVM_COMPILER=dragonegg
6195
export LLVM_GCC_PREFIX=llvm-
@@ -69,8 +103,9 @@ Example building bitcode module
69103
# Produces pkg-config.bc
70104
extract-bc pkg-config
71105

72-
Example building bitcode archive
73-
================================
106+
107+
Building bitcode archive
108+
========================
74109

75110
export LLVM_COMPILER=clang
76111
tar -xvf bullet-2.81-rev2613.tgz
@@ -82,11 +117,38 @@ Example building bitcode archive
82117
# Produces src/LinearMath/libLinearMath.bca
83118
extract-bc src/LinearMath/libLinearMath.a
84119

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
86129
================================
87130

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+
90152

91153
Debugging
92154
=========
@@ -104,6 +166,18 @@ For example
104166

105167
export WLLVM_OUTPUT=DEBUG
106168

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+
107181
License
108182
=======
109183

driver/as

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
# (which was created in the first compilation phase by the real
1111
# compiler). We'll link this together at a later stage.
1212

13-
import os
13+
from __future__ import absolute_import
1414
import sys
15-
from utils import *
15+
import os
16+
17+
sys.path.append(os.path.dirname(os.path.dirname(os.path.realpath(__file__))))
18+
19+
from driver.utils import *
1620
from subprocess import *
17-
from popenwrapper import Popen
18-
import logconfig
21+
from driver.popenwrapper import Popen
1922

23+
import logging
24+
logging.basicConfig()
2025

2126
class BCFilter(ArgumentListFilter):
2227
def __init__(self, arglist):
@@ -48,18 +53,15 @@ except AttributeError as e:
4853
logging.error('Output file argument not found.\nException message: ' + str(e))
4954
sys.exit(1)
5055

51-
bcfilename = '.{0}.bc'.format(filename)
52-
bcPath = os.path.join(dirs, bcfilename)
53-
fakeAssembler = [llvmAssembler, infile, '-o', bcPath]
56+
fakeAssembler = [llvmAssembler, infile, '-o', argFilter.outFileName]
57+
5458
asmProc = Popen(fakeAssembler)
5559
realRet = asmProc.wait()
5660

5761
if realRet != 0:
5862
logging.error('llvm-as failed')
5963
sys.exit(realRet)
6064

61-
attachBitcodePathToObject(bcPath, argFilter.outFileName)
62-
6365
sys.exit(realRet)
6466

6567

0 commit comments

Comments
 (0)