[llvm] 1dae4dd - [JITLink][PowerPC] Fix incorrect assertion of addend for R_PPC64_REL24

Kai Luo via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 13 19:40:49 PDT 2023


Author: Kai Luo
Date: 2023-09-14T02:40:45Z
New Revision: 1dae4dd0d80fd453d60564b60a70f1b3814ef5a5

URL: https://github.com/llvm/llvm-project/commit/1dae4dd0d80fd453d60564b60a70f1b3814ef5a5
DIFF: https://github.com/llvm/llvm-project/commit/1dae4dd0d80fd453d60564b60a70f1b3814ef5a5.diff

LOG: [JITLink][PowerPC] Fix incorrect assertion of addend for R_PPC64_REL24

There is case that R_PPC64_REL24 with non-zero addend. The assertion is incorrectly triggered in such situation.

Reviewed By: lhames

Differential Revision: https://reviews.llvm.org/D158708

Added: 
    

Modified: 
    llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
    llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
    llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-rel24-non-zero-addend.test

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h b/llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
index 42ab9ddd8765b4e..88af15d61e714e1 100644
--- a/llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
+++ b/llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
@@ -204,9 +204,11 @@ class PLTTableManager : public TableManager<PLTTableManager<Endianness>> {
       if (isExternal) {
         E.setKind(ppc64::CallBranchDeltaRestoreTOC);
         this->StubKind = LongBranchSaveR2;
+        // FIXME: We assume the addend to the external target is zero. It's
+        // quite unusual that the addend of an external target to be non-zero as
+        // if we have known the layout of the external object.
         E.setTarget(this->getEntryForTarget(G, E.getTarget()));
-        // We previously set branching to local entry. Now reverse that
-        // operation.
+        // Addend to the stub is zero.
         E.setAddend(0);
       } else
         // TODO: There are cases a local function call need a call stub.

diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp b/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
index ba66439f04086e4..5ce7a5bda840239 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
+++ b/llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
@@ -346,9 +346,13 @@ class ELFLinkGraphBuilder_ppc64
       break;
     case ELF::R_PPC64_REL24:
       Kind = ppc64::RequestCall;
-      assert(Addend == 0 && "Addend is expected to be 0 for a function call");
-      // We assume branching to local entry, will reverse the addend if not.
-      Addend = ELF::decodePPC64LocalEntryOffset((*ObjSymbol)->st_other);
+      // Determining a target is external or not is deferred in PostPrunePass.
+      // We assume branching to local entry by default, since in PostPrunePass,
+      // we don't have any context to determine LocalEntryOffset. If it finally
+      // turns out to be an external call, we'll have a stub for the external
+      // target, the target of this edge will be the stub and its addend will be
+      // set 0.
+      Addend += ELF::decodePPC64LocalEntryOffset((*ObjSymbol)->st_other);
       break;
     case ELF::R_PPC64_REL64:
       Kind = ppc64::Delta64;

diff  --git a/llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-rel24-non-zero-addend.test b/llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-rel24-non-zero-addend.test
index 6ee7ba407f935ed..eca0fc9097af54b 100644
--- a/llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-rel24-non-zero-addend.test
+++ b/llvm/test/ExecutionEngine/JITLink/ppc64/ppc64-rel24-non-zero-addend.test
@@ -1,7 +1,4 @@
-# REQUIRES: asserts
 # RUN: yaml2obj %S/Inputs/rel24-non-zero-addend.yaml -o %t.o
-# RUN: not --crash llvm-jitlink -noexec %t.o 2>&1 | FileCheck %s
-# CHECK: Addend == 0 && "Addend is expected to be 0 for a function call"
-#
+# RUN: llvm-jitlink -noexec %t.o 2>&1
 # The object is generated from llvm/test/ExecutionEngine/MCJIT/test-global-ctors.ll,
 # containing an R_PPC64_REL24 whose addend is not zero.


        


More information about the llvm-commits mailing list