binutils Newspaper
NOVEMBER 30, 2026
loongarch — Committed

LoongArch: Reject foreign ELF inputs during relocation

Prevents linking of non-LoongArch ELF files by checking input BFD format before relocation processing.

This patch addresses a bug (PR ld/34807) by ensuring that the linker rejects non-LoongArch ELF inputs before attempting relocation processing. This prevents potential errors or incorrect behavior when mixing object files from different architectures.

In the Thread 2 participants
  1. zhaozhou proposer

    Submitted a patch to reject non-LoongArch ELF inputs during relocation.

    “Reject non-LoongArch inputs before processing relocations. PR ld/34807”
  2. Alan Modra <amodra@gmail.com> maintainer

    Accepted the patch.

    “OK.”

Technical Tradeoffs

  • Adds an explicit check to reject unsupported file formats early in the linking process, improving robustness.

In Details

This change to the LoongArch ELF backend ensures that loongarch_elf_relocate_section only processes input BFDs that are identified as LoongArch ELF files. It adds an explicit check for is_loongarch_elf early in the function, returning an error if the format is incorrect, thus preventing potential issues with cross-architecture linking or malformed object files.

For Context
LoongArch
A RISC-based instruction set architecture developed in China.
ELF
Executable and Linkable Format. A common standard file format for object files, executables, shared libraries, and core dumps on Unix-like systems.
relocation
The process of updating symbolic references in object code to absolute or relocatable addresses during linking.
BFD
Binary File Descriptor library. A low-level library used by GNU Binutils to parse and manipulate object files from various architectures and formats.
Filed Under: loongarchlinkerELFrelocation