objdump `–adjust-vma` destroys debug info
When using the --adjust-vma
option of objdump
all the functions get squashed together, as if there is no debug information about where each function starts.
I’ll demonstrate with the following simple C file (a.c
):
void func(void)
{
}
int main()
{
}
Compile it using gcc -g a.c
Now without the --adjust-vma
I get plenty of information :
$ objdump -d a.out
Disassembly of section .text:
0000000000001040 <_start>:
----- Many other functions which I cut off -------
0000000000001129 <func>:
1129: f3 0f 1e fa endbr64
112d: 55 push %rbp
112e: 48 89 e5 mov %rsp,%rbp
1131: 90 nop
1132: 5d pop %rbp
1133: c3 ret
0000000000001134 <main>:
1134: f3 0f 1e fa endbr64
1138: 55 push %rbp
1139: 48 89 e5 mov %rsp,%rbp
113c: b8 00 00 00 00 mov $0x0,%eax
1141: 5d pop %rbp
1142: c3 ret
But with --adjust-vma
I get the following:
$ objdump -d a.out --adjust-vma=0x100000
Disassembly of section .text:
0000000001001040 <main+0xffff0c>:
-------- No function markers, just a lot of instructions one after the other -------
# AM: That's the original `func`
1001129: f3 0f 1e fa endbr64
100112d: 55 push %rbp
100112e: 48 89 e5 mov %rsp,%rbp
1001131: 90 nop
1001132: 5d pop %rbp
1001133: c3 ret
# AM: That's the original `main`
1001134: f3 0f 1e fa endbr64
1001138: 55 push %rbp
1001139: 48 89 e5 mov %rsp,%rbp
100113c: b8 00 00 00 00 mov $0x0,%eax
1001141: 5d pop %rbp
1001142: c3 ret
Any idea why this happens?
The manual for objdump says this about the --adjust-vma option
When dumping information, first add offset to all the section addresses. This is useful if the section addresses do not correspond to the symbol table, which can happen when putting sections at particular addresses when using a format which can not represent section addresses, such as a.out.
A case where I would use this if I were packing code into a boot rom that I then was going to copy into ram and execute[1]. To make sense of the code that is stored in the rom, one wants to ignore the addresses as they are in the rom and consider what the addresses will be once it is copied into ram. The debug information reflects the code at the ram locations, not the copy being stored in the rom. The --adjust-vma
option allows you to add the constant that is the difference between the rom and ram addresses,
Put another way, the --adjust-vma
doesn’t adjust debug information, just the addresses of the code.
[1] Code typically executes much faster from ram than rom, so if the code doesn’t fit in the cpu cache it can be worth the extra time to copy code from rom to ram.