Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clang interleaved source and assembly

Wondering if it is possible to generate interleaved source and assembly from clang? I am looking for something equivalent to gcc command (as demonstrated at http://www.fclose.com/240/generate-a-mixed-source-and-assembly-listing-using-gcc/)

gcc -Wa,-adhln -g source_code.c > assembly_list.s

I have visited Link: How do you get assembler output from C/C++ source in gcc? but it gets so far as to list the assembly - but no interleaving.

Also Visual Studio does give you pretty nice interleaved assembly output, details here: How to view the assembly behind the code using Visual C++?

Thank you for all the help.

Sarang

like image 213
Sarang Avatar asked Jul 07 '14 06:07

Sarang


2 Answers

There seems to be a bug reported sometimes last year stating exactly this: http://llvm.org/bugs/show_bug.cgi?id=16647

Bug 16647 - No option to produce mixed source + assembly listing?

So since it is still NEW I guess clang does not have this supported yet.

As an alternative, how about compiling your code and then use objdump -S ? The output format is somewhat similar ...

like image 135
dragosht Avatar answered Oct 20 '22 05:10

dragosht


As of August 2016, the bug that @dragosht mentioned still is open. However, there is a workaround offered by the linked bug 17465: clang -no-integrated-as -Xassembler -adhln. It disables the clang-integrated assembler and calls an external assembler, which hopefully supports the listing-generating options.

That works OK in Linux, but it doesn't work in Mac OS X (as of 10.11.6). The problem is that even the external assembler in OS X does not support the listing-generating options - you can check that with man as.

objdump -S is an alternative that also works well in Linux, but Mac OS X's alternative to objdump is otool, which does provide disassembly but not source interlacing. Hopefully that will change soon-ish, because otool seems to be on its way out while llvm grows its own objdump. See man llvm-otool.

Finally, for OS X the best option seems to be using gobjdump -S, from binutils. It can be installed with MacPorts or brew.

like image 41
hmijail mourns resignees Avatar answered Oct 20 '22 04:10

hmijail mourns resignees