Clang: How to check if LTO was performed
Asked Answered
G

2

6

For gcc, this answer tells us how we can verify that Link-Time Optimization was performed. For clang, I cannot see any entries similar to .gnu.lto.

More specifically, I have a binary where I am quite sure that LTO should have a significant benefit, but I am seeing nothing. I wonder if cmake actually does the right thing.

Is there any way to tell if clang performed LTO by looking at a binary or an *.o file?

Generalize answered 26/6, 2018 at 17:21 Comment(0)
W
5

An option would be to try running llvm-dis on one of your .o files. If the LTO was actually performed, the .o files contain llvm bitcode and llvm-dis will produce the .ll file containing humain-readable llvm ir. Otherwise it will produce the error message "error: Invalid bitcode signature".

Wyler answered 29/6, 2018 at 14:6 Comment(1)
I had to re-read this to realize that no output is good news. Now it works, thanks!Generalize
C
6

The file utility will report that the file is "LLVM IR bitcode". LLVM/clang's LTO facilities don't produce "fat" object files, it's just IR.

Cymose answered 8/3, 2019 at 3:36 Comment(0)
W
5

An option would be to try running llvm-dis on one of your .o files. If the LTO was actually performed, the .o files contain llvm bitcode and llvm-dis will produce the .ll file containing humain-readable llvm ir. Otherwise it will produce the error message "error: Invalid bitcode signature".

Wyler answered 29/6, 2018 at 14:6 Comment(1)
I had to re-read this to realize that no output is good news. Now it works, thanks!Generalize

© 2022 - 2024 — McMap. All rights reserved.