[PATCH] elf: Set text-segment address to the maximum page size

H.J. Lu hjl.tools@gmail.com
Thu Jun 25 15:46:58 GMT 2026


On Thu, Jun 25, 2026 at 10:42 PM Nick Clifton <nickc@redhat.com> wrote:
>
> Hi H.J.
>
> >       PR ld/34184
> >       * ldexp.c (fold_binary): Set text-segment address to the maximum
> >       page size for ELF PDE output with -z max-page-size=SIZE.
> >       * testsuite/ld-elf/elf.exp: Add ld/34184 test.
> >       * testsuite/ld-elf/pr34184.c: New file.
>
> I like this patch, but I do have a couple of comments:
>
> > +      /* When generating Position Dependent Executable for ELF with the
> > +      maximum page size set on command-line, if text-segment address
> > +      is lower than the maximum page size, set text-segment address
> > +      to the maximum page size.  */
> > +      if ((bfd_get_flavour (link_info.output_bfd)
> > +        == bfd_target_elf_flavour)
> > +       && bfd_link_pde (&link_info)
> > +       && link_info.maxpagesize_is_set
> > +       && link_info.maxpagesize > value
> > +       && strcmp (segment_name, "text-segment") == 0)
> > +     value = link_info.maxpagesize;
>
> I think that it would be helpful to inform the user that the text
> segment address is being changed - *if* they have tried to set it
> using --image-base or --Ttext-segment.  Otherwise they may wonder
> why their command line option is being ignored.

Will do.

>
> > +    [list \
> > +     "Run pr34184" \
> > +     "-Wl,-z,max-page-size=0x800000" \
> > +     "" \
> > +     {pr34184.c} \
> > +     "pr34184" \
> > +     "pass.out" \
> > +    ] \
>
> As far as I can tell, this test does not actually check that
> the text segment's address is now a multiple of the max page
> size...

This is a run-time test.  Without the fix, we get segfault:

[hjl@gnu-tgl-3 tmp]$ cat x.c
int
main ()
{
  return 0;
}
[hjl@gnu-tgl-3 tmp]$ gcc -Wl,-z,max-page-size=0x800000 x.c
[hjl@gnu-tgl-3 tmp]$ ./a.out
Segmentation fault         ./a.out
[hjl@gnu-tgl-3 tmp]$


-- 
H.J.


More information about the Binutils mailing list