binutils Newspaper
OCTOBER 6, 2026
elf — Needs Revision — Sentiment 4 / 10

elf: Avoid relocating non-allocated code sections

Fixes binutils linker to correctly handle non-allocated code sections, preventing crashes.

This patch addresses a bug in the binutils linker where it would abort when attempting to relocate non-allocated code sections. The original fix proposed to issue an error, but was deemed insufficient. The discussion clarifies that the issue stems from the x86 backend’s handling of such sections when using GOT or PLT, and the fix is being moved to the backend to properly manage these cases, resolving PR ld/34444.

In the Thread 5 participants
  1. H.J. Lu proposer

    Proposes to issue an error when encountering a non-allocated code section, as they cannot be properly relocated.

    “Since non-allocated code sections can't be properly relocated, issue an error on such input.”
  2. Alan Modra reviewer

    Argues that the proposed error is not a proper fix, as the root cause is a relocation offset out of range, and the weird flags are secondary. Suggests the fix should address the underlying issue.

    “This is not a proper fix for the bug, which is caused by a reloc offset out of range. The weird flags are just something you see with fuzzed object files.”
  3. H.J. Lu proposer

    Explains that non-allocated code sections using GOT or PLT can lead to an abort in the x86 backend's relocation logic. Proposes to move the check to the x86 backend.

    “If input code section doesn't have SEC_ALLOC, x86-64 linker may abort at if (off >= (bfd_vma) -2) abort (); in elf_x86_64_relocate_section since x86-64 linker has if ((input_section->flags & SEC_ALLOC) != 0 ... if ((input_section->flags & SEC_ALLOC) == 0) I will move the check to x86 backend.”
  4. Jan Beulich reviewer

    Questions why text sections are treated specially and points out that the issue might be with the GOT/PLT usage in non-alloced sections.

    “In addition to what Alan said - why would text sections be different here? Iirc this isn't the first time that you want to treat them specially when there's no provision for that in the spec.”
  5. Alan Modra reviewer

    Agrees that a correction might be needed where the non-alloced sections use GOT or PLT.

    “So that may be where a correction is needed then.”

Technical Tradeoffs

  • Moving the fix to the backend complicates the overall linker logic.
  • The initial approach of disallowing non-allocated code sections was a simpler workaround but deemed incorrect.

In Details

The binutils ELF linker (elflink.c) has logic to handle relocations. A bug was found where non-allocated code sections (those without the SEC_ALLOC flag) could cause the linker to abort, particularly in the x86 backend when using GOT/PLT for resolution. The initial approach was to disallow these sections, but it's recognized as a workaround. The discussion moves towards addressing the issue within the x86 backend where the problematic relocation logic resides.

For Context
relocation
The process of updating symbolic references in relocatable object code to absolute symbols, typically done by the linker.
non-allocated section
An object file section that is not intended to be loaded into memory at runtime (e.g., debug sections).
SEC_ALLOC
A flag indicating that a section should be allocated memory when the program is loaded.
GOT
Global Offset Table, a data structure used by position-independent code to indirectly access global variables and functions.
PLT
Procedure Linkage Table, a table used in position-independent code to dynamically resolve function calls.
PR ld/34444
A bug report filed against the GNU ld linker, identified by the number 34444.
Filed Under: linkerbugfixx86ELF