[PATCH v8 3/6] elf: Introduce _dl_map_segment_align hook for segment alignment tuning

H.J. Lu hjl.tools@gmail.com
Thu Apr 9 11:47:23 GMT 2026


On Thu, Apr 9, 2026 at 6:21 PM Wilco Dijkstra <Wilco.Dijkstra@arm.com> wrote:
>
> Hi HJ,
>
> > > > > > > >   LOAD           0x000000 0x00400000 0x00400000 0x16d110 0x16d110 R   0x1000
> > > > > > > >   LOAD           0x16e000 0x0056e000 0x0056e000 0x1055d9 0x1055d9 R E 0x1000
> > > > > > > >
> > > > > > > > into a single RE THP map.
> > >
> > > So my question is why do we need to do this in both loaders?
> > >
> > > Shouldn't the linker just do better here? Eg. it can merge program headers
> > > and related read-only data into the text segment even with -zseparate-code.
> >
> > x86 linker on master branch no longer does that after the fix for
> >
> > https://sourceware.org/bugzilla/show_bug.cgi?id=34003
>
> So x86 now starts with R+X load segment by default?

That was before the bug fix.  Now we get:

  LOAD           0x000000 0x00400000 0x00400000 0x16d110 0x16d110 R   0x1000
  LOAD           0x16e000 0x0056e000 0x0056e000 0x1055d9 0x1055d9 R E 0x1000
  LOAD           0x273ebc 0x00674ebc 0x00674ebc 0x02540 0x039fc RW  0x1000

> However I'm still not convinced that what you're trying to do is correct - it seems to me you can't
> just decide to merge segments when the user requested -zseperate-code or --rosegment. Those
> segments exist for a reason.

After the bug fix, x86 linker no longer puts read-only data, including ELF
headers, in R+X load segment with -z seperate-code --rosegment.

> The loader could support R, R+X load segments and still align for THP without merging them.
>

I was told that THP needed to start from the file offset 0.  So

  LOAD           0x16e000 0x0056e000 0x0056e000 0x1055d9 0x1055d9 R E 0x1000

doesn't work for THP.

> Cheers,
> Wilco



-- 
H.J.


More information about the Libc-alpha mailing list