From d2bb8c16e711602481c8b33d0e2ccc9994eb6641 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Wed, 1 Jan 2020 00:15:28 -0800 Subject: [MC][TargetMachine] Delete MCTargetOptions::MCPIECopyRelocations clang/lib/CodeGen/CodeGenModule performs the -mpie-copy-relocations check and sets dso_local on applicable global variables. We don't need to duplicate the work in TargetMachine shouldAssumeDSOLocal. Verified that -mpie-copy-relocations can still emit PC relative relocations for external variable accesses. clang -target x86_64 -fpie -mpie-copy-relocations -c => R_X86_64_PC32 clang -target aarch64 -fpie -mpie-copy-relocations -c => R_AARCH64_ADR_PREL_PG_HI21+R_AARCH64_LDST64_ABS_LO12_NC --- llvm/lib/Target/TargetMachine.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'llvm/lib/Target/TargetMachine.cpp') diff --git a/llvm/lib/Target/TargetMachine.cpp b/llvm/lib/Target/TargetMachine.cpp index 51991840506..97a1eb2f190 100644 --- a/llvm/lib/Target/TargetMachine.cpp +++ b/llvm/lib/Target/TargetMachine.cpp @@ -184,15 +184,14 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M, const Function *F = dyn_cast_or_null(GV); if (F && F->hasFnAttribute(Attribute::NonLazyBind)) return false; - - bool IsTLS = GV && GV->isThreadLocal(); - bool IsAccessViaCopyRelocs = - GV && Options.MCOptions.MCPIECopyRelocations && isa(GV); Triple::ArchType Arch = TT.getArch(); - bool IsPPC = - Arch == Triple::ppc || Arch == Triple::ppc64 || Arch == Triple::ppc64le; - // Check if we can use copy relocations. PowerPC has no copy relocations. - if (!IsTLS && !IsPPC && (RM == Reloc::Static || IsAccessViaCopyRelocs)) + + // PowerPC prefers avoiding copy relocations. + if (Arch == Triple::ppc || TT.isPPC64()) + return false; + + // Check if we can use copy relocations. + if (!(GV && GV->isThreadLocal()) && RM == Reloc::Static) return true; } -- cgit v1.2.3