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

Improve error checking for garbage collection in ELF backend

ld now properly reports errors during ELF garbage collection when input sections have invalid data.

The linker’s ELF backend now correctly handles errors during garbage collection of input sections. Previously, the bfd_gc_sections function could return false on invalid input without the linker reporting a fatal error. This change ensures that if gc_mark_extra_sections returns an error, bfd_gc_sections also returns false, and lang_gc_sections checks this return value to report a fatal error, preventing incorrect linking.

In Details

Modifies bfd_elf_gc_sections to propagate errors from gc_mark_extra_sections by returning false. It also updates lang_gc_sections to check the return value of bfd_gc_sections and report a fatal error accordingly. This addresses PR ld/34448, ensuring that invalid input section garbage collection states are properly flagged.

For Context
ld
The standard GNU linker program. It takes object files and archives as input and links them together to produce an executable, a shared library, or another object file.
garbage collection (GC)
In the context of linkers, garbage collection refers to the process of identifying and discarding unused sections or symbols from input object files, thus reducing the size of the final executable.
ELF
Executable and Linkable Format. A common standard file format for object files, executables, shared libraries, and core dumps on Unix-like systems.
bfd
Binary File Descriptor library. A low-level library used by binutils and GDB to support various binary file formats, including ELF.
Filed Under: ldlinkerelfgarbage collectionerror handling