[PATCH] objdump: Show correct file offsets for symbols
Jan Beulich
jbeulich@suse.com
Fri Oct 17 12:02:12 GMT 2025
On 16.10.2025 19:00, Ben Kallus wrote:
> 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.
And it potentially being a different section is because of
find_symbol_for_address() may not be required to stick to the incoming
section, as per ->application_data->require_sec? That's the kind of
detail that would have made reviewing easier.
> 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,
Nit: This line is now too long. Okay with this adjusted, and provided
my understanding above is correct. Assuming you will need this committed
on your behalf anyway, I can of course make the respective edit while
committing, so long as you agree.
Jan
More information about the Binutils
mailing list