LoongArch: Mark .reloc *, R_LARCH_RELAX as linker-relaxable
Ensures GAS correctly identifies fragments with R_LARCH_RELAX as linker-relaxable.
This patch corrects how the LoongArch assembler (GAS) handles .reloc *, R_LARCH_RELAX directives. Previously, GAS marked such fragments as linker-relaxable but did not record this state in the containing frag and section. This led to incorrect assumptions about fixed distances between symbols, resulting in the conversion of same-frag symbol subtraction to PC-relative relocations and the use of special DWARF line table opcodes, both invalid after linker relaxation. The fix involves recording the relaxable state and adjusting relocation decisions and DWARF line table generation accordingly.
In Details
This patch addresses an issue in the LoongArch GAS backend where .reloc *, R_LARCH_RELAX directives, which mark a fragment as linker-relaxable, were not properly propagated. The assembler would incorrectly treat distances within such fragments as fixed. This caused problems with same-frag symbol subtraction (incorrectly converted to PC-relative relocations) and DWARF line table generation (using invalid fixed advance opcodes). The patch introduces loongarch_md_finish to record the presence of these relaxable relocations and uses tc_frob_file_before_fix to mark the relevant frags and sec…
- .reloc *, R_LARCH_RELAX
- An assembler directive on LoongArch that marks a code fragment as 'linker-relaxable', meaning its final size or position can be adjusted by the linker.
- 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.
- PC-relative relocation
- A type of relocation where the target address is calculated relative to the current program counter.
- DWARF line tables
- A debugging information format used by DWARF that maps machine code addresses to source code lines, enabling debuggers to set breakpoints and step through code.
- DW_LNS_fixed_advance_pc
- A specific DWARF Line Number Statement (LNS) opcode indicating a fixed advance in the program counter, used for tracking source code locations.