This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [patch] Fix bfd_elf_bfd_from_remote_memory() loadbase


On Sun, Aug 12, 2007 at 06:15:44PM -0700, Roland McGrath wrote:
> > On Fri, Aug 10, 2007 at 05:15:46PM +0200, Jan Kratochvil wrote:
> > > I believe a simple rule "just the first PT_LOAD segment" implemented in my
> > > patch should be enough.
> > 
> > No.  Please fix this properly as per the ELF gABI.
> 
> Sorry, reading your citation from the spec did not help me have any idea
> what you think "fix this properly" means in this context.
> 
> The situation is that we have some phdrs, and we know an address that is
> the lowest virtual address corresponding to file offset 0.  The task at
> hand is to calculate the base address from that knowledge.
> 
> In a correct object per the spec, "PT_LOAD with lower p_vaddr" is the
> same as "PT_LOAD with lower index".  Ergo, the first PT_LOAD with
> (p_offset & -maxpage) == 0 is the one whose (p_vaddr & -maxpage)
> describes the lowest-addresse mapping of file offset 0.

The test on p_offset was the thing that made me reject Jan's patch.
The spec doesn't even mention p_offset entering the equation for
calculating the base address.  What I missed, due to not looking at
this function's parameters, was that in this case we know one of the
program headers loaded the ELF header into memory, and indeed the
memory address we have is that for the ELF header.

What I'd like to see is:
- remove the nonsense PF_R tests.
- set loadbase using the first header with (p_offset & -p_align) == 0

-- 
Alan Modra
Australia Development Lab, IBM


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]