I want to generate clean assembly like Compiler Explorer locally. Note that, I read How to remove “noise” from GCC/clang assembly output? before attempting this. The output using that method isn't as clean or dense compared to godbolt and still has a lot of asm directives and unused labels in it.
How can I get clean assembly output without any unused labels or directives?
A while ago, I needed something like this locally so I wrote a small tool to make the asm readable.
It attempts to 'clean' and make the 'asm' output from 'gcc' readable using C++ itself. It does something similar to Compiler Explorer and tries to remove all the directives and unused labels, making the asm clean. Only standard library is used for this.
Some things I should mention:
-S -fno-asynchronous-unwind-tables -fno-dwarf2-cfi-asm -masm=intel
, (remove-masm=
if you want AT&T asm) AT&T syntax will probably work but I didn't test it much. The other two options are to remove the.cfi
directives. It can be handled using the code below but the compiler itself does a much better job of this. See the answer by Peter Cordes above.abi::__cxa_demangle()
is used for demanglingThe strategy used for cleaning the asm(There are probably better, faster more efficient ways to do this):
Update 1: Not all static data gets removed now.