ccompilationobjdump

llvm objdump: generated assembler not intermixed with C source despite using --source. Why?


I can't seem to generate assembler with intermixed C source with assembler when using Apple LLVM objdump on macOS Sonoma with the --source objdump option. What am I missing?

Environment:

With FILE being hello, hello.c being present, I end up with the hello executable and hello.asm. Same for other larger single-file C programs. I can see the ARM assembler code, but I never get the embedded C source inside the objdump output.

I looked for bug reports in LLVM but did not find any. Is there a problem with the command line options I used?


Solution

  • The issue is your compile command:

    cc FILE.c -o FILE
    

    You cannot extract what you don't put in the file. Normally, debug information (like the coresponding source file and line for a given instruction) is not included in created output file.

    You can tell the compiler to add this information using option -g.