binutils Newspaper
NOVEMBER 30, 2026
loongarch — Proposed

LoongArch: Exclude JIRL from conditional branch relaxation (v2)

Version 2 of a patch that prevents the LoongArch assembler from incorrectly altering JIRL instructions during conditional branch relaxation.

This is the second version of a patch for the LoongArch architecture in Binutils. It 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 modification changes the instruction’s semantics. The patch excludes JIRL from conditional branch relaxation to prevent this behavior.

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

    Submits version 2 of 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 specifically addresses an issue with branch relaxation, a process where the assembler adjusts branch instructions to use shorter immediate offsets when possible. The problem arises because JIRL instructions, when using the R_LARCH_B16 relocation, can be misinterpreted by GAS's relaxation logic. If the immediate value for JIRL is out of range for a B instruction (which GAS might try to substitute), GAS incorrectly inverts the JIRL opcode and appends a B, semantically altering the instruction…

For Context
JIRL
Jump If Register Less, a LoongArch instruction. In this context, it appears to be a specific variant or usage of a jump instruction.
Conditional branch relaxation
A compiler or assembler optimization where short, fixed-length branch instructions are rewritten to use longer, variable-length forms if the target is too far away. This ensures all branches can reach their targets.
GAS
GNU Assembler, the default assembler used by the GCC toolchain.
R_LARCH_B16
A relocation type specific to the LoongArch architecture, indicating a 16-bit branch relocation.
Opcode
The part of a machine language instruction that specifies the operation to be performed.
Filed Under: binutilsgasLoongArchassemblyoptimization