0

I wrote simple x86 assembly routine:

$ cat asm.s

.global foo

.section .text
foo:
    nop
    ret

And compiled it with

$ gcc -c -g asm.s -o asm.o

But when I do objdump --dwarf asm.o, it does not display any info about function foo. Looks like, gcc does not create .debug_info details about foo.

BTW, there is a entry of foo in .symtab.

Any ideas?

Ravi
  • 1,574
  • 2
  • 16
  • 28
  • The function is not called. Maybe it is optimised out as dead code? – Jan Henke Jul 25 '16 at 10:16
  • @JanHenke thanks. asm.s is one of the Compilation Unit. I'm calling it from main() defined in other Compilation Unit. Apart from that, I'm not using any gcc optimization options. Otherwise it won't appear in symbol table. right? – Ravi Jul 25 '16 at 10:33

1 Answers1

2

The error is in the objdump command. use the following command, and it will show the assembly listing of your function:

    objdump -d -M intel -S asm.o

Now you updated the question - if you want to include debug info then invoke the assembler with:

    gcc -gdwarf2 -c  asm.s -o asm.o

Now objdump --dwarf will display the debug info.

MichaelMoser
  • 3,172
  • 1
  • 26
  • 26
  • No. objdump with -d option disassembles the code. But I'm asking about --dwarf option. (Updated title of question) – Ravi Jul 25 '16 at 10:50