binutils Newspaper
OCTOBER 6, 2026
loongarch — Proposed

LoongArch: Optimize ADD/SUB and PC-relative relocations handling

Series optimizes LoongArch relocation handling for ADD/SUB and PC-relative types.

This patch series introduces several improvements to LoongArch relocation handling in the GNU Assembler. It adds support for emitting relocations for symbolic subtraction expressions, optimizes the TC_FORCE_RELOCATION_SUB_LOCAL mechanism to reduce fixup overhead, and corrects the md_pcrel_from function for accurate PC-relative offset calculations. These changes collectively aim to improve the efficiency and correctness of code generation for LoongArch.

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

    Submits a three-part patch series to optimize ADD/SUB and PC-relative relocation handling on LoongArch by enhancing symbolic expression support, reducing fixups, and correcting PC-relative base address calculation.

In Details

This cover letter introduces a three-part series for the LoongArch assembler (gas). Patch 1 enables R_LARCH_ADD/SUB relocations for expressions like constant - symbol by correctly setting fx_addsy. Patch 2 optimizes TC_FORCE_RELOCATION_SUB_LOCAL to prefer PC-relative relocations over ADD/SUB relocations when linker relaxation is not fully applicable, reducing fixup counts. Patch 3 fixes md_pcrel_from to return the correct instruction start address for PC-relative calculations, which was previously hardcoded to 0. These changes collectively improve relocation efficiency and accurac…

For Context
LoongArch
A RISC ISA developed by China's Loongson Technology.
relocation
Information embedded in an object file that describes how to modify symbolic addresses and constants when linking. It tells the linker which parts of the code or data need to be adjusted based on the final memory layout.
assembler
A program that translates assembly language into machine code. It also generates relocation information for the linker.
ADD/SUB relocations
Specific relocation types used by the assembler/linker to represent the result of an addition or subtraction between symbols or constants.
PC-relative
A type of address calculation where the offset is relative to the current program counter (PC). This is common for position-independent code.
linker relaxation
A linker optimization that allows it to substitute shorter, faster instructions for longer ones if the target address is known to be close enough. This can involve changing instruction opcodes and relocation types.
Filed Under: loongarchassemblerrelocationsoptimizationcode generation