[RFC PATCH] LoongArch: Adjust addends for relaxed section-symbol relocations

Project / Subsystem

binutils / loongarch

Date

2026-09-23

Proposer

mengqinggang <mengqinggang@loongson.cn>

Source type

public_inbox

Consensus

Proposed

Sentiment

—/10

Technical tradeoffs

  • • Introduces a new function and logic to handle a specific relaxation edge case.
  • • Ensures correct relocation behavior for LoongArch targets when using `ld -r`.

All attributes

project
binutils
subsystem
loongarch
patch_id
—
discussion_id
20260923095431.2702807-1-mengqinggang@loongson.cn
source_type
public_inbox
title
[RFC PATCH] LoongArch: Adjust addends for relaxed section-symbol relocations
headline
LoongArch: Adjust addends for relaxed section-symbol relocations
tldr
Fixes incorrect relocation targets after code relaxation on LoongArch by adjusting addends.
proposer
mengqinggang <mengqinggang@loongson.cn>
consensus
Proposed
outcome
proposed
sentiment_score
—
technical_tradeoffs
  • • Introduces a new function and logic to handle a specific relaxation edge case.
  • • Ensures correct relocation behavior for LoongArch targets when using `ld -r`.
series_id
—
series_role
standalone
series_parts
[]
tags
  • • linker
  • • relocation
  • • relaxation
  • • loongarch
bugzilla_url
—
date
2026-09-23T00:00:00.000Z

[RFC PATCH] LoongArch: Adjust addends for relaxed section-symbol relocations

This patch introduces a fix for incorrect relocation targets on LoongArch when using ld -r with relaxed section-symbol relocations. Previously, the ELF linker would fold the section offset into the relocation addend, but LoongArch’s relaxation process did not update these addends, leading to incorrect targets after code shrinking. The fix adds a new function loongarch_relax_adjust_reloc_addends to correct these addends based on deleted instructions during relaxation, specifically for sections with local STT_SECTION relocations and non-zero addends.