注意事项

  1. # 装了pip
  2. sudo apt install python-pip
  3. # 装了wllvm
  4. pip install wllvm
  5. # 如果系统找不到wllvm,可以sudo
  6. sudo pip install wllvm
  7. # export
  8. export LLVM_COMPILER=clang
  9. # 检查clang的版本
  10. clang -v
  11. which clang
  12. # 相关工具
  13. # extract-bc 需要llvm-link
  14. # 设置CFLAGS
  15. CC=wllvm CXX=wllvm++ CFLAGS="-O0 -g" ./configure # configure
  16. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g") # CMake
  17. # 设置-fno-discard-value-names
  18. CFLAGS="-fno-discard-value-names"
  19. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure
  20. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" cmake ../
  21. # 覆盖makefile的CFLAGS
  22. make CFLAGS='-g -O' #if you say ‘make CFLAGS='-g -O'’, each C compilation will be done with ‘cc -c -g -O’
  23. # 默认使用静态链接(不过没成功)
  24. cmake -DBUILD_SHARED_LIBS=OFF ..

具体示例

1. Coreutils

  1. coreutils-6.11$ mkdir obj-llvm
  2. coreutils-6.11$ cd obj-llvm
  3. obj-llvm$ CC=wllvm ../configure --disable-nls CFLAGS="-g"
  4. ... verify that configure worked ...
  5. obj-llvm$ CC=wllvm make
  6. obj-llvm$ CC=wllvm make -C src arch hostname
  7. ... verify that make worked ...
  8. # 7.2编译问题
  9. # 报错:Please port gnulib freadahead.c to your platform
  10. # 参考:https://blog.csdn.net/Jun626/article/details/104870430
  11. sed -i 's/IO_ftrylockfile/IO_EOF_SEEN/' lib/*.c
  12. echo "#define _IO_IN_BACKUP 0x100" >> lib/stdio-impl.h

2. libpng

  1. wget . http://prdownloads.sourceforge.net/libpng/libpng-1.6.37.tar.gz
  2. tar -zxvf libpng-1.6.37.tar.gz && cd libpng-1.6.37/
  3. mkdir obj && cd obj
  4. export LLVM_COMPILER=clang
  5. CC=wllvm ../configure
  6. make -j25
  7. # no-discard-value直接正常跑就行

3. pcre2

  1. git clone https://github.com/PhilipHazel/pcre2.git && cd pcre2/
  2. export CC=gclang
  3. ./autogen.sh
  4. mkdir obj && cd obj
  5. cmake .. && make -j8
  6. get-bc pcre2grep

4. leptonica

  1. git clone https://github.com/DanBloomberg/leptonica.git && cd cd leptonica/
  2. ./autogen.sh
  3. ./configure --enable-debug
  4. mkdir obj && cd obj
  5. export CXX=gclang++ && export CC=gclang
  6. cmake .. && make -j8

5. apache

  1. export LLVM_COMPILER=clang
  2. export WLLVM_OUTPUT=WARNING
  3. wget https://archive.apache.org/dist/httpd/httpd-2.4.23.tar.gz
  4. tar xfz httpd-2.4.23.tar.gz
  5. cd httpd-2.4.23
  6. CC=wllvm ./configure
  7. make
  8. extract-bc httpd

6. bullet

  1. export LLVM_COMPILER=clang
  2. tar -xvf bullet-2.81-rev2613.tgz
  3. mkdir bullet-bin
  4. cd bullet-bin
  5. CC=wllvm CXX=wllvm++ cmake ../bullet-2.81-rev2613/
  6. make
  7. # Produces src/LinearMath/libLinearMath.bca
  8. extract-bc src/LinearMath/libLinearMath.a
  9. # Note that by default extracting bitcode from an archive produces
  10. # an archive of bitcode. You can also extract the bitcode directly into a module.
  11. extract-bc -b src/LinearMath/libLinearMath.a

7. jansson

  1. export LLVM_COMPILER=clang
  2. tar xvfz jansson-2.7.tar.gz
  3. cd jansson-2.7
  4. CC=wllvm ./configure
  5. make
  6. mkdir bitcode
  7. cp src/.libs/libjansson.a bitcode
  8. cd bitcode
  9. extract-bc libjansson.a
  10. llvm-ar x libjansson.bca
  11. ls -la

8. darknet

  1. # 先安装opencv
  2. sudo apt-get install build-essential
  3. sudo apt-get install cmake git libgtk2.0-dev pkg-config libavcodec-dev libavformat-dev libswscale-dev
  4. git clone https://github.com/opencv/opencv.git
  5. cd opencv
  6. mkdir build
  7. cd build
  8. # 编译opencv
  9. cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -D OPENCV_GENERATE_PKGCONFIG=ON ..
  10. make -j6
  11. sudo make install
  12. # darknet
  13. git clone https://github.com/pjreddie/darknet
  14. cd darknet
  15. # 设置opencv路径来找到OpenCVConfig.cmake
  16. set(OpenCV_DIR /home/xxx/opencv/build)
  17. # 修改各种CFlags和编译选项
  18. set(default_build_type "Debug")
  19. string(REGEX REPLACE "-O0" "-Og" CMAKE_CXX_FLAGS_DEBUG ${CMAKE_CXX_FLAGS_DEBUG})
  20. # 编译darknet
  21. CC=wllvm CXX=wllvm++ cmake ../ -DENABLE_CUDA=OFF
  22. # 如果没有cmake,只有MakeFile,则修改Makefile里面的OPT和CFLAGS来控制编译选项
  23. # 修改CFLAGS -fno-discard-value-names,直接修改makefile就行

9. git

  1. # 安装依赖
  2. sudo apt-get install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev gettext libz-dev libssl-dev
  3. # 编译
  4. tar -zxf git-2.28.0.tar.gz
  5. cd git-2.28.0
  6. make configure
  7. CC=wllvm ./configure #不知道要不要加上CFLAGS="-O0 -g"
  8. make
  9. # 新版的git比老版本的体积大很多,但老版本的编译似乎有些问题

10. wine

11. openssl-1.1.0和libssh2

  1. # https://blog.csdn.net/yxf1993/article/details/88533716
  2. # 先下载openssl
  3. ./config --prefix=/usr/local/openssl --openssldir=/usr/local/openssl/ssl
  4. # 再编译libssh2
  5. CC=wllvm CXX=wllvm++ ./configure --prefix=/usr/local/libssh2 --with-openssl CPPFLAGS="-I/usr/local/openssl/include" LDFLAGS="-L/usr/local/openssl/lib"
  6. # 结果为libssh.a

12. shadowsocks-3.3.4

  • 网络问题,暂未安装成功
  • 直接拿安装包会缺少依赖
  • 最后警报太少了
  1. # https://www.24kplus.com/linux/156.html
  2. git clone https://github.com/shadowsocks/shadowsocks-libev.git
  3. cd shadowsocks-libev
  4. git submodule update --init
  5. ./autogen.sh && ./configure --disable-documentation && make
  6. sudo make install
  7. # 费了好大功夫
  8. # 先直接从git拿
  9. git clone https://github.com/shadowsocks/shadowsocks-libev.git --depth 1 --branch v3.3.4
  10. # 然后需要submodule拿依赖包
  11. git submodule update --init --recursive
  12. # 接着还需要安装好几个依赖
  13. sudo apt install libpcre3 libpcre3-dev # 找不到pcre
  14. sudo apt install asciidoc # 找不到asciidoc,也可以configure来disable
  15. sudo apt install libmbedtls-dev
  16. sudo apt install libsodium-dev
  17. sudo apt install libc-ares-dev
  18. sudo apt install libev-dev
  19. # 特殊的编译问题:multiple definition
  20. https://github.com/shadowsocksr-backup/shadowsocksr-libev/issues/8
  21. # 特殊的configure
  22. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure
  23. --disable-documentation
  24. # make

13. icecast-2.4.3

  1. # 需要安装一些依赖
  2. sudo apt install libvorbis-dev
  3. apt-get install libxslt-dev
  4. # 也可以源码安装,这些安装的源码也可以用于后续测试,例如libvorbis
  5. # 参考:https://www.linuxfromscratch.org/blfs/view/svn/multimedia/libogg.html
  6. # 参考:https://www.linuxfromscratch.org/blfs/view/svn/multimedia/libvorbis.html
  7. cd ~/icecast-2.4.3/build/
  8. CC=wllvm ../configure

14. libxml2

  1. cd build
  2. ../autogen.sh
  3. CC=wllvm CXX=wllvm++ ../configure
  4. make
  5. # 生成的文件为build/.libs/libxml2.a,目测有点太大了

15. openssh-8.0p1.tar.gz

  1. # https://www.linuxfromscratch.org/blfs/view/svn/postlfs/openssh.html
  2. wget https://ftp.openbsd.org/pub/OpenBSD/OpenSSH/portable/openssh-8.0p1.tar.gz
  3. cd build
  4. CC=wllvm CXX=wllvm++ ../configure
  5. # 会出现好多个可执行文件
  6. # 先拿了这些
  7. scp sftp ssh ssh-agent ssh-keygen ssh-keyscan

16. SQLite-3.34.0

  1. wget https://github.com/sqlite/sqlite/archive/refs/tags/version-3.34.0.tar.gz
  2. # 看到默认的为-g -O2
  3. # 可以尝试两个不同版本的,可以通过修改configure的CFLAGS参数设置优化等级
  4. cd build
  5. CC=wllvm CXX=wllvm++ ../configure
  6. # 最后就是一个sqlite3可执行文件

17. zsh

  1. # 源码下面只有configure.ac
  2. aclocal
  3. autoconf
  4. autoheader
  5. automake --add-missing # 没啥用好像
  6. CC=wllvm CXX=wllvm++ ../configure
  7. make
  8. # 结果在build/Src/zsh
  9. # 尝试修改configure中的-O2为-O0,编译出来的zsh体积没什么变化,很奇怪

18. gedit

  • 依赖的库有点多,先不装了

19. proftpd-1.3.7e

  • 常规操作../configure

20. nano-4.0

  • 常规操作../configure

21. libpng-1.5.15

  • 常规操作
  1. wget https://downloads.sourceforge.net/libpng/libpng-1.5.15.tar.gz

22. libsndfile

  1. # 修改CMakeList
  2. set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -O0 -g")

23. libtiff

  • 似乎有很多tools
  • 不知道效果如何,还没有修改CFLAGS
  1. wget https://gitlab.com/libtiff/libtiff/-/archive/v4.0.10/libtiff-v4.0.10.tar.gz

24. lua

25. poppler

26. emacs

  1. # emacs会有一个-g3的默认编译选项,可能有问题,于是直接指定CFLAGS将其关闭
  2. # emacs编译时
  3. CC=wllvm CFLAGS="-O2 -g" ./configure --without-x #26.3只需要--without-x,27.2还需要加上--without-makeinfo
  4. make
  5. # 然后在emacs/src/emacs
  6. # 后面也尝试使用-O0编译
  7. # 又编译了一次,link时去掉了很多东西,但是make会出一堆error; 只做一个--without-x没问题
  8. 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

  1. # 必须要在外层目录下./configure,而不是在新建的build目录
  2. # P.S. 最后没能extract-bc出来,不知道为什么

28. libarchive

  1. # 有一个自带的build目录,直接autogen.sh
  2. # .libs里面

29. libical-3.0.5

  1. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" cmake ../ -DENABLE_GTK_DOC=OFF

30. h2o-2.2.5

  1. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" cmake ../

31. freetype-2-10-1

  1. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure
  2. # .libs/libfreetype.a

32. ImageMagick-7.1.0-13

  1. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure
  2. # 编译出的静态链接库有点难找
  3. # build/MagickCore/.libs/libMagickCore-7.Q16HDRI.a

33. vim-8.2.2456

  1. # 需要在原目录下
  2. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ./configure
  3. # src/vim

34. cJSON-1.2.1

  1. # 原目录下
  2. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" make

35. radare2-5.7.6

  1. # 在原目录下工作

36. openvpn-2.5.8

  1. # 进入openvpn目录,并没有发现惯常的编译脚本configure,后来才知道,需要运行一个命令才能生成:
  2. autoreconf -i -v -f //BUILD COMMANDS FROM SRC REPOSITORY CHECKOUT:
  3. # 接下来可以执行configure脚本了:
  4. ./configure --prefix=/usr/local/OpenVPN --disable-lzo //如需禁用lzo,加入此参数
  5. # 这里用这个,disable-lzo要加上,不然configure错误
  6. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure --disable-lzo
  7. # 处理另一个configure错误
  8. sudo apt-get install libpam0g-dev

37. Midnight Commander (mc-4.8.26)

  1. # https://www.jianshu.com/p/80f5fff734be
  2. # configure: error: S-Lang library version 2.0 or newer not found
  3. sudo apt install libslang2-dev
  4. # autogen and configure

38. yara

  1. # 直接./bootstrap + configure
  2. # 其他文件太小了,只有这个比较大:./libyara/.libs/libyara.a

39. suricata(6.0.8 和 6.0.9)

  1. # sudo apt install libyaml-dev
  2. # sudo apt install libjansson-dev
  3. # sudo apt install libpcap-dev # fatal error: pcap.h: 没有那个文件或目录
  4. # sudo apt install libhtp-dev

40. mosquitto(1.6.8编译成功;2.0.6编译失败)

  1. sudo apt install xsltproc
  2. # 直接cmake

41. fluent-bit-1.9.9

  1. # 直接cmake
  2. # 编译出来的结果有好多 .a 文件,有libsqlite3, libfluent, 还有原本的fluent-bit
  3. # 暂时都存着试试

42. wireshark

  1. # 最后extract-bc提取不出来
  2. # 按步骤安装依赖

43. MOTHBALLED-graphviz

  1. ./autogen.sh
  2. make
  3. # 结果文件有点难找
  4. $ find . -name "*.a" -print0 | xargs -0 du -h | sort -rh | head -n 30
  5. 4,1M ./plugin/neato_layout/.libs/libgvplugin_neato_layout_C.a
  6. 3,8M ./lib/gvc/.libs/libgvc_C.a
  7. 2,3M ./lib/common/.libs/libcommon_C.a
  8. 1,8M ./lib/expr/.libs/libexpr_C.a
  9. 1,5M ./lib/neatogen/.libs/libneatogen_C.a
  10. # 最后使用前两个进行分析

44. varnish-7.0.3

  1. # autogen.sh
  2. # configure时需要安装多个依赖包,一个个下,其中有一个名字不太好找:libpcre2-dev
  3. # 结果文件有多个可执行文件,但只有bin/varnishd/varnishd比较大
  4. # 当然也可以拷贝到一起
  5. cp varnishadm/varnishadm varnishd/varnishd varnishhist/varnishhist varnishlog/varnishlog varnishncsa/varnishncsa varnishstat/varnishstat varnishtest/varnishtest varnishtop/varnishtop result

45. nnn

  1. #直接make,注意需要依赖包
  2. sudo apt install libreadline-dev

46. grub-128c16a

  1. # 先bootstrap再autogen,期间注意网络畅通
  2. # 正常configure+make
  3. # 需要注意的是,结果中有很多的.a和exec,目前把他们全都收集进来打成bc文件
  4. find . -name "grub-*" -type f -print0 | xargs -0 du -h | sort -rh
  5. find . -type f -exec extract-bc {} \;
  6. find . -name "*.bc" -exec opt --mem2reg {} -o {}.opt \;
  7. find . -name "*.bc" -exec rm {} \;

47. mailutils-9abec3

  1. # 需要从git拉,不能直接打zip或tar下来
  2. # git clone后bootstrap,会拉取依赖的项目,要保持网络畅通
  3. # make出来后的文件会出现multiple definition,按实际情况加上extern就行,不过不改也行
  4. # 最后能用的貌似只有libmailutils.a , 4.2MB

48. libredwg

  1. # 这个项目出乎意料地大,编译结果也很大
  2. # 即便是disable一些东西,也有92MB大
  3. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ../configure --disable-bindings --disable-python

48. gnupg

  1. # 它需要最新的automake,无语子;我觉得太sb了,就去configure.ac改一下它检查的版本号
  2. # 还需要源码安装最新的,我都安装了
  3. # autogen+configure最后也过去了
  4. # make的时候过不去,然后加了一些条件
  5. CC=wllvm CXX=wllvm++ CFLAGS="-fno-discard-value-names -O2 -g" ./configure --sysconfdir=/etc --enable-maintainer-mode
  6. # 最终make还是失败了,但仍然有一些有用的结果可以extract-bc

49. httpd

  1. # 死活起不来,但是相关警报目测大概率能报出来,而且挺不错的,之后再考虑了

相关资料

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