Normally, one can get GCC's optimized assembler output from a source file using the -S
flag in GCC and Clang, as in the following example.
gcc -O3 -S -c -o foo.s foo.c
But suppose I compile all of my source files using -O3 -flto
to enable link-time whole-program optimizations and want to see the final compiler-generated optimized assembly for a function, and/or see where/how code gets inlined.
The result of compiling is a bunch of .o
files which are really IR files disguised as object files, as expected. In linking an executable or shared library, these are then smushed together, optimized as a whole, and then compiled into the target binary.
But what if I want assembly output from this procedure? That is, the assembly source that results after link-time optimizations, during the compilation of IR to assembly, and before the actual assembly and linkage into the final executable.
I tried simply adding a -S
flag to the link step, but that didn't really work.
I know disassembling the executable is possible, even interleaving with source, but sometimes it's nicer to look at actual compiler-generated assembly, especially with -fverbose-asm
.
-g
there are labels on every function, and block -> source-line-number debug info that letsobjdump -drwC -S -l
interleave disassembly with source. Worth a try, IDK if that works. Not as nice asgcc -S -fverbose-asm
to have named outputs, though. – Langobardllvm-link
'ing all of the "object" files together before passing-S
work? – Blakely