binutils Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
binutils/ld

ld: Fix SEGV in elf_orphan_compatible for PR 34450

Fixes a segmentation fault in `elf_orphan_compatible` when handling ELF sections with `SHF_LINK_ORDER`.

This commit addresses a segmentation fault (SEGV) in the elf_orphan_compatible function within the GNU linker (ld). The issue occurred because the code did not properly check for null pointers when SHF_LINK_ORDER was set. The fix adds a necessary sanity check for linked_to before dereferencing it, preventing the crash.

In Details

The elf_orphan_compatible function in ldelf.c previously assumed that if SHF_LINK_ORDER was set on an input and output section, then elf_linked_to_section(in) and elf_linked_to_section(out) would be non-NULL. This commit adds checks for elf_linked_to_section(out) != NULL to prevent a NULL pointer dereference when linked_to is NULL, resolving PR 34450.

For Context
SEGV
Segmentation Violation. A runtime error that occurs when a program attempts to access a memory location that it is not allowed to access.
elf_orphan_compatible
A function within the GNU linker (ld) that handles the compatibility of ELF sections that are considered 'orphans' (sections not directly associated with a symbol).
SHF_LINK_ORDER
A flag in the ELF file format that indicates a section's placement relative to other sections. It affects the order in which sections are laid out in the output file.
linked_to
In the context of ELF sections, 'linked_to' likely refers to a pointer or reference indicating another section that a given section is logically linked with, often used in conjunction with SHF_LINK_ORDER.
ELF relocation
Information within an object file that describes how to modify memory addresses and other references when the code or data is loaded into memory at a different address than that assumed during linking. This is crucial for Position-Independent Code (PIC).
Filed Under: binutilslinkerbugfixELFcrash