plugin-opt=save-temps doesn't work in LLVM Gold 5.0.0

To compile an auto-tooled project to bitcode, I used to use plugin-opt=save-temps switch as explained in: This switch works with LLVM 3.8.0.

However, it seems to have no effect with LLVM 5.0.0. I can see intermediate bitcode files on disk, but not the final one. Is the option removed altogether? Has the switch changed?

That documentation is a bit out of date.

The LLVM gold plugin (and the lld linker) now use a different LTO API (as of a year ago). There is actually a richer set of intermediate files emitted when you do save-temps. E.g.:

$ clang -flto main.c foo.c -Wl,-plugin-opt=save-temps -o testsavetemps

$ file testsavetemps*
testsavetemps: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, not stripped
testsavetemps.0.0.preopt.bc: LLVM IR bitcode
testsavetemps.0.2.internalize.bc: LLVM IR bitcode
testsavetemps.0.4.opt.bc: LLVM IR bitcode
testsavetemps.0.5.precodegen.bc: LLVM IR bitcode
testsavetemps.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
testsavetemps.resolution.txt: ASCII text

Likely what you want is testsavetemps.0.5.precodegen.bc - the bitcode just before generating the native object (testsavetemps.o).


Thank you so much, Teresa.