LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 41341 - llvm-objdump -d --line-numbers omits function name
Summary: llvm-objdump -d --line-numbers omits function name
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: llvm-objdump (show other bugs)
Version: trunk
Hardware: PC Linux
: P enhancement
Assignee: Unassigned LLVM Bugs
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-01 22:21 PDT by Jordan Rupprecht
Modified: 2020-02-26 10:40 PST (History)
3 users (show)

See Also:
Fixed By Commit(s): 266877a2a8b2d1939f3b08fcfb711890fefc96e3


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jordan Rupprecht 2019-04-01 22:21:33 PDT
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
Comment 1 Eric Christopher 2019-04-01 22:29:25 PDT
No strong preference. Almost assuredly not intentional. It seems a little redundant?
Comment 2 Jordan Rupprecht 2019-04-01 22:48:11 PDT
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
...
Comment 3 Jordan Rupprecht 2019-04-02 15:14:53 PDT
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
Comment 4 Jordan Rupprecht 2019-04-02 15:32:22 PDT
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