"IPO / LTO not supported", "relocation R_X86_64_32 can not be used when making a shared object" for clang++

I am updating a travis file to use the new bionic VMs. The build system is CMake.

While everything seems to work fine with g++, with clang the build fails when compiling a shared library, mentioning the infamouse gxx personality linker error and mentioning -fPic. Additionally CMake can’t enable LTO optimization with clang.

Given that fPic was passed, and that on my local machine everything works fine (I’m comparing the log builds line by line, the only differences seems to be the binaries paths), so I’m wondering whether there are some differences with the linker with the default settings between g++ and clang that could be causing this.

You can see the LTO failure at line 766, while the linker error at line 2385 (of the clang build). The line numbers are similar for the working g++ build.

https://travis-ci.org/Svalorzen/AI-Toolbox/builds/658637852

/usr/bin/ld: /usr/local/clang-7.0.0/bin/../lib/LLVMgold.so: error loading plugin: /usr/local/clang-7.0.0/bin/../lib/LLVMgold.so: cannot open shared object file: No such file or directory

/usr/bin/ld: ../libAIToolboxFMDP.a(JointActionLearner.cpp.o): relocation R_X86_64_32 against symbol `__gxx_personality_v0@@CXXABI_1.3' can not be used when making a shared object; recompile with -fPIC

Looks like ../libAIToolboxFMDP.a was compiled without -fPIC

Thanks for the help. I am now able to get LTO by directly installing clang-7 and llvm-7-dev and using /usr/bin/clang+±7.

Regarding the -fPIC, it looks like it’s a clang bug that starts at clang-7. It’s mentioned here for example: https://github.com/ponylang/ponyc/issues/3099

I’ve switched to clang-6.0 and now everything works (just as in my machine). Thanks again for the help!

Imprint