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
This is the second version (v2) of a fix for LoongArch's ld -r behavior. The linker previously introduced unnecessary .align sections, breaking kernel modules on Debian sid due to R_LARCH_ALIGN presence. The fix now conditionally inserts the .align section only if input files contain R_LARCH_ALIGN or R_LARCH_RELAX, tracked by a new reloc_may_remove_bytes flag in the hash table.
- ld -r
- The
ldcommand with the-roption 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_ALIGNandR_LARCH_RELAXfor 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.