我想用 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
我仍然不知道如何处理这个问题,任何人都可以给我一些建议吗?