This is the mail archive of the
gdb-patches@sourceware.org
mailing list for the GDB project.
Re: [PATCH 2/3] relocate the entry point addess when used
- From: Pedro Alves <palves at redhat dot com>
- To: Tom Tromey <tromey at redhat dot com>
- Cc: gdb-patches at sourceware dot org
- Date: Wed, 15 Jan 2014 11:42:29 +0000
- Subject: Re: [PATCH 2/3] relocate the entry point addess when used
- Authentication-results: sourceware.org; auth=none
- References: <1389040247-2620-1-git-send-email-tromey at redhat dot com> <1389040247-2620-3-git-send-email-tromey at redhat dot com> <52CD5129 dot 7090003 at redhat dot com> <8738kr1ug8 dot fsf at fleche dot redhat dot com>
On 01/13/2014 08:46 PM, Tom Tromey wrote:
>>>>>> "Pedro" == Pedro Alves <palves@redhat.com> writes:
>
> Tom> I think the existing code here is wrong. It computes the entry point
> Tom> address directly from the BFD, not applying any runtime offsets.
> Tom> However, then objfile_relocate1 passes this address to find_pc_section
> Tom> -- which does use the offsets . So, it seems to me that the current
> Tom> code can only find the correct address by luck.
>
> Pedro> It's twisted, but I don't think it's luck. You can convince yourself
> Pedro> it works by debugging a PIE, and trying a backtrace past main
> Pedro> ("set backtrace past-main" will then trigger the code to stop the
> Pedro> backtrace at the entry point), or doing "info files" (shows the entry).
>
> Well, what I don't understand is that most addresses in dwarf2read.c are
> offset:
>
> baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile));
>
> ... however this is not done for the entry point, which comes directly
> from the BFD:
>
> objfile->per_bfd->ei.entry_point = bfd_get_start_address (objfile->obfd);
>
> I suppose there is some other invariant ensuring that the entry point is
> only computed when all the objfile offsets are zero. This part is not
> obvious to me.
I think it's just that the entry point is only really used for the main
executable, and if that is loaded at some relocation offset, we'll
always go through objfile_relocate (either PIE handling, or RSP
qOffsets handling for embedded systems) after reading in symbols,
while shared libraries are read in with the offsets already handy
upfront. Even though init_entry_point_info seemingly computes the
entry point for shared libraries, that's really still for the
main executable:
https://sourceware.org/ml/gdb-patches/2008-05/msg00112.html
and is probably indeed wrong for real shared libraries not
the main executable.
I do think your patch makes things much clearer and sturdier.
>
> [...]
> Pedro> This is assuming osect ends up NULL after iterating over all.
> Pedro> It's violating the abstraction of the macro. And, actually,
> Pedro> it's wrong, showing exactly why such assumptions are a bad idea:
>
> Sorry about that, I'll fix it up locally.
Thanks.
--
Pedro Alves