loadbase alignment - ld.so/prelink/kernel or bfd_elf_bfd_from_remote_memory() bug?

H.J. Lu hjl@lucon.org
Wed Aug 15 16:00:00 GMT 2007


On Wed, Aug 15, 2007 at 05:13:48PM +0200, Jakub Jelinek wrote:
> On Wed, Aug 15, 2007 at 03:56:10PM +0200, Jan Kratochvil wrote:
> > bfd_elf_bfd_from_remote_memory() would almost work for general ELF files but it
> > fails (I have no simple testcase) now due to the ELF `Base address' alignment.
> > BFD uses `& -i_phdrs[i].p_align' for the VMA addresses but the real mapping
> > is only PAGE_SIZE aligned (illustrated in the `BEFORE' dumps below).
> > 
> > For x86_64:
> > 
> > * bfd_elf_bfd_from_remote_memory() expects `loadbase' is P_ALIGN aligned.
> > 
> >   * GCC on x86_64 produces P_ALIGN 0x200000 == 2MB.
> 
> If bfd_elf_bfd_from_remote_memory() doesn't handle it, then it should be
> fixed.  The current ld.so/prelink/kernel behavior is desirable.
> 

I can see both approaches make senses. On one hand, BFD doesn't
know what the run-time page size is. BFD has to use a constant like
the maximum page size. On the other hand, we may not want to waste
address space at run-time. But it does violate gABI. We hadn't
run into any problems up to now since only ld.so cares about base
address so far. It won't work when BFD also needs base address. If we
want to keep the current ld.so behavior and also support base address
in BFD, I suggest we should

1. Modify the gABI to use the maximum run-time page size when
computing base address, instead of the maximum page size.
2. Modify BFD to take the maximum run-time page size, which can
be set at run-time, and use it to compute base address.


H.J.



More information about the Binutils mailing list