0

I want to compile nginx with CFI enforced by LLVM. I modify the Makefile in the objs directory. The modification includs: 1. change the compiler:cc--> clang 2. add parameters related with CFI: -flto -fvisibility=hidden -fsanitize=cfi The modified Makefile is illusrated below

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

The compilation process is passed. However, there are some errors are reported during the link process:

/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)

According to the document of clang 6.0.0, the CFI schemes relies on link-time optimization(LTO), and the linker used must support LTO (such as gold plugin). There are some materials about LTO:

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

I still do not know how to deal with this problem, Any one could give me some suggestion?

Rambo
  • 53
  • 6
  • You need `-fuse-ld=gold` flag. And install Gold linker, of course. – arrowd Aug 16 '17 at 17:15
  • Thans for your response. To help other freshman like me, I give more details: 1. install the Gold linker(down load the binutils (>2.21.51.0.2) with ld.bfd). 2. Run CMake with -DLLVM_BINUTILS_INCDIR=/path/to/binutils/include (this path contain the file plugin-api.h), and make -j8. this step generate the LLVMgold.so. 3. copy LLVMgold.so to /usr/local/lib – Rambo Aug 17 '17 at 00:10
  • For the latest LLVM, we do not have to copy LLVMgold.so to /usr/local/lib. After make install, the file will be copy to the target directory (./install_dir/lib) – Rambo Aug 17 '17 at 00:27
  • You'd better turn this into an answer, and mark it so. – arrowd Aug 17 '17 at 09:22

1 Answers1

0

To help other freshman like me, I give more details:

  1. Install the Gold linker(down load the binutils (>2.21.51.0.2) with ld.bfd).
  2. Run CMake with -DLLVM_BINUTILS_INCDIR=/path/to/binutils/include (this path contain the file plugin-api.h), and make -j8. this step generate the LLVMgold.so.
  3. For previous LLVM version, copy LLVMgold.so to /usr/local/lib. For the latest LLVM, we do not have to copy LLVMgold.so to /usr/local/lib. After make install, the file will be copy to the target directory (./install_dir/lib)
Rambo
  • 53
  • 6