RFC: Add GNU_PROPERTY_NEED_PHDRS

H.J. Lu hjl.tools@gmail.com
Tue Oct 2 16:23:00 GMT 2018


On Tue, Oct 2, 2018 at 8:48 AM Michael Matz <matz@suse.de> wrote:
>
> Hi,
>
> On Tue, 2 Oct 2018, H.J. Lu wrote:
>
> > > > If linker script discards a section, all bets are off.  Anything can
> > > > happen.
> > >
> > > I disagree, but even if I'd agree your solution still is more
> > > accidental than by design.  You want to guarantee something about
> > > program headers, so any solution that doesn't do anything specific
> > > about/with program headers is similarly accidental.
> >
> > Nothing is guaranteed when linker script is used since anything can
> > happen with linker script.
>
> Ignore the parts about the linker script, I disagree with you, but that's
> immaterial to my main point.  Your solution still is only an accidental
> one as you don't do anything about program headers but instead just add
> magic sections to magic places that happens to do what you want currently.
> That's not by design.

The problem is

1. Linker kernel passes AT_PHDR to main and assumes that AT_PHDR
is in a PT_LOAD segment.
2. gABI doesn't require phdrs in a PT_LOAD segment.
3. Ld won't create a PT_LOAD segment just to hold phdrs.
4. With -z separate-code, linker won't put any non-code in a PF_X PT_LOAD
segment.

When there are only PF_X PT_LOAD segments, phdrs isn't in any PT_LOAD
segment.

You are looking for a solution to create a PT_LOAD segment just to hold phdrs.
I have investigated it.  It is very intrusive.  My solution, which you
called a hack,
is to add a read-only SHF_ALLOC section so that a PT_LOAD segment will
be created by ld to hold phdrs when there is only PF_X PT_LOAD segments
otherwise.

-- 
H.J.



More information about the Binutils mailing list