[lld] [RISCV][lld] Guarding lld relaxation for RISCV (PR #130265)

Sharjeel Khan via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 7 02:05:54 PST 2025


https://github.com/Sharjeel-Khan updated https://github.com/llvm/llvm-project/pull/130265

>From 1d6718b951bf3cbe6d1a24accfb127fd263dc47f Mon Sep 17 00:00:00 2001
From: Sharjeel Khan <sharjeelkhan at google.com>
Date: Fri, 7 Mar 2025 08:38:38 +0000
Subject: [PATCH] [RISCV][lld] Guarding lld relaxation for RISCV

Based on https://github.com/llvm/llvm-project/issues/123248#issuecomment-2675911618,
the relaxation algorithm assumes relaxing a call will shift the later
function forward by the same bytes we removed. As some sections are
between call and its call target are 32-byte aligned, the call and call
target sections might not be the same distance apart. We guard band the
relaxation so it stops the relaxation loop and take the last state.
---
 lld/ELF/Arch/RISCV.cpp | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp
index 4d8989a21b501..7e864574ccea9 100644
--- a/lld/ELF/Arch/RISCV.cpp
+++ b/lld/ELF/Arch/RISCV.cpp
@@ -902,6 +902,9 @@ bool RISCV::relaxOnce(int pass) const {
   if (ctx.arg.relocatable)
     return false;
 
+  if (pass == 29)
+    return false;
+
   if (pass == 0)
     initSymbolAnchors(ctx);
 



More information about the llvm-commits mailing list