LowFat icon indicating copy to clipboard operation
LowFat copied to clipboard

LowFat with link-time optimizations not working

Open taddeus opened this issue 5 years ago • 8 comments

I am trying to compile benchmarks with link-time optimizations by adding -flto to CFLAGS and LDFLAGS. To have these options available, I added -DLLVM_ENABLE_LTO=ON to build.sh on line 76. This breaks the build script with the following error:

CMake Error at projects/compiler-rt/cmake/Modules/AddCompilerRT.cmake:133 (message):
  Architecture x86_64 can't be targeted
Call Stack (most recent call first):
  projects/compiler-rt/lib/lowfat/CMakeLists.txt:10 (add_compiler_rt_runtime)

See the complete output of the build script here: https://gist.github.com/taddeus/7c2babd439e2846abb7a598ec12a029a

taddeus avatar May 06 '19 03:05 taddeus

Thanks for the report. I am not sure if LowFat has ever been tested with LTO before, so I am not surprised something breaks. Unfortunately the error message here is not very helpful.

GJDuck avatar May 06 '19 13:05 GJDuck

Yeah I understand. It would be nice to get it to work though, the instrumentation should not break with LTO in principle. I'm not sure how to approach fixing this in the build script, though. Could you give me some pointers on that?

taddeus avatar May 07 '19 01:05 taddeus

By chance I was looking into LTO for a different project. I don't think the -DLLVM_ENABLE_LTO=ON build option makes an LTO-compatible LLVM, rather it builds LLVM itself with LTO.

For the former you need to compile+install the gold linker and point -DLLVM_BINUTILS_INCDIR to the binutils include directory: https://llvm.org/docs/GoldPlugin.html

GJDuck avatar May 14 '19 05:05 GJDuck

Ah, of course. Come to think of it, I'm doing this for another project as well... I will try to get this working tomorrow and let you know if it works.

taddeus avatar May 14 '19 05:05 taddeus

@GJDuck did you get this to work? I tried to get it to compile with the same binutils setup I have working in another setup but the lowfat compiler breaks with a syntax error in the lowfat.ld linker script (unexpected STRING).

taddeus avatar May 15 '19 04:05 taddeus

No, I was using LTO for something else. I am not sure if ld.gold supports linker scripts, so perhaps that is the problem. All I can think of is removing the reference to lowfat.ld from the modified clang front end, with compile with global support disabled -mllvm -lowfat-no-replace-globals,

GJDuck avatar May 15 '19 04:05 GJDuck

Hmm, I do need the full instrumentation. It seems like LTO is not going to work, then.

taddeus avatar May 16 '19 00:05 taddeus

Looked into this a bit, the problem is the INSERT AFTER command in the linker script which tells ld to augment the default linker script. gold does not have a default linker script and does not support the command. One would have to extend the linker script with ld's default script instead of using INSERT AFTER. See also this thread: https://bugzilla.redhat.com/show_bug.cgi?id=927573

taddeus avatar May 16 '19 00:05 taddeus