binutils Newspaper
JULY 29, 2026
loongarch Proposed

LoongArch: Fix the size of TLS descriptor relocations

Corrects the size of R_LARCH_TLS_DESC64_* relocations from 8 to 4 bytes in binutils.

This patch corrects the size definition for R_LARCH_TLS_DESC64_* relocations in the LoongArch binutils backend. Previously, their size was incorrectly set to 8 bytes; this change sets it to the correct value of 4 bytes, ensuring proper handling of Thread-Local Storage descriptor relocations.

In the Thread 1 participant
  1. mengqinggang <mengqinggang@loongson.cn> proposer

    Submits a patch to fix the size of LoongArch TLS descriptor relocations from 8 to 4 bytes.

    “Change the size of R_LARCH_TLS_DESC64_* from 8 to 4. ---”

In Details

This patch addresses an incorrect size definition for LoongArch's Thread-Local Storage (TLS) descriptor relocations (R_LARCH_TLS_DESC64_PC_LO20, R_LARCH_TLS_DESC64_PC_HI12, R_LARCH_TLS_DESC64_LO20, R_LARCH_TLS_DESC64_HI12) within the binutils elfxx-loongarch.c file. The size field in the loongarch_howto_table was set to 8, but it should be 4, as these relocations deal with 32-bit offsets within a 64-bit TLS descriptor. Rectifying this ensures the assembler and linker correctly interpret and process TLS-related references.

For Context
LoongArch
A RISC-V-based instruction set architecture developed by Loongson Technology.
TLS
Thread-Local Storage, a mechanism that allows variables to have distinct values for each thread of execution.
relocations
Information in an object file that describes how to modify addresses and references when the code is linked or loaded into memory.
binutils
A collection of programming tools for creating and managing executable programs, including the GNU Assembler (gas) and the GNU Binary File Descriptor library (BFD).
R_LARCH_TLS_DESC64_*
Specific relocation types defined for LoongArch that handle Thread-Local Storage descriptor access, likely involving 64-bit addressing or data structures.
elfxx-loongarch.c
The C source file in binutils responsible for handling ELF object files for the LoongArch architecture.
Filed Under: loongarchbinutilslinkerrelocationtls