From a224de06bc816812a5918c146b351c92b05d6ed8 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 26 May 2016 12:42:55 +0000 Subject: Use shouldAssumeDSOLocal on AArch64. This reduces code duplication and now AArch64 also handles PIE. llvm-svn: 270844 --- llvm/lib/CodeGen/Analysis.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) (limited to 'llvm/lib/CodeGen') diff --git a/llvm/lib/CodeGen/Analysis.cpp b/llvm/lib/CodeGen/Analysis.cpp index 292142b848c..ef405484e84 100644 --- a/llvm/lib/CodeGen/Analysis.cpp +++ b/llvm/lib/CodeGen/Analysis.cpp @@ -650,6 +650,49 @@ bool llvm::canBeOmittedFromSymbolTable(const GlobalValue *GV) { return !GS.IsCompared; } +// FIXME: make this a proper option +static bool CanUseCopyRelocWithPIE = false; + +bool llvm::shouldAssumeDSOLocal(Reloc::Model RM, const Triple &TT, + const Module &M, const GlobalValue *GV) { + // 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 (RM == Reloc::Static) + return true; + + if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility())) + return true; + + if (TT.isOSBinFormatELF()) { + assert(RM != Reloc::DynamicNoPIC); + // Some linkers can use copy relocations with pie executables. + if (M.getPIELevel() != PIELevel::Default) { + if (CanUseCopyRelocWithPIE) + return true; + + // If the symbol is defined, it cannot be preempted. + if (GV && !GV->isDeclarationForLinker()) + return true; + return false; + } + + // ELF supports preemption of other symbols. + return false; + } + + assert(TT.isOSBinFormatMachO()); + if (GV && GV->isStrongDefinitionForLinker()) + return true; + + return false; +} + static void collectFuncletMembers( DenseMap &FuncletMembership, int Funclet, const MachineBasicBlock *MBB) { -- cgit v1.2.3