binutils Newspaper
NOVEMBER 30, 2026
binutils/x86 — Proposed

x86: Drop empty .relr.dyn from PHDRS segments

Ensures empty .relr.dyn sections are correctly excluded from segments when using PHDRS in the linker script.

This patch addresses an issue where an empty .relr.dyn section could be incorrectly included in a segment when using linker scripts with PHDRS. The linker currently removes this section but doesn’t mark it as excluded, leading to it being processed during segment map creation and potentially causing errors or incorrect segment sizing. The fix ensures the section is marked with SEC_EXCLUDE before removal, aligning its handling with other excluded sections.

In the Thread 1 participant
  1. mintsuki@protonmail.com proposer

    Submits a patch to correctly exclude empty .relr.dyn sections when PHDRS are used.

    “Set SEC_EXCLUDE on it before removing it, as those do. bfd/ * elfxx-x86.c (_bfd_elf_x86_size_relative_relocs): Set SEC_EXCLUDE on the empty .relr.dyn output section before removing it. ld/ * testsuite/ld-i386/dt-relr-3.d: New file. * testsuite/ld-i386/i386.exp: Run dt-relr-3. * testsuite/ld-x86-64/dt-relr-3-x32.d: New file. * testsuite/ld-x86-64/dt-relr-3.d: Likewise. * testsuite/ld-x86-…”

In Details

In binutils/ld, when using -z pack-relative-relocs and a linker script with PHDRS, an empty .relr.dyn section can cause issues. The _bfd_elf_x86_size_relative_relocs function removes this section from the section list but doesn't mark it with SEC_EXCLUDE. This prevents elf_modify_segment_map from dropping it, leading to incorrect segment assignment and sizing when PHDRS are processed before section exclusion. This patch adds SEC_EXCLUDE.

For Context
.relr.dyn
A dynamic section in ELF executables that contains relocation information, specifically for position-independent code (PIC) or position-independent executables (PIE), used at runtime by the dynamic linker.
PHDRS
Program Headers in an ELF file, which describe how the segments of the program should be mapped into memory by the operating system. Linker scripts can use PHDRS to control segment layout.
SEC_EXCLUDE
A flag or attribute associated with a section in the linker's internal representation, indicating that the section should not be included in the final executable's segments or memory map.
ld
The GNU linker, responsible for combining object files and libraries into an executable or shared library.
linker script
A file used by the linker to control the memory layout of the output file, specifying where sections should be placed and how segments are formed.
Filed Under: binutilsldlinkerx86elf