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: RFC: Add GNU_PROPERTY_NEED_PHDRS


On Tue, Oct 02, 2018 at 02:06:43PM -0700, Cary Coutant wrote:
> Even with no-separate-code, or with a read-only segment before the
> text, the inclusion of the program headers in the first PT_LOAD
> segment is merely a happy accident -- it's a side effect of way the
> linker rounds segment boundaries down and up to page boundaries, and
> depends entirely on the property that the first PT_LOAD segment falls
> within the first page of the executable file.

As Michael would say, it's a hack.  ;-)

> > 3. Ld won't create a PT_LOAD segment just to hold phdrs.
> 
> You seem to be breezing right past the idea of doing exactly this.
> Why? The scripting language already allows you to declare which
> segment should include FILEHDR and PHDRS. For -z separate-code, why
> not use a default linker script with something like the following?
> 
>      PHDRS
>      {
>        headers PT_PHDR PHDRS ;
>        interp PT_INTERP ;
>        header_seg PT_LOAD FILEHDR PHDRS ;
>        text PT_LOAD ;
>        data PT_LOAD ;
>        dynamic PT_DYNAMIC ;
>      }

The script idea is probably not practical in view of all the
variations of headers we'd need.  PT_NOTE, PT_TLS, PT_GNU_EH_FRAME,
PT_GNU_STACK, PT_GNU_RELRO come to mind, some of which depend on
executable contents.

I do agree that ld should be modified to create a PT_LOAD just for
headers when needed, probably keyed off SIZEOF_HEADERS in a script.

> And, really, there's no denying that adding an otherwise-unnecessary
> note section -- just to get us back into the realm of "it works by
> happy accident" -- is a pure hack.

I don't particularly like the note section hack, but I can see why HJ
did it that way.  Adding a note section no doubt avoids objcopy bugs
that would otherwise need to be fixed.

-- 
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]