elf: Set text-segment address to the maximum page size
Checks
| Context |
Check |
Description |
| linaro-tcwg-bot/tcwg_binutils_build--master-arm |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_build--master-aarch64 |
success
|
Build passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-arm |
success
|
Test passed
|
| linaro-tcwg-bot/tcwg_binutils_check--master-aarch64 |
success
|
Test passed
|
Commit Message
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.
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.
From a6ec71ac7385ee7fc8c9dc353ffde5f239ace5da Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Thu, 28 May 2026 10:47:37 +0800
Subject: [PATCH] elf: Set text-segment address to the maximum page size
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.
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.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
---
ld/ldexp.c | 13 +++++++++++++
ld/testsuite/ld-elf/elf.exp | 8 ++++++++
ld/testsuite/ld-elf/pr34184.c | 8 ++++++++
3 files changed, 29 insertions(+)
create mode 100644 ld/testsuite/ld-elf/pr34184.c
@@ -552,6 +552,19 @@ fold_binary (etree_type *tree)
/* Check to see if the user has overridden the default
value. */
segment_name = tree->binary.rhs->name.name;
+
+ /* 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;
+
for (seg = segments; seg; seg = seg->next)
if (strcmp (seg->name, segment_name) == 0)
{
@@ -700,6 +700,14 @@ run_ld_link_exec_tests [list \
"" \
"tmpdir/pr26391-6.o" \
] \
+ [list \
+ "Run pr34184" \
+ "-Wl,-z,max-page-size=0x800000" \
+ "" \
+ {pr34184.c} \
+ "pr34184" \
+ "pass.out" \
+ ] \
]
set merge_exec_tests {
new file mode 100644
@@ -0,0 +1,8 @@
+#include <stdio.h>
+
+int
+main ()
+{
+ printf ("PASS\n");
+ return 0;
+}
--
2.54.0