TUESDAY, JULY 7, 2026
loongarch — Proposed
LoongArch: Fix the size of tls desc relocations
Adjusts relocation sizes for LoongArch TLS descriptors from 8 to 4 bytes.
This patch corrects the size of R_LARCH_TLS_DESC64_* relocations for the LoongArch architecture from 8 bytes to 4 bytes. This change is part of a larger series aimed at optimizing linker relaxation.
In Details
This patch modifies the BFD (as in Binary File Descriptor) library's ELF definitions for LoongArch. Specifically, it changes the size field associated with TLS descriptor relocation types (R_LARCH_TLS_DESC64_{PC_LO20, PC_HI12, LO20, HI12}) from 8 to 4. This is a common adjustment when the actual number of bits encoded in the relocation is smaller than initially assumed or a more compact representation is deemed correct.
For Context
- TLS
- Thread-Local Storage. A mechanism that allows variables to have unique instances per thread, managed by the runtime library.
- relocation
- Information in an object file that describes how to modify code or data after linking, typically to resolve symbol addresses or other layout-dependent values. In ELF, these are represented by types like R_LARCH_TLS_DESC64_*.
- linker relaxation
- A linker optimization where it analyzes instruction sequences and adjusts addresses or instruction forms to reduce code size or improve performance, often involving the generation and resolution of relocations.
- BFD
- Binary File Descriptor library. A GNU project library that provides a common interface to various object file formats, including ELF.
- ELF
- Executable and Linkable Format. A standard file format for object files, executables, and shared libraries on many Unix-like systems.
- R_LARCH_TLS_DESC64_*
- Specific relocation types for the LoongArch architecture related to Thread-Local Storage descriptors, indicating how to calculate an offset or address for TLS data.