LoongArch: Mark .reloc *, R_LARCH_RELAX target frags correctly
LoongArch GAS now correctly marks fragments with R_LARCH_RELAX for linker relaxation.
LoongArch GAS now properly identifies and marks fragments containing .reloc *, R_LARCH_RELAX, indicating they are linker-relaxable. This prevents GAS from incorrectly treating distances between symbols within these frags as fixed, which could lead to inappropriate PC-relative relocations or DWARF line table issues. The change ensures that same-frag symbol subtraction uses ADD/SUB relocs and forces DW_LNS_fixed_advance_pc in DWARF line tables when R_LARCH_RELAX is present.
In Details
This commit enhances LoongArch GAS to correctly handle fragments marked with .reloc *, R_LARCH_RELAX. Previously, GAS did not track this linker-relaxable state in the containing frag and section, leading to incorrect assumptions about fixed distances and the generation of invalid relocations (e.g., converting symbol subtraction to PC-relative) or DWARF line table entries. The fix introduces marking these frags as linker-relaxable via tc_frob_file_before_fix after size_seg and adjusts relocation and DWARF emission accordingly.
- .reloc *, R_LARCH_RELAX
- An assembler directive and relocation type for LoongArch that marks a specific code or data fragment as subject to linker relaxation. The linker may adjust the fragment's size or position.
- linker relaxation
- A linker optimization technique where the linker can adjust the size and position of certain code or data segments after an initial linking pass to improve code density or enable specific instruction encodings.
- PC-relative relocation
- A type of relocation where an address is specified relative to the current Program Counter (PC), commonly used for position-independent code.
- DWARF line tables
- A debugging data format that maps executable code addresses back to source code lines, enabling source-level debugging.
- DW_LNS_fixed_advance_pc
- A specific DWARF line table instruction that advances the program counter by a fixed amount, used to represent code sequencing in the debugger.