From: Richard Smith Date: Fri, 11 Aug 2017 23:52:28 +0000 (+0000) Subject: D36604: PR34148: Do not assume we can use a copy relocation for an `external_weak... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f604fb5d6e2ed2553fd52fd3ce540e706b2f9bbe;p=llvm D36604: PR34148: Do not assume we can use a copy relocation for an `external_weak` global An `external_weak` global may be intended to resolve as a null pointer if it's not defined, so it doesn't make sense to use a copy relocation for it. Differential Revision: https://reviews.llvm.org/D36604 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310773 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/TargetMachine.cpp b/lib/Target/TargetMachine.cpp index e8fe0a2b218..b2578fb7a02 100644 --- a/lib/Target/TargetMachine.cpp +++ b/lib/Target/TargetMachine.cpp @@ -154,8 +154,9 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M, return true; bool IsTLS = GV && GV->isThreadLocal(); - bool IsAccessViaCopyRelocs = - Options.MCOptions.MCPIECopyRelocations && GV && isa(GV); + bool IsAccessViaCopyRelocs = Options.MCOptions.MCPIECopyRelocations && GV && + isa(GV) && + !GV->hasExternalWeakLinkage(); Triple::ArchType Arch = TT.getArch(); bool IsPPC = Arch == Triple::ppc || Arch == Triple::ppc64 || Arch == Triple::ppc64le; diff --git a/test/CodeGen/X86/global-access-pie-copyrelocs.ll b/test/CodeGen/X86/global-access-pie-copyrelocs.ll index b0ecf3e942e..b370c4eeca9 100644 --- a/test/CodeGen/X86/global-access-pie-copyrelocs.ll +++ b/test/CodeGen/X86/global-access-pie-copyrelocs.ll @@ -63,6 +63,20 @@ entry: ret i32 %0 } +; ExternalWeak Linkage +@e = extern_weak global i32, align 4 + +define i32* @my_access_global_d() #0 { +; X32-LABEL: my_access_global_d: +; X32: addl $_GLOBAL_OFFSET_TABLE_{{.*}}, %eax +; X32: movl e@GOT(%eax), %eax +; X64-LABEL: my_access_global_d: +; X64: movq e@GOTPCREL(%rip), %rax + +entry: + ret i32* @e +} + ; External Linkage, only declaration, store a value. define i32 @my_access_global_store_d() #0 {