binutils Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
loongarch

LoongArch: Reject non-LoongArch ELF inputs during relocation

The LoongArch ELF backend now rejects incompatible ELF object files before relocation processing.

This commit enhances the LoongArch ELF backend in binutils by adding a check to reject any non-LoongArch ELF inputs during the relocation process. This prevents potential errors and misinterpretations when the linker attempts to handle object files not intended for the LoongArch architecture, addressing a reported bug.

In Details

This change adds a safety check to bfd/elfnn-loongarch.c within the loongarch_elf_relocate_section function. Before proceeding with relocation processing for a LoongArch object file, it now verifies that the input BFD (input_bfd) is indeed a LoongArch ELF file using is_loongarch_elf. If it's not, it sets the BFD error to bfd_error_wrong_format and returns false, effectively rejecting foreign ELF inputs at an early stage. This prevents potential issues during relocation, as seen in PR ld/34807.

For Context
LoongArch
A RISC-based instruction set architecture (ISA) developed in China.
ELF
Executable and Linkable Format. A standard file format for executables, object code, shared libraries, and core dumps, used on many Unix-like systems.
Relocation
The process performed by a linker or loader to resolve symbolic addresses and references in object code, so that code can be loaded at a specific memory address. This involves adjusting addresses and patching instructions or data.
BFD
Binary File Descriptor library. A GNU library that provides a common interface to describe and manipulate various executable file formats, including ELF.
Linker
A program that combines various code and data modules into a single executable file or library. It resolves external references between these modules.
Filed Under: loongarchlinkerelfsecurity