LoongArch: only insert align section for ld -r if an input has R_LARCH_ALIGN or R_LARCH_RELAX
Fixes LoongArch linker behavior when using `ld -r` to avoid inserting align sections unnecessarily, preventing kernel module loading issues.
Xi Ruoyao proposes a fix to the LoongArch linker’s behavior with ld -r. A previous change inadvertently caused issues with Debian kernel modules because the linker was inserting align sections even when not explicitly required by R_LARCH_ALIGN or R_LARCH_RELAX relocations. This patch ensures the align section is only inserted when such relocations are present, resolving the kernel module loading problem and preventing unnecessary bloat from NOPs and align sections.
In Details
This patch addresses a regression in LoongArch's ld -r (relocatable linking) behavior. Specifically, it corrects the creation of an align section that was previously inserted unconditionally. The issue reported is that this unconditional insertion breaks kernel modules built with -mno-relax, as they expect no R_LARCH_ALIGN relocations. The fix is to condition the align section's creation on the presence of R_LARCH_ALIGN or R_LARCH_RELAX relocations in the input object files.
- 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.
- R_LARCH_RELAX
- A LoongArch-specific relocation type used for relaxation, potentially allowing for code or data removal.
- -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.