binutils Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
ld.bfd

LoongArch: Fix relaxation alignment with ld -r

Binutils linker fixes LoongArch relaxation alignment issues when using `ld -r`.

Binutils’ linker (ld) now correctly handles relaxation alignment on LoongArch when operating in relinkable mode (ld -r). This commit corrects the sh_size and sh_entsize of sections containing relocation information, ensuring they use the size of external relocations. This fixes issues causing assembler-generated notes in linkonce sections to fail during relinking and improves alignment handling for ld-loongarch-elf/relax-align-ld-r test cases.

In Details

For LoongArch, the dynamic linker uses relaxation to adjust branch and load instructions at link time. When ld -r is used, creating an intermediate object file, the linker needs to correctly record segment information for subsequent linking steps. This patch corrects the ELF section header definitions (sh_size, sh_entsize) for relocation sections in elfnn-loongarch.c to accurately reflect the size of external relocation entries (ElfNN_External_Rela) rather than internal ones (Elf_Internal_Rela), resolving alignment and relaxation issues in relinked objects.

For Context
ld -r
An option for the GNU linker (ld) that performs a partial link, combining input object files into a single output file without resolving all symbols. The output is typically suitable for further linking.
relaxation
A linking process where the linker modifies instructions in the object code to optimize them for the target architecture, often related to address or branch calculations that are not yet fully resolved.
LoongArch
A family of RISC-based CPU architectures developed in China.
ELF (Executable and Linkable Format)
A standard file format for executables, object code, shared libraries, and core dumps on many Unix-like systems.
sh_size
In an ELF section header, this field indicates the size of the section in bytes.
sh_entsize
In an ELF section header, this field indicates the size in bytes of entries in a table section, such as a symbol table or relocation table.
Filed Under: binutilslinkerLoongArchrelaxation