binutils Newspaper
JULY 29, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
loongarch

LoongArch: Simplify TLS DTPREL relocation processing

Improves LoongArch TLS DTPREL32/64 relocation handling by simplifying logic and setting partial_inplace to false for RELA relocations.

This commit simplifies the processing of R_LARCH_TLS_DTPREL32/64 relocations on LoongArch by returning the offset to the TLS block for the symbol. It also corrects the relocation type by setting partial_inplace to false, acknowledging that LoongArch uses RELA relocations. This change contributes to more accurate and efficient handling of Thread-Local Storage (TLS) in the LoongArch toolchain.

In Details

The change modifies elfnn-loongarch.c to streamline the handling of R_LARCH_TLS_DTPREL32 and R_LARCH_TLS_DTPREL64 relocations when resolved_dynly is true. Instead of complex logic involving outrel and unresolved_reloc, it now directly returns the offset to the TLS block. Crucially, it sets partial_inplace to false for these relocations, reflecting LoongArch's use of RELA rather than REL relocations for TLS descriptor access, aligning the BFD backend with the architecture's ABI.

For Context
R_LARCH_TLS_DTPREL32/64
LoongArch-specific relocation types used for accessing Thread-Local Storage (TLS) variables relative to the thread descriptor area. They specify whether the offset is 32-bit or 64-bit.
TLS (Thread-Local Storage)
A mechanism that allows each thread in a multi-threaded program to have its own private copy of a variable. Toolchains generate specific relocations to manage access to these per-thread variables.
RELA relocations
A type of ELF relocation that includes an explicit addend. This is in contrast to REL relocations, which do not have an explicit addend and are often used for simpler address calculations.
partial_inplace
A flag within the BFD relocation handling that indicates whether a relocation can be resolved in-place within the output section. Setting it to false means the relocation requires a separate relocation entry in the output.
Filed Under: loongarchtlsrelocationself