binutils Newspaper
OCTOBER 6, 2026
loongarch — Proposed

LoongArch: Emit relocations for .long 0x2eef - symbol

Enables correct relocation generation for symbolic subtraction expressions.

This patch enables the LoongArch assembler to correctly emit relocations for expressions like ‘.long 0x2eef - symbol’. Previously, the assembler failed to generate these relocations because fx_addsy was incorrectly set to NULL. The fix involves setting fx_addsy to abs_section_sym in md_apply_fix to ensure proper relocation handling.

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

    Proposes to set `fx_addsy` to `abs_section_sym` in `md_apply_fix` to enable relocation generation for expressions like `.long 0x2eef - symbol`.

In Details

This patch addresses a limitation in the LoongArch assembler's relocation handling. Specifically, it corrects the md_apply_fix function to properly set the fx_addsy field when processing symbolic subtraction expressions (e.g., constant - symbol). The absence of this symbolic addend prevented the generation of necessary relocations, such as R_LARCH_ADD64 or R_LARCH_SUB64, which are crucial for correctly resolving addresses at link time. The fix ensures that these expressions are now handled by setting fx_addsy to point to the absolute section symbol.

For Context
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.
symbol
A named identifier in a program that refers to a memory location, variable, or function. The linker uses symbols to resolve references between different parts of the code.
fx_addsy
A field within the fixup structure that likely represents the addend symbol used in a relocation calculation. Setting it correctly is crucial for generating the appropriate relocation type.
abs_section_sym
A symbol representing the absolute address of a section. Used here to provide a base for relocation calculations when a symbolic subtraction involves a constant and a symbol.
Filed Under: loongarchassemblerrelocationssymbolic expressions