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

LoongArch GAS fixes TLS LE relaxation with -mno-relax

Corrects LoongArch assembler to only apply relaxation for TLS LE sequences when the '-mno-relax' option is not used.

This commit fixes a bug in the LoongArch assembler (GAS) concerning Thread-Local Storage (TLS) LE (Local Exec) relaxation. When the ‘-mno-relax’ option was used, the assembler incorrectly emitted relaxation markers for parts of the TLS LE sequence. This could lead the linker to optimize incorrectly by removing instructions, resulting in a wrong TLS address. The fix ensures that the relaxation marker for the le_add_r instruction is only emitted when linker relaxation is actually enabled.

In Details

This commit modifies the LoongArch backend for GAS (gas/config/tc-loongarch.c) to fix a bug related to TLS LE relaxation when -mno-relax is active. The original code unconditionally emitted a BFD_RELOC_LARCH_RELAX relocation for the le_add_r instruction, even when relaxation was disabled by the user. This led to incorrect linker relaxation where the add.d instruction could be removed, breaking the TLS LE sequence. The fix now guards the emission of this relaxation marker with if (LARCH_opts.relax), ensuring it's only applied when linker relaxation is actually enabled, resolving is…

For Context
GAS
GNU Assembler. The assembler used by the GCC toolchain to convert assembly code into object files.
TLS LE
Thread-Local Storage, Local Exec mode. A mechanism for accessing data that is unique to each thread. 'Local Exec' refers to the access mode for TLS variables that are local to the executable.
Relaxation
A linker optimization process where it adjusts the addresses and sizes of code and data sections to optimize for space or performance. This can involve replacing placeholder instructions with more efficient ones or removing redundant instructions.
-mno-relax
An assembler option that disables linker relaxation for the target architecture.
LoongArch
A family of RISC-based instruction set architectures developed in China.
TP
Thread Pointer. A register that holds the base address of the current thread's control block, often used to access thread-local storage.
Filed Under: LoongArchassemblerTLSrelaxation