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

LoongArch: Emit alignment relocations only after relaxed instructions

Aligns LoongArch GAS behavior for alignment relocations with relaxed instructions, preventing incorrect emission.

This commit refines how LoongArch’s GAS handles alignment relocations by ensuring they are emitted only after relaxed instructions have been processed. Previously, alignment fragments could be created without considering whether the section contained relaxed instructions, potentially leading to incorrect relocation emission. This change aligns the GAS behavior with LLVM’s approach (referenced in the commit) and improves the accuracy of generated code.

In Details

The change in gas/config/tc-loongarch.c modifies the loongarch_frag_align_code function. It introduces a check if (!now_seg->sec_flg1), which determines if the current section has been marked as containing relaxed instructions. Alignment fragments (and thus their associated relocations) are now only generated if sec_flg1 is set, meaning relaxed instructions are present. This prevents premature or incorrect emission of alignment relocations in contexts where they might not be strictly necessary or could interfere with relaxation processing, mirroring a fix in LLVM.

For Context
Alignment Relocations
Relocations generated by the assembler to ensure that code or data is properly aligned in memory according to the target architecture's requirements. These can sometimes interact with instruction relaxation.
Relaxed Instructions
Instructions whose final machine code encoding (e.g., branch offsets, immediates) is not known at assembly time and may change during linking. The linker 'relaxes' these instructions by patching them to their final form.
GAS (GNU Assembler)
The assembler component of the GNU toolchain, responsible for converting assembly language source code into machine code object files.
sec_flg1
A flag within the BFD section structure that likely indicates whether the section contains linker-relaxable instructions. This commit uses it to gate the emission of alignment relocations.
Filed Under: loongarchgasrelocationsassembly