GCC Newspaper
OCTOBER 6, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
loongarch

LoongArch: Remove addend for .dtprelword and .dtpreldword

LoongArch TLS access no longer needs addend offset due to TP register pointing to TLS block start.

This commit removes an unnecessary addend offset from .dtprelword and .dtpreldword directives on LoongArch. The architecture’s thread pointer (TP) register directly points to the beginning of the Thread-Local Storage (TLS) block, eliminating the need for the previous 0x8000 offset. A new test case is introduced to verify this change.

In Details

The LoongArch loongarch_output_dwarf_dtprel function previously added a 0x8000 offset when emitting DWARF debugging information for thread-local storage (.dtprelword and .dtpreldword). This commit removes that offset because the LoongArch TP register (r2) is defined to point to the start of the TLS block, making the offset redundant. A new test case, dtprel.c, is added to confirm correct DWARF output.

For Context
Thread-Local Storage (TLS)
A memory management technique that allows each thread in a multithreaded program to have its own distinct copy of a variable. This is managed through special sections in object files and specific instructions/registers for accessing thread-specific data efficiently.
.dtprelword and .dtpreldword
These are directives used in object files to define data for dynamic thread-local storage. They are precursors to the actual data definitions and help the dynamic linker resolve references to thread-local variables at runtime.
TP register
Thread Pointer register. This is a special register that holds the base address of the current thread's Thread-Local Storage (TLS) block. Accessing TLS variables typically involves an offset from this register.
Addend
A value added during the calculation of a symbol's final address, particularly in the context of relocations. In this case, the 0x8000 was an addend that was incorrectly applied.
Filed Under: loongarchtlsdwarfrelocation