binutils Newspaper
NOVEMBER 30, 2026
loongarch — Proposed

LoongArch: Exclude JIRL from conditional branch relaxation

A patch to prevent the LoongArch assembler from incorrectly altering JIRL instructions during conditional branch relaxation.

This patch for the LoongArch architecture in Binutils addresses an issue where the assembler, GAS, incorrectly modifies JIRL opcodes by appending a B instruction when the immediate value is out of range. This alteration changes the instruction’s semantics. The patch excludes JIRL from conditional branch relaxation to prevent this incorrect behavior.

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

    Submits a patch to prevent the LoongArch assembler from inverting JIRL opcodes and appending a B instruction when the immediate is out of range.

    “JIRL can use an R_LARCH_B16 relocation, therefore cause GAS to invert the JIRL opcode and append a B instruction when its immediate is out of range, changing the instruction's semantics.”

In Details

This patch targets the LoongArch backend in GNU Assembler (GAS), part of the Binutils project. It addresses an issue with branch relaxation, where the assembler adjusts branch instructions for optimal size. The problem occurs with JIRL instructions using R_LARCH_B16 relocations; if the immediate value is out of range for a B instruction (which GAS might substitute), GAS incorrectly inverts the JIRL opcode and appends a B, altering the instruction's meaning. The fix excludes JIRL from this relaxation process.

For Context
JIRL
Jump If Register Less, a LoongArch instruction. In this context, it refers to a specific jump instruction that can use a 16-bit relocation.
Conditional branch relaxation
An assembler optimization where branch instructions are adjusted to use shorter or longer forms to fit their target distance, optimizing code size or reachability.
GAS
GNU Assembler, the default assembler for the GCC toolchain.
R_LARCH_B16
A LoongArch-specific relocation type for 16-bit branches.
Opcode
The part of a machine instruction that specifies the operation to be performed.
Filed Under: binutilsgasLoongArchassemblyrelaxation