LoongArch: Optimize alignment before linker-relaxable frags
LoongArch GAS optimizes alignment of early fragments to avoid R_LARCH_ALIGN relocations.
LoongArch GAS now converts initial alignment fragments into ordinary align-code fragments, allowing GAS to compute exact NOP padding. This avoids unnecessary R_LARCH_ALIGN relocations for these early alignments. The optimization is skipped if any .reloc *, R_LARCH_RELAX is present, as the exact linker-relaxable fragment cannot be determined prior to size_seg. The sec_flg1 flag is refreshed after this optimization.
In Details
This commit modifies GAS for LoongArch to optimize alignment fragments that appear before the first linker-relaxable fragment. It converts rs_machine_dependent alignment frags to rs_align_code frags, enabling GAS to emit precise NOP padding and avoid R_LARCH_ALIGN relocations. The optimization is guarded by checks for R_LARCH_RELAX relocations and ensures correct handling of linker relaxation.
- linker-relaxable frag
- A fragment of code or data within an object file that the linker can modify or adjust its position after the initial linking pass, typically to optimize alignment or instruction encoding.
- R_LARCH_ALIGN
- A relocation type specific to LoongArch that indicates an alignment adjustment is needed at a particular address.
- NOP padding
- The insertion of No-Operation (NOP) instructions to fill space, often used for alignment purposes or to ensure predictable instruction timing.
- size_seg
- A phase in the linker or assembler process where the final sizes and addresses of code and data segments are determined.