0

我想用 LLVM 强制执行的 CFI 编译 nginx。我修改了 objs 目录中的 Makefile。修改包括: 1. 修改编译器:cc--> clang 2. 添加CFI相关参数: -flto -fvisibility=hidden -fsanitize=cfi 修改后的Makefile如下图

CC =    clang
CFLAGS =  -pipe  -O -W -Wall -Wpointer-arith -Wno-unused-parameter -Werror -g -flto -fvisibility=hidden -fsanitize=cfi
CPP =   cc -E
LINK =  $(CC)

编译过程通过。但是在链接过程中会报一些错误:

/usr/bin/ld: unrecognized option '-plugin'
/usr/bin/ld: use the --help option for usage information
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)

根据clang 6.0.0的文档,CFI方案依赖于链接时优化(LTO),使用的链接器必须支持LTO(如gold插件)。关于LTO有一些资料:

http://llvm.org/docs/GoldPlugin.html

我仍然不知道如何处理这个问题,任何人都可以给我一些建议吗?

4

1 回答 1

0

为了帮助像我这样的其他新生,我提供了更多细节:

  1. 安装 Gold 链接器(使用 ld.bfd 下载 binutils (>2.21.51.0.2))。
  2. 使用 -DLLVM_BINUTILS_INCDIR=/path/to/binutils/include 运行 CMake(此路径包含文件 plugin-api.h),并生成 -j8。此步骤生成 LLVMgold.so。
  3. 对于以前的 LLVM 版本,将 LLVMgold.so 复制到 /usr/local/lib。对于最新的 LLVM,我们不必将 LLVMgold.so 复制到 /usr/local/lib。make install 后,文件将被复制到目标目录(./install_dir/lib)
于 2017-08-19T13:34:15.400 回答