diff options
author | Rafael Espindola <rafael.espindola@gmail.com> | 2016-06-27 23:15:57 +0000 |
---|---|---|
committer | Rafael Espindola <rafael.espindola@gmail.com> | 2016-06-27 23:15:57 +0000 |
commit | 3beef8d6db3688b8265728a3b05970cd9628f523 (patch) | |
tree | 310d78331dae592b820e026554e21456ed5535d7 /llvm/lib/Target/TargetMachine.cpp | |
parent | 990ff38786ce2300a38eeaaba510c40170223ef6 (diff) | |
download | bcm5719-llvm-3beef8d6db3688b8265728a3b05970cd9628f523.tar.gz bcm5719-llvm-3beef8d6db3688b8265728a3b05970cd9628f523.zip |
Move shouldAssumeDSOLocal to Target.
Should fix the shared library build.
llvm-svn: 273958
Diffstat (limited to 'llvm/lib/Target/TargetMachine.cpp')
-rw-r--r-- | llvm/lib/Target/TargetMachine.cpp | 47 |
1 files changed, 46 insertions, 1 deletions
diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index d7617e73245..b703105eaf4 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -110,11 +110,56 @@ static TLSModel::Model getSelectedTLSModel(const GlobalValue *GV) { llvm_unreachable("invalid TLS model"); } +// FIXME: make this a proper option +static bool CanUseCopyRelocWithPIE = false; + +bool TargetMachine::shouldAssumeDSOLocal(const Module &M, + const GlobalValue *GV) const { + Reloc::Model RM = getRelocationModel(); + const Triple &TT = getTargetTriple(); + + // DLLImport explicitly marks the GV as external. + if (GV && GV->hasDLLImportStorageClass()) + return false; + + // Every other GV is local on COFF + if (TT.isOSBinFormatCOFF()) + return true; + + if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility())) + return true; + + if (TT.isOSBinFormatMachO()) { + if (RM == Reloc::Static) + return true; + return GV && GV->isStrongDefinitionForLinker(); + } + + assert(TT.isOSBinFormatELF()); + assert(RM != Reloc::DynamicNoPIC); + + bool IsExecutable = + RM == Reloc::Static || M.getPIELevel() != PIELevel::Default; + if (IsExecutable) { + // If the symbol is defined, it cannot be preempted. + if (GV && !GV->isDeclarationForLinker()) + return true; + + bool IsTLS = GV && GV->isThreadLocal(); + // Check if we can use copy relocations. + if (!IsTLS && (RM == Reloc::Static || CanUseCopyRelocWithPIE)) + return true; + } + + // ELF supports preemption of other symbols. + return false; +} + TLSModel::Model TargetMachine::getTLSModel(const GlobalValue *GV) const { bool IsPIE = GV->getParent()->getPIELevel() != PIELevel::Default; Reloc::Model RM = getRelocationModel(); bool IsSharedLibrary = RM == Reloc::PIC_ && !IsPIE; - bool IsLocal = shouldAssumeDSOLocal(RM, TargetTriple, *GV->getParent(), GV); + bool IsLocal = shouldAssumeDSOLocal(*GV->getParent(), GV); TLSModel::Model Model; if (IsSharedLibrary) { |