binutils Newspaper
JUNE 15, 2026
elf Proposed

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

This patch sets the text-segment address to the maximum page size for ELF Position Dependent Executables (PDEs) when specified via command-line to avoid loadin…

This patch (v2) addresses an issue where the text-segment address of an ELF Position Dependent Executable (PDE) could be lower than the maximum page size specified on the command line. The patch modifies the linker to ensure that the text-segment address is set to the maximum page size when generating PDE output with the -z max-page-size=SIZE option. This prevents potential loading issues, particularly with PIE (Position Independent Executable), static PDE, and static PIE binaries, and includes added tests for these scenarios.

In Details

The linker's fold_binary function in ldexp.c is modified to adjust the text-segment address for ELF PDEs. This ensures that the text segment is aligned to the maximum page size specified via -z max-page-size. This addresses PR ld/34184 and includes new test cases (testsuite/ld-elf/pr34184.c) and updates to the test suite (testsuite/ld-elf/elf.exp) to cover PIE, static PDE, and static PIE scenarios. This is crucial for systems where page alignment affects execution.

For Context

When creating executable files, the linker assigns memory addresses to different parts of the program, including the text segment (containing the program's code). Page size refers to the size of a memory page, which is a unit of memory management used by the operating system. This patch ensures that the starting address of the program's code is aligned to the maximum page size specified during linking. This alignment is important for performance and security reasons, especially for Position Dependent Executables (PDEs) and Position Independent Executables (PIEs), which can be loaded at different memory addresses each time they are run. The -z max-page-size option controls the maximum page size used by the linker.

Filed Under: elflinkerpage sizepdepie