objdump and resolving linkage of local function calls?
Asked Answered
E

1

9

If I run objdump -d on a (linux amd64) .o file, function calls show up without the link time resolution done. Example:

  90:   66 89 44 24 1c          mov    %ax,0x1c(%rsp)
  95:   44 89 74 24 10          mov    %r14d,0x10(%rsp)
  9a:   e8 00 00 00 00          callq  9f <foo+0x9f>
  9f:   83 f8 ff                cmp    $0xffffffffffffffff,%eax
  a2:   74 5e                   je     102 <foo+0x102>

A branch within the function shows up properly, but the callq is just the stub put in for the linker (with four bytes of zeros available for the linker to put a proper address into).

Is there a way, without actually linking, to get an assembly listing that has the function names resolved? I don't care about the address that will eventually be used, just the name of the function. That info has got to be in the .o file, since the linker must consume it to do its job.

I ask because the shared lib that the code in question goes into is about 140Mb, and it takes a long time to run objdump -d on that to get the asm dump with all the function calls resolved to their actual names.

Enloe answered 24/1, 2012 at 19:35 Comment(2)
I've figured out a workaround for my specific problem. I can run nm to get the function address in our huge shared lib, and then run objdump with --start-address using that nm output. I'd still be interested in an answer to the original question though if it is possible.Enloe
Related: meaning of an entry in a relocation table of an object file for more details about relocation entries.Dialectal
S
18

Is there a way, without actually linking, to get an assembly listing that has the function names resolved?

Yes: use objdump -dr foo.o

Stifling answered 25/1, 2012 at 5:2 Comment(1)
I like objdump -drwC -Mintel because -w and -C are nice, too: no line wrapping, and demangle C++ names. (I alias disas='objdump -drwC -Mintel' in my shell.)Dialectal

© 2022 - 2024 — McMap. All rights reserved.