LoongArch: Use local anchors for relocatable section symbols
RFC patch to use local anchors for relocatable section symbols in LoongArch to handle linker's folding of output_offset into RELA addends.
This RFC patch addresses an issue in LoongArch where the linker, when performing a partial link (ld -r), folds the output section offset into the RELA addend for STT_SECTION symbols. LoongArch’s relaxation mechanism does not support optimizing symbols into a section symbol plus offset form, necessitating the use of local STT_NOTYPE anchors. These anchors will store the input section’s output offset, allowing subsequent relaxation or section movement to update the anchor without modifying relocation addends.
In Details
This RFC patch for binutils targets the LoongArch architecture, specifically how the linker handles relocatable section symbols with ld -r. The problem arises because elf_link_input_bfd() folds sec->output_offset into the RELA addend when an input STT_SECTION symbol is redirected to an output section symbol. LoongArch's relaxation process, which optimizes code by potentially adjusting instruction encodings based on symbol positions, does not support the 'section symbol + offset' form. The proposed solution is to use local STT_NOTYPE anchors per referenced input section symbol. The `…
- ld -r
- An option for the GNU linker (ld) that performs a partial link, similar to an incremental link, producing an intermediate object file.
- STT_SECTION
- A symbol table entry type indicating a section symbol.
- RELA
- A type of relocation entry that includes an addend.
- LoongArch relaxation
- A feature in the LoongArch architecture that allows for code optimization, potentially by adjusting instruction encoding based on symbol positions.
- local anchors
- A mechanism to create stable references within sections that can be updated during linking or relaxation without altering relocation addends.
- st_value
- The value associated with a symbol table entry, often representing an offset or address.