binutils Newspaper
NOVEMBER 30, 2026
Date
/
Architectures
Components
Topics
News & Policy
Other
binutils/ld

LoongArch GOT allocation fixed for TLS PCREL20 relocations.

Binutils linker now correctly handles GOT allocation for LoongArch TLS PCREL20 relocations, fixing link-time crashes.

The LoongArch linker now correctly records GOT references for TLS PCREL20 relocations, preventing link-time crashes. Previously, unallocated GOT entries for these relocation types (R_LARCH_TLS_{LD,GD,DESC}_PCREL20_S2) could cause the linker to fail. This fix ensures proper handling of Thread Local Storage (TLS) access through the Global Offset Table (GOT) for these specific relocation types.

In Details

This commit addresses an issue in loongarch_elf_check_relocs where certain TLS PCREL20 relocation types (R_LARCH_TLS_LD_PCREL20_S2, R_LARCH_TLS_GD_PCREL20_S2, R_LARCH_TLS_DESC_PCREL20_S2) were not being recorded for GOT allocation. Failing to record these references means that the linker might not allocate the necessary GOT entries, leading to a crash during the final relocation pass when these entries are expected but not present. The fix ensures loongarch_elf_record_tls_and_got_reference is called for these types.

For Context
GOT
Global Offset Table. A table used by dynamically linked executables and shared libraries to store the addresses of external symbols, allowing for position-independent code.
TLS
Thread Local Storage. A mechanism that provides variables with a scope limited to a single thread. Each thread gets its own copy of the variable.
PCREL20
A type of relocation that calculates an offset relative to the Program Counter (PC) using a 20-bit value.
R_LARCH_TLS_LD_PCREL20_S2
A LoongArch-specific relocation type for accessing Thread Local Storage variables using a PC-relative address with a 20-bit offset, potentially related to Local Dynamic (LD) TLS models.
Relocation
The process of updating symbolic references in object code to absolute addresses or offsets, typically performed by the linker.
Filed Under: binutilsloongarchlinkertls