Compile bitcode file using wllvm gclang - SVF-tools/SVF GitHub Wiki
Option 1. Install gllvm
Create a ubuntu docker first.
Install the go tool 1.16 and then install gllvm
-
wget https://go.dev/dl/go1.16.15.linux-amd64.tar.gz
-
rm -rf /usr/local/go && tar -C /usr/local -xzf go1.16.15.linux-amd64.tar.gz
-
export PATH=$PATH:/usr/local/go/bin
-
go version
-
GO111MODULE=off go get github.com/SRI-CSL/gllvm/cmd/...
After this, we have the gllvm commands including gclang
, gclang++
, get-bc
, gsanity-check
under the /root/go/bin/
check env
Run export LLVM_COMPILER_PATH=$SVF_INSTALL_LLVM_14/bin
to set the llvm path to LLVM14 that SVF installs and run gsanity-check
to confirm the enviroment.
Option 2. Install wllvm
pip install wllvm
After this, we have the wllvm commands including wllvm
, wllvm++
, extract-bc
, wllvm-sanity-checker
check env
Run export LLVM_COMPILER=clang
to set the compiler. If we need a deferent version of LLVM, run export LLVM_CC_NAME=clang-9
, export LLVM_CXX_NAME=clang-9++
, export LLVM_LINK_NAME=llvm-link-9
, export LLVM_AR_NAME=llvm-ar-9
for example the version is llvm-9.
Finally, run wllvm-sanity-checker
to confirm the enviroment.
3. compile bc
When compiling a source code, we need to set CC=gclang
or CXX=gclang++
. For example, CC=gclang make
For wllvm, change to CC=wllvm
or CXX=wllvm++
https://github.com/RIOT-OS/RIOT
4. RIOT examplegit clone https://github.com/RIOT-OS/RIOT
cd RIOT/examples/default/
make CC="gclang -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" CXX="gclang++ -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" -j8
cd bin/native/
get-bc default.elf
we get the default.elf.bc at this step.
llvm-dis default.elf.bc
if readable ll is needed.
https://github.com/enzo1982/mp4v2/
5. mp4v2 example version v2.1.3wget https://github.com/enzo1982/mp4v2/archive/refs/tags/v2.1.3.tar.gz
tar -xzvf v2.1.3.tar.gz
cd mp4v2-2.1.3
mkdir build && cd build
CC="wllvm -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" CXX="wllvm++ -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" cmake ../
make -j12
extract-bc mp4art && extract-bc mp4extract && extract-bc mp4file && extract-bc mp4subtitle && extract-bc mp4track
https://github.com/tmux/tmux
6. tmux version 3.3awget https://github.com/tmux/tmux/archive/refs/tags/3.3a.tar.gz
tar -xzvf 3.3a.tar.gz
cd tmux-3.3a/
sh autogen.sh
CC="wllvm -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" CXX="wllvm++ -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" ./configure
make -j12
https://github.com/emqx/nanomq
7. NanoMQ version 0.17.2wget https://github.com/emqx/nanomq/archive/refs/tags/0.17.2.tar.gz
tar -xzvf 0.17.2.tar.gz
cd nanomq-0.17.2/nng/
git clone https://github.com/nanomq/NanoNNG.git
cd NanoNNG/ && git checkout 0.17.2
cmake ./
make -j12
mv * ../
mkdir ../../build && cd ../../build
CC="wllvm -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" CXX="wllvm++ -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" cmake ../
make -j12
extract-bc nanomq/nanomq
extract-bc nanomq_cli/nanomq_cli
https://github.com/redis/redis/
8. redis version 7.0.11wget https://github.com/redis/redis/archive/refs/tags/7.0.11.tar.gz
tar -xzvf 7.0.11.tar.gz
cd redis-7.0.11/
CC="wllvm -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" CXX="wllvm++ -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" make -j12
cd src && extract-bc redis-server
cd src && extract-bc redis-cli
https://github.com/pjreddie/darknet
9. darknetgit clone https://github.com/pjreddie/darknet.git
cd darknet/
vim Makefile
change CC=wllvm and CPP=wllvm++`
CC="wllvm -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" CXX="wllvm++ -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" make -j12
extract-bc darknet
https://teeworlds.com/
10. teeworlds 0.7.5wget https://github.com/teeworlds/teeworlds/releases/download/0.7.5/teeworlds-0.7.5-src.tar.gz
tar -xzvf teeworlds-0.7.5-src.tar.gz
mkdir teeworlds-0.7.5-src/build && cd teeworlds-0.7.5-src/build
CC="wllvm -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" CXX="wllvm++ -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" cmake ../
make -j12
extract-bc teeworlds
https://github.com/lloyd/yajl
11. yajl 2.1.0wget https://github.com/lloyd/yajl/archive/refs/tags/2.1.0.tar.gz
tar -xzvf 2.1.0.tar.gz
mkdir yajl-2.1.0/build && cd yajl-2.1.0/build
CC="wllvm -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" CXX="wllvm++ -O0 -Xclang -disable-O0-optnone -g -save-temps=obj -fno-discard-value-names -w" cmake ../
make -j12
cd yajl-2.1.0/bin/
extract-bc json_reformat
extract-bc json_verify