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

LoongArch linker avoids unnecessary alignment sections with ld -r

Linker now only adds alignment sections for LoongArch when input files contain specific relocation types, fixing kernel module loading issues.

The LoongArch linker no longer unconditionally inserts alignment sections when using ld -r (relocation). It now checks if any input file contains R_LARCH_ALIGN or R_LARCH_RELAX relocations. This change restores correct behavior for kernel modules that expect not to contain these relocations.

In Details

Previously, ld -r on LoongArch would unconditionally insert an .align section if an input file required relaxation. This broke kernel modules on Debian sid because the module loader rejects modules with R_LARCH_ALIGN. This commit adds a flag reloc_may_remove_bytes to the loongarch_elf_link_hash_table to track if any input has R_LARCH_ALIGN or R_LARCH_RELAX, and the .align section is only inserted if this flag is set.

For Context
ld -r
The ld command with the -r option performs a partial link, combining multiple input object files into a single output object file without resolving all symbols. This is often used for creating libraries or kernel modules.
LoongArch
A RISC-V based instruction set architecture developed in China.
relocation
A relocation entry in an object file or executable that specifies how to modify addresses at link-time or load-time to correctly reference symbols. Examples include R_LARCH_ALIGN and R_LARCH_RELAX for LoongArch.
kernel module
A piece of code that can be loaded into and unloaded from the kernel on demand. They extend the functionality of the kernel, e.g. device drivers.
Filed Under: loongarchlinkerkernelrelocation