Skip to content

Commit

Permalink
[JITLink][PowerPC] Fix incorrect assertion of addend for R_PPC64_REL24
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bzEq committed Sep 14, 2023
1 parent 347b3f1 commit 1dae4dd
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 9 deletions.
6 changes: 4 additions & 2 deletions llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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.

0 comments on commit 1dae4dd

Please sign in to comment.