llvm-objdump does not include the function name when disassembling with -l (--line-numbers). I'm not sure whether or not this is desired/intentional. $ cat foo.c int foo() { return 5; } $ clang -g -c foo.c -o foo.o $ objdump -l -d foo.o foo.o: file format elf64-x86-64 Disassembly of section .text: 0000000000000000 <foo>: foo(): <--------- this line is missing below /tmp/foo.c:1 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp /tmp/foo.c:2 4: b8 05 00 00 00 mov $0x5,%eax 9: 5d pop %rbp a: c3 retq $ llvm-objdump -l -d foo.o foo.o: file format ELF64-x86-64 Disassembly of section .text: 0000000000000000 foo: ; /tmp/foo.c:1 0: 55 pushq %rbp 1: 48 89 e5 movq %rsp, %rbp ; /tmp/foo.c:2 4: b8 05 00 00 00 movl $5, %eax 9: 5d popq %rbp a: c3 retq
No strong preference. Almost assuredly not intentional. It seems a little redundant?
Yeah, seems redundant to me too. Before trying to add this, it would be nice to see if there's an example where it isn't redundant (two methods in the same symbol? function name that doesn't match the symbol name? are any of those possible?) I can get the strings to be different when mangling is added, although I think that's just a mistake that only one is demangled, e.g. $ cat foo.cc namespace bar { int blah() { return 5; } } $ objdump -ldC foo.o ... 0000000000000000 <bar::blah()>: _ZN3bar4blahEv(): /tmp/foo.cc:1 ...
The function name printed is actually coming from debug info, not the symbol name. If the symbol is lost but debug info still knows about it, this may be useful. For example: $ clang -g -c foo.c -o foo.o $ strip -N foo foo.o $ objdump -ld foo.o ... 0000000000000000 <.text>: foo(): <--- foo.o only knows we're in .text, but debug info still knows the name /tmp/foo.c:1 0: 55 push %rbp ... $ llvm-objdump -ld foo.o ... 0000000000000000 .text: ; /tmp/foo.c:1 0: 55 pushq %rbp
Or, with a more common workflow (not sniping out specific symbols): $ cat foo.c int foo() { return 5; } int bar() { return 10; } $ clang -g -c foo.c -o foo.o $ objcopy --only-keep-debug foo.o foo.dbg $ strip foo.o $ objcopy --add-gnu-debuglink=foo.dbg foo.o $ objdump -ld foo.o ... 0000000000000000 <.text>: foo(): /tmp/foo.c:1 0: 55 push %rbp 1: 48 89 e5 mov %rsp,%rbp 4: b8 05 00 00 00 mov $0x5,%eax 9: 5d pop %rbp a: c3 retq b: 0f 1f 44 00 00 nopl 0x0(%rax,%rax,1) bar(): /tmp/foo.c:2 10: 55 push %rbp 11: 48 89 e5 mov %rsp,%rbp 14: b8 0a 00 00 00 mov $0xa,%eax 19: 5d pop %rbp 1a: c3 retq