[PATCH] D71649: [PPC32] Emit R_PPC_PLTREL24 for calls to dso_local ifunc
Fangrui Song via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 17 22:53:35 PST 2019
MaskRay created this revision.
MaskRay added reviewers: PowerPC, hfinkel, nemanjai, jhibbits, sfertile, vit9696.
Herald added subscribers: llvm-commits, jsji, kbarton, hiraditya.
Herald added a project: LLVM.
static void *ifunc(void) __attribute__((ifunc("resolver")));
void foo() { ifunc(); }
The relocation produced by the ifunc() call:
1. gcc -msecure-plt -fPIC => R_PPC_PLTREL24 r_addend=0x8000
2. gcc -msecure-plt -PIE => R_PPC_PLTREL24 r_addend=0x8000
3. clang -msecure-plt -fPIC => R_PPC_PLTREL24 r_addend=0x8000
4. clang -msecure-plt -fPIE => R_PPC_REL24
4 is incorrect. The R_PPC_REL24 needs a call stub due to ifunc. If this
relocation is mixed with other R_PPC_PLTREL24(r_addend=0x8000) in a
function, both GNU ld and lld (after D71621 <https://reviews.llvm.org/D71621> fix) may produce a wrong
result.
This patch fixes 4 to use R_PPC_PLTREL24, which matches GCC.
Both GNU ld and lld (after D71621 <https://reviews.llvm.org/D71621>) will be happy.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71649
Files:
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
llvm/test/CodeGen/PowerPC/ifunc-dsolocal.ll
Index: llvm/test/CodeGen/PowerPC/ifunc-dsolocal.ll
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/PowerPC/ifunc-dsolocal.ll
@@ -0,0 +1,19 @@
+; RUN: llc %s -o - -mtriple=powerpc | FileCheck --check-prefix=REL %s
+; RUN: llc %s -o - -mtriple=powerpc -relocation-model=pic | FileCheck --check-prefix=PLTREL %s
+; RUN: llc %s -o - -mtriple=powerpc64 | FileCheck --check-prefix=REL %s
+; RUN: llc %s -o - -mtriple=powerpc64 -relocation-model=pic | FileCheck --check-prefix=REL %s
+
+ at ifunc1 = dso_local ifunc void(), i8*()* @resolver
+ at ifunc2 = ifunc void(), i8*()* @resolver
+
+define i8* @resolver() { ret i8* null }
+
+define void @foo() {
+ ; REL: bl ifunc1{{$}}
+ ; REL: bl ifunc2{{$}}
+ ; PLTREL: bl ifunc1 at PLT
+ ; PLTREL: bl ifunc2 at PLT
+ call void @ifunc1()
+ call void @ifunc2()
+ ret void
+}
Index: llvm/lib/Target/PowerPC/PPCISelLowering.cpp
===================================================================
--- llvm/lib/Target/PowerPC/PPCISelLowering.cpp
+++ llvm/lib/Target/PowerPC/PPCISelLowering.cpp
@@ -5102,9 +5102,10 @@
auto isLocalCallee = [&]() {
const GlobalAddressSDNode *G = dyn_cast<GlobalAddressSDNode>(Callee);
const Module *Mod = DAG.getMachineFunction().getFunction().getParent();
+ const GlobalValue *GV = G ? G->getGlobal() : nullptr;
- return DAG.getTarget().shouldAssumeDSOLocal(*Mod,
- G ? G->getGlobal() : nullptr);
+ return DAG.getTarget().shouldAssumeDSOLocal(*Mod, GV) &&
+ !dyn_cast_or_null<GlobalIFunc>(GV);
};
bool UsePlt = Subtarget.is32BitELFABI() && !isLocalCallee();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71649.234464.patch
Type: text/x-patch
Size: 1661 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191218/52b5ddf1/attachment.bin>
More information about the llvm-commits
mailing list