[PATCH v4] elf: Set image base address to the maximum page size
H.J. Lu
hjl.tools@gmail.com
Fri Jun 26 04:06:50 GMT 2026
On Thu, Jun 25, 2026 at 11:46 PM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> 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.
Fixed in the v4 patch.
> >
> > > + [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.
Here is the v4 patch.
--
H.J.
---
When generating Position Dependent Executable for ELF with the maximum
page size set on command-line, set the default image base address to the
maximum page size to avoid segfault if it is lower than the maximum page
size and issue an warning if the image base address set on command-line
is lower than the maximum page size.
PR ld/34184
* ldexp.c (fold_binary): Set the default image base address to
the maximum page size for ELF PDE output if it is lower than
the maximum page size set on command-line and issue an warning
if the image base address set on command-line is lower than the
maximum page size.
* testsuite/ld-elf/elf.exp: Add ld/34184 tests for PDE, PIE
static PDE and static PIE.
* testsuite/ld-elf/pr34184.c: New file.
* testsuite/ld-elf/textaddr3.d: Change -Ttext-segment adddress
to 0x200100 so that it > the maximum page size.
* testsuite/ld-elf/textaddr5.d: Likewise.
* testsuite/ld-elf/textaddr8.d: New test.
* testsuite/ld-elf/textaddr9.d: Likewise.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: v4-0001-elf-Set-image-base-address-to-the-maximum-page-si.patch
Type: text/x-patch
Size: 7470 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/binutils/attachments/20260626/2d38e265/attachment.bin>
More information about the Binutils
mailing list