|
| 1 | +Steps to build bitcode version of FreeBSD 10.0 world and kernel |
| 2 | +----------------------------------------------- |
| 3 | + |
| 4 | +The following instructions have been tested with FreeBSD 10.0 amd64. |
| 5 | + |
| 6 | +-- Prerequisites: -------------------------------------------------------------- |
| 7 | + |
| 8 | +1. FreeBSD |
| 9 | + |
| 10 | +The ideal way to start is with a clean install of FreeBSD 10.0 with |
| 11 | +sources installed. The simplest way to do this is to install from the |
| 12 | +Release 10.0 ISO image and and on the "Distribution Select" screen |
| 13 | +select just the following: |
| 14 | + |
| 15 | + [*] ports Ports tree |
| 16 | + [*] src System source code |
| 17 | + |
| 18 | +If you are on an existing system that has either an old version of the |
| 19 | +source tree or is missing source, you can follow the instructions in the |
| 20 | +FreeBSD Handbook Chapter 24 to get the relevant sources. |
| 21 | + |
| 22 | +2. Necessary ports |
| 23 | + |
| 24 | +Upgrade the ports collection (as 'root'): |
| 25 | + |
| 26 | + su - |
| 27 | + portsnap fetch |
| 28 | + portsnap extract |
| 29 | + cd /usr/ports/ports-mgmt/portupgrade |
| 30 | + make -DBATCH install clean |
| 31 | + portupgrade -a --batch |
| 32 | + |
| 33 | +Install the following ports using the BSD port tree: |
| 34 | + |
| 35 | + bash git subversion python27 sudo wget |
| 36 | + |
| 37 | +(See the FreeBSD Handbook Chapter 5 for instructions.) |
| 38 | +The quick way to do this is: |
| 39 | + |
| 40 | + su - |
| 41 | + cd /usr/ports |
| 42 | + cd shells/bash && make -DBATCH install clean && \ |
| 43 | + cd ../../devel/git && make -DBATCH install clean && \ |
| 44 | + cd ../../devel/subversion && make -DBATCH install clean && \ |
| 45 | + cd ../../security/sudo && make -DBATCH install clean && \ |
| 46 | + cd ../../ftp/wget && make -DBATCH install clean |
| 47 | + |
| 48 | +(Python27 is installed as a prerequisite of Subversion.) |
| 49 | + |
| 50 | +Below we assume the shell being used is bash, that is: |
| 51 | + |
| 52 | + chsh -s /usr/local/bin/bash |
| 53 | + |
| 54 | +has been run. If you want to use another shell, replace bash-isms like |
| 55 | +'export' with the appropriate equivalent. |
| 56 | + |
| 57 | +We suggest installing 'sudo' and setting up your account as a sudoer, to |
| 58 | +make installing programs easier. You can do this, or modify the commands |
| 59 | +that use 'sudo' below. |
| 60 | + |
| 61 | +3. LLVM and Clang 3.3 |
| 62 | + |
| 63 | +Install LLVM and Clang version 3.3. (These instructions adapted from |
| 64 | +http://llvm.org/docs/GettingStarted.html) Decide where you want to |
| 65 | +install LLVM. If you have 'root' access, you can use the default |
| 66 | +'/usr/local', though any location is fine. You may then wish to add this |
| 67 | +to your shell startup (in '~/.profile' for bash): |
| 68 | + |
| 69 | + export LLVM_HOME=/usr/local/llvm-3.3 |
| 70 | + |
| 71 | +Get LLVM and Clang version 3.5: |
| 72 | + |
| 73 | + svn co http://llvm.org/svn/llvm-project/llvm/branches/release_33 llvm |
| 74 | + cd llvm/tools |
| 75 | + svn co http://llvm.org/svn/llvm-project/cfe/branches/release_33 clang |
| 76 | + cd ../projects |
| 77 | + svn co http://llvm.org/svn/llvm-project/compiler-rt/branches/release_33 compiler-rt |
| 78 | + cd ../.. |
| 79 | + |
| 80 | +Now finish the build and install: |
| 81 | + |
| 82 | + cd llvm |
| 83 | + mkdir build |
| 84 | + cd build |
| 85 | + ../configure --prefix=$LLVM_HOME --enable-assertions \ |
| 86 | + --enable-targets=host-only --enable-optimized |
| 87 | + gmake |
| 88 | + sudo gmake install |
| 89 | + |
| 90 | +Note that the FreeBSD 10.0 base includes Clang 3.3 (but does not include |
| 91 | +the complete LLVM framework, in particular llvm-link is not included). |
| 92 | + |
| 93 | +So to make life easier, so that extract-bc can find it do: |
| 94 | + |
| 95 | + sudo ln -s $LLVM_HOME/bin/llvm-link /usr/bin/llvm-link |
| 96 | + |
| 97 | + |
| 98 | +1. Download SRI-modified version of WLLVM. |
| 99 | + |
| 100 | +> cd ${HOME} |
| 101 | +> git clone https://github.com/SRI-CSL/whole-program-llvm |
| 102 | +
|
| 103 | +2. Create the hooks for interposing on compiler calls. |
| 104 | + |
| 105 | +> cd ${HOME} |
| 106 | +> mkdir ${HOME}/wllvm.bin |
| 107 | +> cd wllvm.bin |
| 108 | +> ln -s ${HOME}/whole-program-llvm/wllvm cc |
| 109 | +> ln -s ${HOME}/whole-program-llvm/wllvm++ c++ |
| 110 | +> ln -s ${HOME}/whole-program-llvm/wllvm clang |
| 111 | +> ln -s ${HOME}/whole-program-llvm/wllvm++ clang++ |
| 112 | +this next one is a hack (make buildworld doesn't find python with /usr/bin/env without it) |
| 113 | +> ln -s /usr/local/bin/python python |
| 114 | +
|
| 115 | +3. Insert the hooks into the build path. |
| 116 | + |
| 117 | +> diff /usr/src/Makefile.inc1 Makefile.inc1.original |
| 118 | +180c180 |
| 119 | +< BPATH= ${HOME}/wllvm.bin:${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games:${WORLDTMP}/legacy/bin |
| 120 | +--- |
| 121 | +> BPATH= ${WORLDTMP}/legacy/usr/sbin:${WORLDTMP}/legacy/usr/bin:${WORLDTMP}/legacy/usr/games:${WORLDTMP}/legacy/bin |
| 122 | +
|
| 123 | +4. If the build location doesn't exist, create it. |
| 124 | + |
| 125 | +> mkdir ${HOME}/build.world |
| 126 | +
|
| 127 | +5. Configure the environment for the build. |
| 128 | + |
| 129 | +> export MAKEOBJDIRPREFIX=${HOME}/build.world |
| 130 | +> export LLVM_COMPILER=clang |
| 131 | +> export LLVM_COMPILER_PATH=/usr/bin |
| 132 | +> export WLLVM_OUTPUT=DEBUG |
| 133 | +
|
| 134 | +6. Start the build. |
| 135 | + |
| 136 | +> cd /usr/src |
| 137 | +> make buildworld |
| 138 | +
|
| 139 | +7. Once that succeeds build the kernel |
| 140 | + |
| 141 | +> make buildkernel |
| 142 | +
|
| 143 | + |
| 144 | +8. extract the bitcode: |
| 145 | + |
| 146 | + |
| 147 | +cd ${MAKEOBJDIRPREFIX}/usr/src/sys/GENERIC |
| 148 | + |
| 149 | +> ${HOME}/whole-program-llvm/extract-bc kernel |
| 150 | +
|
| 151 | +> nm kernel | wc |
| 152 | + 53140 159418 2421852 |
| 153 | + |
| 154 | +> ${LLVM_HOME}/bin/llvm-nm kernel.bc | wc |
| 155 | + 50664 101328 1910997 |
| 156 | + |
| 157 | +We are working on seeing if we can get these numbers to match. |
| 158 | +But suspect their is some assembler causing this difference. |
| 159 | + |
| 160 | + |
0 commit comments