diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2018-02-19 16:02:38 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2018-02-19 16:02:38 +0000 |
commit | c7e51805ff52e84594b0514d5bdf31579434b80c (patch) | |
tree | 8b16479bcae90b6f88b97cbdc450ee5a78b8bbdd /llvm/lib/Target/TargetMachine.cpp | |
parent | 9c5ac63785b5aac0c85b57637409869b27983bfe (diff) | |
download | bcm5719-llvm-c7e51805ff52e84594b0514d5bdf31579434b80c.tar.gz bcm5719-llvm-c7e51805ff52e84594b0514d5bdf31579434b80c.zip |
Bring back r323297.
It was reverted because it broke the grub build. The reason the grub
build broke is because grub does its own relocation processing and was
not handing R_386_PLT32. Since grub has no dynamic linker, the fix is
trivial: handle R_386_PLT32 exactly like R_386_PC32.
On the report it was noted that they are using
-fno-integrated-assembler. The upstream GAS (starting with
451875b4f976a527395e9303224c7881b65e12ed) will already be producing a
R_386_PLT32 anyway, so they have to update their code one way or the
other
Original message:
Don't assume a null GV is local for ELF and MachO.
This is already a simplification, and should help with avoiding a plt
reference when calling an intrinsic with -fno-plt.
With this change we return false for null GVs, so the caller only
needs to check the new metadata to decide if it should use foo@plt or
*foo@got.
llvm-svn: 325514
Diffstat (limited to 'llvm/lib/Target/TargetMachine.cpp')
-rw-r--r-- | llvm/lib/Target/TargetMachine.cpp | 21 |
1 files changed, 14 insertions, 7 deletions
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index ee5b010ecf2..76ec541f8b6 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -137,20 +137,27 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M, if (TT.isOSBinFormatCOFF() || (TT.isOSWindows() && TT.isOSBinFormatMachO())) return true; + // If GV is null we know that this is a call to an intrinsic. For ELF and + // MachO we don't need to assume those are local since the liker can trivially + // convert a call to a PLT to a direct call if the target (in the runtime + // library) turns out to be local. + if (!GV) + return false; + // Most PIC code sequences that assume that a symbol is local cannot // produce a 0 if it turns out the symbol is undefined. While this // is ABI and relocation depended, it seems worth it to handle it // here. - if (GV && isPositionIndependent() && GV->hasExternalWeakLinkage()) + if (isPositionIndependent() && GV->hasExternalWeakLinkage()) return false; - if (GV && !GV->hasDefaultVisibility()) + if (!GV->hasDefaultVisibility()) return true; if (TT.isOSBinFormatMachO()) { if (RM == Reloc::Static) return true; - return GV && GV->isStrongDefinitionForLinker(); + return GV->isStrongDefinitionForLinker(); } assert(TT.isOSBinFormatELF()); @@ -160,19 +167,19 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M, RM == Reloc::Static || M.getPIELevel() != PIELevel::Default; if (IsExecutable) { // If the symbol is defined, it cannot be preempted. - if (GV && !GV->isDeclarationForLinker()) + if (!GV->isDeclarationForLinker()) return true; // A symbol marked nonlazybind should not be accessed with a plt. If the // symbol turns out to be external, the linker will convert a direct // access to an access via the plt, so don't assume it is local. - const Function *F = dyn_cast_or_null<Function>(GV); + const Function *F = dyn_cast<Function>(GV); if (F && F->hasFnAttribute(Attribute::NonLazyBind)) return false; - bool IsTLS = GV && GV->isThreadLocal(); + bool IsTLS = GV->isThreadLocal(); bool IsAccessViaCopyRelocs = - Options.MCOptions.MCPIECopyRelocations && GV && isa<GlobalVariable>(GV); + Options.MCOptions.MCPIECopyRelocations && isa<GlobalVariable>(GV); Triple::ArchType Arch = TT.getArch(); bool IsPPC = Arch == Triple::ppc || Arch == Triple::ppc64 || Arch == Triple::ppc64le; |