Skip to content

Commit 1dae4dd

Browse files
author
Kai Luo
committed
[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
1 parent 347b3f1 commit 1dae4dd

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

llvm/include/llvm/ExecutionEngine/JITLink/ppc64.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,11 @@ class PLTTableManager : public TableManager<PLTTableManager<Endianness>> {
204204
if (isExternal) {
205205
E.setKind(ppc64::CallBranchDeltaRestoreTOC);
206206
this->StubKind = LongBranchSaveR2;
207+
// FIXME: We assume the addend to the external target is zero. It's
208+
// quite unusual that the addend of an external target to be non-zero as
209+
// if we have known the layout of the external object.
207210
E.setTarget(this->getEntryForTarget(G, E.getTarget()));
208-
// We previously set branching to local entry. Now reverse that
209-
// operation.
211+
// Addend to the stub is zero.
210212
E.setAddend(0);
211213
} else
212214
// TODO: There are cases a local function call need a call stub.

llvm/lib/ExecutionEngine/JITLink/ELF_ppc64.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -346,9 +346,13 @@ class ELFLinkGraphBuilder_ppc64
346346
break;
347347
case ELF::R_PPC64_REL24:
348348
Kind = ppc64::RequestCall;
349-
assert(Addend == 0 && "Addend is expected to be 0 for a function call");
350-
// We assume branching to local entry, will reverse the addend if not.
351-
Addend = ELF::decodePPC64LocalEntryOffset((*ObjSymbol)->st_other);
349+
// Determining a target is external or not is deferred in PostPrunePass.
350+
// We assume branching to local entry by default, since in PostPrunePass,
351+
// we don't have any context to determine LocalEntryOffset. If it finally
352+
// turns out to be an external call, we'll have a stub for the external
353+
// target, the target of this edge will be the stub and its addend will be
354+
// set 0.
355+
Addend += ELF::decodePPC64LocalEntryOffset((*ObjSymbol)->st_other);
352356
break;
353357
case ELF::R_PPC64_REL64:
354358
Kind = ppc64::Delta64;
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
# REQUIRES: asserts
21
# RUN: yaml2obj %S/Inputs/rel24-non-zero-addend.yaml -o %t.o
3-
# RUN: not --crash llvm-jitlink -noexec %t.o 2>&1 | FileCheck %s
4-
# CHECK: Addend == 0 && "Addend is expected to be 0 for a function call"
5-
#
2+
# RUN: llvm-jitlink -noexec %t.o 2>&1
63
# The object is generated from llvm/test/ExecutionEngine/MCJIT/test-global-ctors.ll,
74
# containing an R_PPC64_REL24 whose addend is not zero.

0 commit comments

Comments
 (0)