[PATCH] objdump: Show correct file offsets for symbols
Ben Kallus
benjamin.p.kallus.gr@dartmouth.edu
Thu Oct 16 17:00:53 GMT 2025
With the -F flag, objdump shows the wrong file offsets for symbols
referenced from another section.
For an example, consider the following C program:
> volatile int i = 1;
> int main(void) { return i; }
If you build it with amd64 GCC 15.2.1 for GNU/Linux, i ends up in
.data, and main ends up in .text. If you objdump -FD the binary,
and look at the disassembly for i, it will be something like this:
> 0000000000004010 <i> (File Offset: 0x3010):
If you then look at the instruction in main that loads i, it will
be something like this:
> mov 0x2eed(%rip),%eax # 4010 <i> (File Offset: 0x4010)
This is the wrong file offset. The file offset should be 0x3010,
as shown above.
This is because objdump_print_addr passes the wrong section arg
when it calls objdump_print_addr_with_sym. Instead of passing the
section for the symbol being printed, it passes the section for
the instruction being disassembled. In this case, the instruction
being disassembled is in .text, but the symbol being printed is in
.data, so the file offset is incorrect.
This patch fixes the bug by passing the correct section to
objdump_print_addr_with_sym.
---
binutils/objdump.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 513f6162204..8d9b58a5f23 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -1738,7 +1738,7 @@ objdump_print_addr (bfd_vma vma,
if (!skip_find)
sym = find_symbol_for_address (vma, inf, &place);
- objdump_print_addr_with_sym (aux->abfd, inf->section, sym, vma, inf,
+ objdump_print_addr_with_sym (aux->abfd, bfd_asymbol_section (sym), sym, vma, inf,
skip_zeroes);
/* If requested, display any extra symbols at this address. */
--
2.51.0
More information about the Binutils
mailing list