|
| 1 | +Introduction |
| 2 | +============ |
| 3 | + |
| 4 | +This project, WLLVM, provides tools for building whole-program (or |
| 5 | +whole-library) LLVM bitcode files from an unmodified C or C++ |
| 6 | +source package. It currently runs on `*nix` platforms such as Linux, |
| 7 | +FreeBSD, and Mac OS X. |
| 8 | + |
| 9 | +WLLVM provides python-based compiler wrappers that work in two |
| 10 | +steps. The wrappers first invoke the compiler as normal. Then, for |
| 11 | +each object file, they call a bitcode compiler to produce LLVM |
| 12 | +bitcode. The wrappers also store the location of the generated bitcode |
| 13 | +file in a dedicated section of the object file. When object files are |
| 14 | +linked together, the contents of the dedicated sections are |
| 15 | +concatenated (so we don't lose the locations of any of the constituent |
| 16 | +bitcode files). After the build completes, one can use an WLLVM |
| 17 | +utility to read the contents of the dedicated section and link all of |
| 18 | +the bitcode into a single whole-program bitcode file. This utility |
| 19 | +works for both executable and native libraries. |
| 20 | + |
| 21 | +This two-phase build process is necessary to be a drop-in replacement |
| 22 | +for gcc or g++ in any build system. Using the LTO framework in gcc |
| 23 | +and the gold linker plugin works in many cases, but fails in the |
| 24 | +presence of static libraries in builds. WLLVM's approach has the |
| 25 | +distinct advantage of generating working binaries, in case some part |
| 26 | +of a build process requires that. |
| 27 | + |
| 28 | +WLLVM works with either clang or the gcc dragonegg plugin. |
| 29 | + |
| 30 | +Tutorial |
| 31 | +==== |
| 32 | + |
| 33 | +See the tutorial markdown files for detailed instructions on how to compile apache with wllvm on Ubuntu. |
| 34 | + |
| 35 | +Usage |
| 36 | +===== |
| 37 | + |
| 38 | +WLLVM includes two python executables: `wllvm` for compiling C code |
| 39 | +and `wllvm++` for C++, and an auxiliary tool `extract-bc`. |
| 40 | + |
| 41 | +Three environment variables must be set to use these wrappers: |
| 42 | + |
| 43 | + * `LLVM_COMPILER` should be set to either `dragonegg` or `clang`. |
| 44 | + * `LLVM_GCC_PREFIX` should be set to the prefix for the version of gcc that should |
| 45 | + be used with dragonegg. This can be empty if there is no prefix. This variable is |
| 46 | + not used if `$LLVM_COMPILER == clang`. |
| 47 | + * `LLVM_DRAGONEGG_PLUGIN` should be the full path to the dragonegg plugin. This |
| 48 | + variable is not used if `$LLVM_COMPILER == clang`. |
| 49 | + |
| 50 | +Once the environment is set up, just use `wllvm` and `wllvm++` as your C |
| 51 | +and C++ compilers, respectively. |
| 52 | + |
| 53 | + |
| 54 | +In addition to the above environment variables the following can be optionally used: |
| 55 | + |
| 56 | + * `LLVM_CC_NAME` can be set if your clang compiler is not called `clang` but |
| 57 | + something like `clang-3.7`. Similarly `LLVM_CXX_NAME` can be used to describe |
| 58 | + what the C++ compiler is called. Note that in these sorts of cases, the environment |
| 59 | + variable `LLVM_COMPILER` should still be set to `clang` not `clang-3.7` etc. |
| 60 | + We also pay attention to the environment variables `LLVM_LINK_NAME` and `LLVM_AR_NAME` in an |
| 61 | + analagous way, since they too get adorned with suffixes in various Linux distributions. |
| 62 | + |
| 63 | + * `LLVM_COMPILER_PATH` can be set to the absolute path to the folder that |
| 64 | + contains the compiler and other LLVM tools such as `llvm-link` to be used. |
| 65 | + This prevents searching for the compiler in your PATH environment variable. |
| 66 | + This can be useful if you have different versions of clang on your system |
| 67 | + and you want to easily switch compilers without tinkering with your PATH |
| 68 | + variable. |
| 69 | + Example `LLVM_COMPILER_PATH=/home/user/llvm_and_clang/Debug+Asserts/bin`. |
| 70 | + |
| 71 | +* `WLLVM_CONFIGURE_ONLY` can be set to anything. If it is set, `wllvm` |
| 72 | + and `wllvm++` behave like a normal C or C++ compiler. They do not |
| 73 | + produce bitcode. Setting `WLLVM_CONFIGURE_ONLY` may prevent |
| 74 | + configuration errors caused by the unexpected production of hidden |
| 75 | + bitcode files. |
| 76 | + |
| 77 | + |
0 commit comments