There is no need to use PLT to call locally defined function for PIE
since locally defined function in PIE can't be preempted.
Fixes PR 24970.
Differential D13481
[X86] Call locally defined function directly for PIE
hjl.tools on Oct 6 2015, 1:07 PM. Authored by
Details
There is no need to use PLT to call locally defined function for PIE Fixes PR 24970.
Diff Detail
Event Timeline
Comment Actions I tried putting ; LINUX-NOT: call{{l|q}} foo@PLT in the same file. But test passed even if llvm wasn't fixed. It seems that ; LINUX: call{{l|q}} foo matches call{{l|q}} foo@PLT and cancels ; LINUX-NOT: call{{l|q}} foo@PLT Comment Actions How about something like this? ; LINUX: call{{l|q}} foo{{ |$}} There are other alternatives as well. Just about anything would be better than replicating the entire test.
Comment Actions I added a helper function, ClassifyGlobalFunctionReference, and used Comment Actions This seems to work: diff --git a/lib/Target/X86/X86Subtarget.cpp b/lib/Target/X86/X86Subtarget.cpp index d94e91b..34f88b9 100644 --- a/lib/Target/X86/X86Subtarget.cpp +++ b/lib/Target/X86/X86Subtarget.cpp @@ -154,8 +154,8 @@ ClassifyGlobalFunctionReference(const GlobalValue *GV, // we don't need to use the PLT - we can directly call it. if (isTargetELF() && TM.getRelocationModel() == Reloc::PIC_ && - !(TM.Options.PositionIndependentExecutable && - GV->isStrongDefinitionForLinker()) && + (!TM.Options.PositionIndependentExecutable || + GV->isDeclarationForLinker()) && GV->hasDefaultVisibility() && !GV->hasLocalLinkage()) { return X86II::MO_PLT; } else if (isPICStyleStubAny() && Comment Actions This is still missing a testcase for other linkages (weak_odr and weak at least). Why do we need to use a PLT for calling those? Even for regular weak and linkonce, why do we need a plt? We know there is *a* definition in the executable. The static linker might resolve it to a definition in some other .o, but it will still be defined in the executable and cannot be preempted out of it.
|
This needs to be refactored to a helper function that is used in both places.
Should this really be isStrongDefinitionForLinker? If this is a weak_odr or linkonce_odr, can't we avoid the plt? Add a test for that one way or the other.