binutils Newspaper
JULY 29, 2026
loongarch Proposed Sentiment 7 / 10

LoongArch: only insert align section for ld -r if an input has R_LARCH_ALIGN

Fixes LoongArch linker behavior when using `ld -r` to avoid inserting align sections unnecessarily, preventing kernel module loading issues.

Xi Ruoyao proposes a fix for the LoongArch linker when using ld -r, addressing a regression that broke kernel modules. The issue arose because a previous commit unconditionally inserted an align section, which is not expected by modules compiled with -mno-relax. This patch ensures the align section is only created if an input object contains the R_LARCH_ALIGN relocation, thus restoring correct behavior for kernel modules and preventing unnecessary output bloat.

In the Thread 1 participant
  1. Xi Ruoyao <xry111@xry111.site> proposer

    Submits a patch to conditionally insert an align section in `ld -r` for LoongArch, fixing a regression that broke kernel modules.

    “Commit 8bf4b69718d4 ("LoongArch: Fix relaxation alignment with ld -r (PR 33236)") has broken the kernel modules on Debian sid. The expectation of the kernel is all the source files which would be linked into a module are compiled with -mno-relax so the module should not contain R_LARCH_ALIGN, thus the module loader rejects any module containing R_LARCH_ALIGN.”

In Details

This is a revised patch (v2) addressing a regression in LoongArch's ld -r functionality. The core issue is the unconditional insertion of an align section, which breaks kernel module loading because modules compiled with -mno-relax are expected not to contain R_LARCH_ALIGN relocations. The patch makes the insertion conditional on the presence of R_LARCH_ALIGN in the input files.

For Context
LoongArch
A RISC-ISA (Instruction Set Architecture) developed in China.
ld -r
A linker option that performs a partial link, combining multiple object files into a single relocatable object file.
R_LARCH_ALIGN
A LoongArch-specific relocation type that indicates byte alignment.
-mno-relax
A compiler flag that disables instruction relaxation, which can affect code size and performance but might be required by certain linkers or environments.
Filed Under: linkerloongarchrelocationkernelbinutils