[llvm] [PowerPC][XCOFF] Handle non-zero addend in relocation to external toc-data symbol (PR #94444)

Kai Luo via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 5 01:59:44 PDT 2024


https://github.com/bzEq created https://github.com/llvm/llvm-project/pull/94444

There are situations that the addend is not zero. We should fix it for IAS.

>From ce6255d13c87e0150262b4031149bdd98c2ed87e Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail at cn.ibm.com>
Date: Wed, 5 Jun 2024 09:04:50 +0000
Subject: [PATCH] Handle non-zero addend in relocation to external toc-data
 symbol

---
 llvm/lib/MC/XCOFFObjectWriter.cpp                     | 5 ++---
 llvm/test/CodeGen/PowerPC/tocdata-non-zero-addend.mir | 2 +-
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/MC/XCOFFObjectWriter.cpp b/llvm/lib/MC/XCOFFObjectWriter.cpp
index a7c3818d598b7..061f362dd5ec8 100644
--- a/llvm/lib/MC/XCOFFObjectWriter.cpp
+++ b/llvm/lib/MC/XCOFFObjectWriter.cpp
@@ -729,10 +729,9 @@ void XCOFFObjectWriter::recordRelocation(MCAssembler &Asm,
     // For non toc-data external symbols, R_TOC type relocation will relocate to
     // data symbols that have XCOFF::XTY_SD type csect. For toc-data external
     // symbols, R_TOC type relocation will relocate to data symbols that have
-    // XCOFF_ER type csect. For XCOFF_ER kind symbols, there will be no TOC
-    // entry for them, so the FixedValue should always be 0.
+    // XCOFF_ER type csect.
     if (SymASec->getCSectType() == XCOFF::XTY_ER) {
-      FixedValue = 0;
+      FixedValue = Target.getConstant();
     } else {
       // The FixedValue should be the TOC entry offset from the TOC-base plus
       // any constant offset value.
diff --git a/llvm/test/CodeGen/PowerPC/tocdata-non-zero-addend.mir b/llvm/test/CodeGen/PowerPC/tocdata-non-zero-addend.mir
index eff10d24a62f3..b49615ce67c43 100644
--- a/llvm/test/CodeGen/PowerPC/tocdata-non-zero-addend.mir
+++ b/llvm/test/CodeGen/PowerPC/tocdata-non-zero-addend.mir
@@ -4,7 +4,7 @@
 # CHECK: lbz 3, 2(2)
 # CHECK-NEXT: R_TOC        x
 # CHECK-LABEL: .read_y
-# CHECK: lbz 3, 0(2)
+# CHECK: lbz 3, 1(2)
 # CHECK-NEXT: R_TOC        y
 
 --- |



More information about the llvm-commits mailing list