Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

llvm-objdump -d --line-numbers omits function name #40686

Closed
rupprecht opened this issue Apr 2, 2019 · 4 comments
Closed

llvm-objdump -d --line-numbers omits function name #40686

rupprecht opened this issue Apr 2, 2019 · 4 comments
Labels
bugzilla Issues migrated from bugzilla tools:llvm-objdump

Comments

@rupprecht
Copy link
Collaborator

Bugzilla Link 41341
Resolution FIXED
Resolved on Feb 26, 2020 10:40
Version trunk
OS Linux
CC @dwblaikie,@echristo
Fixed by commit(s) 266877a

Extended Description

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(): <--------- 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

@echristo
Copy link
Contributor

echristo commented Apr 2, 2019

No strong preference. Almost assuredly not intentional. It seems a little redundant?

@rupprecht
Copy link
Collaborator Author

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
...

@rupprecht
Copy link
Collaborator Author

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

@rupprecht
Copy link
Collaborator Author

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

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla tools:llvm-objdump
Projects
None yet
Development

No branches or pull requests

2 participants