LoongArch: Optimize alignment before first relaxable frag
Optimizes alignment handling in LoongArch by converting early alignment frags to non-relaxable ones.
This patch optimizes alignment handling for LoongArch by converting alignment fragments that appear before the first linker-relaxable instruction into ordinary, non-linker-relaxable alignment fragments. This allows the assembler (GAS) to compute the exact NOP padding, thus avoiding the emission of R_LARCH_ALIGN relocations. Alignments that appear later remain linker-relaxable. The optimization is skipped if any R_LARCH_RELAX relocations are present, as the exact relaxable fragment cannot be determined before final addresses are known. The patch also refreshes section flags after optimization.
In Details
This patch modifies the LoongArch GAS backend to optimize alignment handling. Specifically, it targets rs_machine_dependent alignment frags that precede any linker-relaxable frags. These early alignment frags are converted to rs_align_code frags, allowing GAS to calculate precise NOP padding at assembly time. This eliminates the need for R_LARCH_ALIGN relocations for these initial alignments, as the final layout is fixed. If R_LARCH_RELAX relocations are present, this optimization is disabled because the true relaxable state isn't known until after size_seg. Section flags are refres…
- linker-relaxable
- A code fragment or instruction whose size or position can be adjusted by the linker during the relaxation phase to optimize code density or performance.
- rs_machine_dependent
- Represents a machine-dependent fragment type within the GAS assembler, often related to specific instruction or alignment semantics for a target architecture.
- rs_align_code
- An assembler fragment type representing an alignment directive, which ensures that subsequent code or data is placed at a properly aligned address.
- R_LARCH_ALIGN
- A LoongArch relocation type specifically used to indicate that an alignment adjustment is required.
- NOP padding
- Insertion of No-Operation (NOP) instructions to fill space, often used for alignment purposes or to provide space for later patching.