LoongArch: Reduce relocations for label subtraction with no relaxed instructions
Optimizes LoongArch assembly by avoiding unnecessary relocations for label subtractions when no relaxed instructions are involved.
This change introduces optimizations for LoongArch assembly by intelligently managing relocations related to label subtraction. It marks fragments and sections to indicate the presence of relaxed instructions. Consequently, if no relaxed instructions exist between addsy and subsy operations, the assembler now avoids emitting unnecessary relocations, leading to smaller object files and potentially faster linking times.
In Details
The commit updates gas/config/tc-loongarch.c and related files to add flags (linker_relax in loongarch_cl_insn, and a flag for sections) that track whether a fragment or section contains linker-relaxable instructions. The core change is in how addsy and subsy handle relocations: if addsy and subsy are within the same fragment, and that fragment does not contain any relaxed instructions, a relocation is no longer emitted. This reduces the number of relocations generated for simple label arithmetic when relaxation is not a factor.
- Label Subtraction
- An operation in assembly language where the addresses of two labels are subtracted from each other. This is often used to calculate the size or distance between two points in the code or data.
- Relocations
- Information in an object file that tells the linker how to modify certain instructions or data references to point to the correct final memory addresses after linking.
- 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.
- addsy
- An assembly directive or pseudo-instruction used in some assemblers (like GAS for LoongArch) to indicate the start of a section involved in symbol arithmetic, potentially related to relocations.
- subsy
- Similar to 'addsy', this directive likely marks the end or a component of symbol arithmetic, working in conjunction with 'addsy' to define the operands for a relocation calculation.