我想用LLVM启用的CFI编译mysql。软件版本如下:
我可以通过以下配置成功编译mysql:
CC="clang" CXX="clang++" CFLAGS="-g" cmake -DCMAKE_INSTALL_PREFIX=../mysql -DWITH_BOOST=./boost .
但是,我无法使用以下配置编译mysql:
CC="clang" CXX="clang++" CFLAGS="-g -flto" CXXFLAGS="-g -flto" cmake -DCMAKE_INSTALL_PREFIX=../mysql -DWITH_BOOST=./boost .
报告的错误如下:
../mysys/libmysys.a: error adding symbols: Archive has no index; run ranlib to add one
clang-6.0: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [extra/comp_err] Error 1
../mysys/libmysys.a由以下命令构成:
cd /home/zhangjun/work/mysql/mysql-5.6.26/mysys_ssl
&& /home/zhangjun/tools/cmake/cmake-3.9.1-Linux-x86_64/bin/cmake -P
CMakeFiles/mysys_ssl.dir/cmake_clean_target.cmake
cd /home/zhangjun/work/mysql/mysql-5.6.26/mysys_ssl && /home/zhangjun/tools/cmake/cmake-3.9.1-Linux-x86_64/bin/cmake -E cmake_link_script CMakeFiles/mysys_ssl.dir/link.txt --verbose=1
/usr/bin/ar qc libmysys_ssl.a CMakeFiles/mysys_ssl.dir/crypt_genhash_impl.cc.o CMakeFiles/mysys_ssl.dir/my_default.cc.o CMakeFiles/mysys_ssl.dir/my_getopt.cc.o CMakeFiles/mysys_ssl.dir/my_aes.cc.o CMakeFiles/mysys_ssl.dir/my_sha1.cc.o CMakeFiles/mysys_ssl.dir/my_sha2.cc.o CMakeFiles/mysys_ssl.dir/my_md5.cc.o CMakeFiles/mysys_ssl.dir/my_rnd.cc.o CMakeFiles/mysys_ssl.dir/my_murmur3.cc.o CMakeFiles/mysys_ssl.dir/my_aes_yassl.cc.o
/usr/bin/ranlib libmysys_ssl.a
如何解决此错误?
为了解决这个错误,我发了一封电子邮件给Caroline Tice,他是"在GCC中实施前沿控制流完整性的作者。 LLVM" 他说我应该使用llvm的ar和runlib。使用以下配置修复上述错误:
CC="clang" CXX="clang++" CFLAGS="-g -flto -fvisibility=hidden -fsanitize=cfi" CXXFLAGS="-g -flto -fvisibility=hidden -fsanitize=cfi" cmake -DCMAKE_{EXE,SHARED,MODULE}_LINKER_FLAGS="-flto -fsanitize=cfi" -DCMAKE_AR=/home/zhangjun/work/llvm/llvm-3.7.1/bin/llvm-ar -DCMAKE_RANLIB=/home/zhangjun/work/llvm/llvm-3.7.1/bin/llvm-ranlib -DCMAKE_NM=/home/zhangjun/work/llvm/llvm-3.7.1/bin/llvm-nm -DCMAKE_INSTALL_PREFIX=../mysql -DWITH_BOOST=./boost .
不幸的是,有一个错误:
ld: /home/zhangjun/work/llvm/llvm/tools/gold/gold-plugin.cpp:879: ld_plugin_status allSymbolsReadHook(): Assertion `ObjFilename.second' failed.
clang-6.0: error: unable to execute command: Aborted (core dumped)
clang-6.0: error: linker command failed due to signal (use -v to see invocation)
make[2]: *** [extra/comp_err] Error 254
make[2]: Leaving directory `/home/zhangjun/work/mysql/mysql-5.6.26'
make[1]: *** [extra/CMakeFiles/comp_err.dir/all] Error 2
make[1]: Leaving directory `/home/zhangjun/work/mysql/mysql-5.6.26'
make: *** [all] Error 2
任何人都可以帮我解决这个错误吗?
答案 0 :(得分:0)
尝试从标记中删除-flto
。出于某种原因,对于clang,我已经进行了链接时优化导致该问题。