LoongArch: Emit fewer relocations for label subtraction
Optimizes LoongArch instruction emission by not generating relocations for label subtraction when no relaxed instructions are present between addsy and subsy.
This patch for the LoongArch binutils component optimizes relocation emission for label subtraction. It introduces flags to mark fragments and sections with relaxed instructions, preventing the generation of relocations when addsy and subsy occur within the same fragment and no relaxed instructions are interspersed.
- proposer
Proposes to reduce relocations for LoongArch label subtraction by marking relaxed instructions and avoiding relocation emission if addsy and subsy are in the same frag.
“Mark the frag and section to indicate if they have a relaxed instruction. For label subtraction, if there are no relaxed instructions between addsy and subsy, do not emit relocations.”
In Details
This LoongArch-specific patch for binutils optimizes linker relaxation by reducing the number of relocations generated for label subtraction. It introduces logic to track whether a fragment or section contains 'relaxed' instructions. If the sequence 'addsy' and 'subsy' (likely related to calculating a symbol's address or offset) occurs within the same fragment without intervening relaxed instructions, the associated relocations are omitted. This optimization aims to improve code density and potentially linker performance.
- LoongArch
- A RISC-V-based instruction set architecture developed by Loongson Technology.
- linker relaxation
- A process where the linker adjusts addresses and offsets of code and data after initial assembly, often to optimize for space or speed, especially in position-independent code.
- relocations
- Information in an object file that describes how to modify addresses and references when the code is linked or loaded into memory.
- label subtraction
- An assembly operation where the difference between two labels (addresses) is calculated, typically used for offset calculations.
- addsy/subsy
- Assembly pseudo-instructions or directives used in LoongArch to define symbols or perform address calculations, likely related to the 'add symbol' and 'subtract symbol' operations.
- frag
- A 'fragment', a basic unit of code or data within an assembler's intermediate representation, which eventually forms part of an object file section.