- 注意事项
- 具体示例
- 1. Coreutils
- 2. libpng
- 3. pcre2
- 4. leptonica
- 5. apache
- 6. bullet
- 7. jansson
- 8. darknet
- 9. git
- 10. wine
- 11. openssl-1.1.0和libssh2
- 12. shadowsocks-3.3.4
- 13. icecast-2.4.3
- 14. libxml2
- 15. openssh-8.0p1.tar.gz
- 16. SQLite-3.34.0
- 17. zsh
- 18. gedit
- 19. proftpd-1.3.7e
- 20. nano-4.0
- 21. libpng-1.5.15
- 22. libsndfile
- 23. libtiff
- 24. lua
- 25. poppler
- 26. emacs
- 27. dhcp
- 28. libarchive
- 29. libical-3.0.5
- 30. h2o-2.2.5
- 31. freetype-2-10-1
- 32. ImageMagick-7.1.0-13
- 33. vim-8.2.2456
- 34. cJSON-1.2.1
- 35. radare2-5.7.6
- 36. openvpn-2.5.8
- 37. Midnight Commander (mc-4.8.26)
- 38. yara
- 39. suricata(6.0.8 和 6.0.9)
- 40. mosquitto(1.6.8编译成功;2.0.6编译失败)
- 41. fluent-bit-1.9.9
- 42. wireshark
- 43. MOTHBALLED-graphviz
- 44. varnish-7.0.3
- 45. nnn
- 46. grub-128c16a
- 47. mailutils-9abec3
- 48. libredwg
- 48. gnupg
- 49. httpd
- 相关资料
注意事项
# 装了pip
sudo apt install python-pip
# 装了wllvm
pip install wllvm
# 如果系统找不到wllvm,可以sudo
sudo pip install wllvm
# export
export LLVM_COMPILER=clang
# 检查clang的版本
clang -v
which clang
# 相关工具
# extract-bc 需要llvm-link
# 设置CFLAGS
CC=wllvm CXX=wllvm++ CFLAGS="-O0 -g" ./configure # configure
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g") # CMake
# 设置-fno-discard-value-names
CFLAGS="-fno-discard-value-names"
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" cmake ../
# 覆盖makefile的CFLAGS
make CFLAGS='-g -O' #if you say ‘make CFLAGS='-g -O'’, each C compilation will be done with ‘cc -c -g -O’
# 默认使用静态链接(不过没成功)
cmake -DBUILD_SHARED_LIBS=OFF ..
具体示例
1. Coreutils
coreutils-6.11$ mkdir obj-llvm
coreutils-6.11$ cd obj-llvm
obj-llvm$ CC=wllvm ../configure --disable-nls CFLAGS="-g"
... verify that configure worked ...
obj-llvm$ CC=wllvm make
obj-llvm$ CC=wllvm make -C src arch hostname
... verify that make worked ...
# 7.2编译问题
# 报错:Please port gnulib freadahead.c to your platform
# 参考:https://blog.csdn.net/Jun626/article/details/104870430
sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' lib/*.c
echo "#define _IO_IN_BACKUP 0x100" >> lib/stdio-impl.h
2. libpng
wget . http://prdownloads.sourceforge.net/libpng/libpng-1.6.37.tar.gz
tar -zxvf libpng-1.6.37.tar.gz && cd libpng-1.6.37/
mkdir obj && cd obj
export LLVM_COMPILER=clang
CC=wllvm ../configure
make -j25
# no-discard-value直接正常跑就行
3. pcre2
git clone https://github.com/PhilipHazel/pcre2.git && cd pcre2/
export CC=gclang
./autogen.sh
mkdir obj && cd obj
cmake .. && make -j8
get-bc pcre2grep
4. leptonica
git clone https://github.com/DanBloomberg/leptonica.git && cd cd leptonica/
./autogen.sh
./configure --enable-debug
mkdir obj && cd obj
export CXX=gclang++ && export CC=gclang
cmake .. && make -j8
5. apache
export LLVM_COMPILER=clang
export WLLVM_OUTPUT=WARNING
wget https://archive.apache.org/dist/httpd/httpd-2.4.23.tar.gz
tar xfz httpd-2.4.23.tar.gz
cd httpd-2.4.23
CC=wllvm ./configure
make
extract-bc httpd
6. bullet
export LLVM_COMPILER=clang
tar -xvf bullet-2.81-rev2613.tgz
mkdir bullet-bin
cd bullet-bin
CC=wllvm CXX=wllvm++ cmake ../bullet-2.81-rev2613/
make
# Produces src/LinearMath/libLinearMath.bca
extract-bc src/LinearMath/libLinearMath.a
# Note that by default extracting bitcode from an archive produces
# an archive of bitcode. You can also extract the bitcode directly into a module.
extract-bc -b src/LinearMath/libLinearMath.a
7. jansson
export LLVM_COMPILER=clang
tar xvfz jansson-2.7.tar.gz
cd jansson-2.7
CC=wllvm ./configure
make
mkdir bitcode
cp src/.libs/libjansson.a bitcode
cd bitcode
extract-bc libjansson.a
llvm-ar x libjansson.bca
ls -la
8. darknet
# 先安装opencv
sudo apt-get install build-essential
sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
git clone https://github.com/opencv/opencv.git
cd opencv
mkdir build
cd build
# 编译opencv
cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_GENERATE_PKGCONFIG=ON ..
make -j6
sudo make install
# darknet
git clone https://github.com/pjreddie/darknet
cd darknet
# 设置opencv路径来找到OpenCVConfig.cmake
set(OpenCV_DIR /home/xxx/opencv/build)
# 修改各种CFlags和编译选项
set(default_build_type "Debug")
string(REGEX REPLACE "-O0" "-Og" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
# 编译darknet
CC=wllvm CXX=wllvm++ cmake ../ -DENABLE_CUDA=OFF
# 如果没有cmake,只有MakeFile,则修改Makefile里面的OPT和CFLAGS来控制编译选项
# 修改CFLAGS -fno-discard-value-names,直接修改makefile就行
9. git
# 安装依赖
sudo apt-get install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
# 编译
tar -zxf git-2.28.0.tar.gz
cd git-2.28.0
make configure
CC=wllvm ./configure #不知道要不要加上CFLAGS="-O0 -g"
make
# 新版的git比老版本的体积大很多,但老版本的编译似乎有些问题
10. wine
11. openssl-1.1.0和libssh2
# https://blog.csdn.net/yxf1993/article/details/88533716
# 先下载openssl
./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl/ssl
# 再编译libssh2
CC=wllvm CXX=wllvm++ ./configure --prefix=/usr/local/libssh2 --with-openssl CPPFLAGS="-I/usr/local/openssl/include" LDFLAGS="-L/usr/local/openssl/lib"
# 结果为libssh.a
12. shadowsocks-3.3.4
- 网络问题,暂未安装成功
- 直接拿安装包会缺少依赖
- 最后警报太少了
# https://www.24kplus.com/linux/156.html
git clone https://github.com/shadowsocks/shadowsocks-libev.git
cd shadowsocks-libev
git submodule update --init
./autogen.sh && ./configure --disable-documentation && make
sudo make install
# 费了好大功夫
# 先直接从git拿
git clone https://github.com/shadowsocks/shadowsocks-libev.git --depth 1 --branch v3.3.4
# 然后需要submodule拿依赖包
git submodule update --init --recursive
# 接着还需要安装好几个依赖
sudo apt install libpcre3 libpcre3-dev # 找不到pcre
sudo apt install asciidoc # 找不到asciidoc,也可以configure来disable
sudo apt install libmbedtls-dev
sudo apt install libsodium-dev
sudo apt install libc-ares-dev
sudo apt install libev-dev
# 特殊的编译问题:multiple definition
https://github.com/shadowsocksr-backup/shadowsocksr-libev/issues/8
# 特殊的configure
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure
--disable-documentation
# make
13. icecast-2.4.3
# 需要安装一些依赖
sudo apt install libvorbis-dev
apt-get install libxslt-dev
# 也可以源码安装,这些安装的源码也可以用于后续测试,例如libvorbis
# 参考:https://www.linuxfromscratch.org/blfs/view/svn/multimedia/libogg.html
# 参考:https://www.linuxfromscratch.org/blfs/view/svn/multimedia/libvorbis.html
cd ~/icecast-2.4.3/build/
CC=wllvm ../configure
14. libxml2
cd build
../autogen.sh
CC=wllvm CXX=wllvm++ ../configure
make
# 生成的文件为build/.libs/libxml2.a,目测有点太大了
15. openssh-8.0p1.tar.gz
# https://www.linuxfromscratch.org/blfs/view/svn/postlfs/openssh.html
wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.0p1.tar.gz
cd build
CC=wllvm CXX=wllvm++ ../configure
# 会出现好多个可执行文件
# 先拿了这些
scp sftp ssh ssh-agent ssh-keygen ssh-keyscan
16. SQLite-3.34.0
wget https://github.com/sqlite/sqlite/archive/refs/tags/version-3.34.0.tar.gz
# 看到默认的为-g -O2
# 可以尝试两个不同版本的,可以通过修改configure的CFLAGS参数设置优化等级
cd build
CC=wllvm CXX=wllvm++ ../configure
# 最后就是一个sqlite3可执行文件
17. zsh
# 源码下面只有configure.ac
aclocal
autoconf
autoheader
automake --add-missing # 没啥用好像
CC=wllvm CXX=wllvm++ ../configure
make
# 结果在build/Src/zsh
# 尝试修改configure中的-O2为-O0,编译出来的zsh体积没什么变化,很奇怪
18. gedit
- 依赖的库有点多,先不装了
19. proftpd-1.3.7e
- 常规操作../configure
20. nano-4.0
- 常规操作../configure
21. libpng-1.5.15
- 常规操作
wget https://downloads.sourceforge.net/libpng/libpng-1.5.15.tar.gz
22. libsndfile
# 修改CMakeList
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g")
23. libtiff
- 似乎有很多tools
- 不知道效果如何,还没有修改CFLAGS
wget https://gitlab.com/libtiff/libtiff/-/archive/v4.0.10/libtiff-v4.0.10.tar.gz
24. lua
25. poppler
26. emacs
# emacs会有一个-g3的默认编译选项,可能有问题,于是直接指定CFLAGS将其关闭
# emacs编译时
CC=wllvm CFLAGS="-O2 -g" ./configure --without-x #26.3只需要--without-x,27.2还需要加上--without-makeinfo
make
# 然后在emacs/src/emacs
# 后面也尝试使用-O0编译
# 又编译了一次,link时去掉了很多东西,但是make会出一堆error; 只做一个--without-x没问题
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure --with-xpm=no --with-jpeg=no --with-gif=no --with-tiff=no
27. dhcp
# 必须要在外层目录下./configure,而不是在新建的build目录
# P.S. 最后没能extract-bc出来,不知道为什么
28. libarchive
# 有一个自带的build目录,直接autogen.sh
# .libs里面
29. libical-3.0.5
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" cmake ../ -DENABLE_GTK_DOC=OFF
30. h2o-2.2.5
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" cmake ../
31. freetype-2-10-1
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure
# .libs/libfreetype.a
32. ImageMagick-7.1.0-13
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure
# 编译出的静态链接库有点难找
# build/MagickCore/.libs/libMagickCore-7.Q16HDRI.a
33. vim-8.2.2456
# 需要在原目录下
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ./configure
# src/vim
34. cJSON-1.2.1
# 原目录下
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" make
35. radare2-5.7.6
# 在原目录下工作
36. openvpn-2.5.8
# 进入openvpn目录,并没有发现惯常的编译脚本configure,后来才知道,需要运行一个命令才能生成:
autoreconf -i -v -f //BUILD COMMANDS FROM SRC REPOSITORY CHECKOUT:
# 接下来可以执行configure脚本了:
./configure --prefix=/usr/local/OpenVPN --disable-lzo //如需禁用lzo,加入此参数
# 这里用这个,disable-lzo要加上,不然configure错误
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure --disable-lzo
# 处理另一个configure错误
sudo apt-get install libpam0g-dev
37. Midnight Commander (mc-4.8.26)
# https://www.jianshu.com/p/80f5fff734be
# configure: error: S-Lang library version 2.0 or newer not found
sudo apt install libslang2-dev
# autogen and configure
38. yara
# 直接./bootstrap + configure
# 其他文件太小了,只有这个比较大:./libyara/.libs/libyara.a
39. suricata(6.0.8 和 6.0.9)
# sudo apt install libyaml-dev
# sudo apt install libjansson-dev
# sudo apt install libpcap-dev # fatal error: pcap.h: 没有那个文件或目录
# sudo apt install libhtp-dev
40. mosquitto(1.6.8编译成功;2.0.6编译失败)
sudo apt install xsltproc
# 直接cmake
41. fluent-bit-1.9.9
# 直接cmake
# 编译出来的结果有好多 .a 文件,有libsqlite3, libfluent, 还有原本的fluent-bit
# 暂时都存着试试
42. wireshark
# 最后extract-bc提取不出来
# 按步骤安装依赖
43. MOTHBALLED-graphviz
./autogen.sh
make
# 结果文件有点难找
$ find . -name "*.a" -print0 | xargs -0 du -h | sort -rh | head -n 30
4,1M ./plugin/neato_layout/.libs/libgvplugin_neato_layout_C.a
3,8M ./lib/gvc/.libs/libgvc_C.a
2,3M ./lib/common/.libs/libcommon_C.a
1,8M ./lib/expr/.libs/libexpr_C.a
1,5M ./lib/neatogen/.libs/libneatogen_C.a
# 最后使用前两个进行分析
44. varnish-7.0.3
# autogen.sh
# configure时需要安装多个依赖包,一个个下,其中有一个名字不太好找:libpcre2-dev
# 结果文件有多个可执行文件,但只有bin/varnishd/varnishd比较大
# 当然也可以拷贝到一起
cp varnishadm/varnishadm varnishd/varnishd varnishhist/varnishhist varnishlog/varnishlog varnishncsa/varnishncsa varnishstat/varnishstat varnishtest/varnishtest varnishtop/varnishtop result
45. nnn
#直接make,注意需要依赖包
sudo apt install libreadline-dev
46. grub-128c16a
# 先bootstrap再autogen,期间注意网络畅通
# 正常configure+make
# 需要注意的是,结果中有很多的.a和exec,目前把他们全都收集进来打成bc文件
find . -name "grub-*" -type f -print0 | xargs -0 du -h | sort -rh
find . -type f -exec extract-bc {} \;
find . -name "*.bc" -exec opt --mem2reg {} -o {}.opt \;
find . -name "*.bc" -exec rm {} \;
47. mailutils-9abec3
# 需要从git拉,不能直接打zip或tar下来
# git clone后bootstrap,会拉取依赖的项目,要保持网络畅通
# make出来后的文件会出现multiple definition,按实际情况加上extern就行,不过不改也行
# 最后能用的貌似只有libmailutils.a , 4.2MB
48. libredwg
# 这个项目出乎意料地大,编译结果也很大
# 即便是disable一些东西,也有92MB大
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure --disable-bindings --disable-python
48. gnupg
# 它需要最新的automake,无语子;我觉得太sb了,就去configure.ac改一下它检查的版本号
# 还需要源码安装最新的,我都安装了
# autogen+configure最后也过去了
# make的时候过不去,然后加了一些条件
CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ./configure --sysconfdir=/etc --enable-maintainer-mode
# 最终make还是失败了,但仍然有一些有用的结果可以extract-bc
49. httpd
# 死活起不来,但是相关警报目测大概率能报出来,而且挺不错的,之后再考虑了
相关资料
https://github.com/travitch/whole-program-llvm/blob/master/doc/tutorial-ubuntu-16.04.md
https://www.yuque.com/wenyueniao/kb/di5ir1
- 生成FreeBSD的bitcode
https://github.com/travitch/whole-program-llvm/blob/master/doc/tutorial-freeBSD.md