[PATCH] D36604: PR34148: Do not assume we can use a copy relocation for an `external_weak` global

Richard Smith - zygoloid via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 11 16:53:32 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL310773: D36604: PR34148: Do not assume we can use a copy relocation for an… (authored by rsmith).

Changed prior to commit:
  https://reviews.llvm.org/D36604?vs=110671&id=110826#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D36604

Files:
  llvm/trunk/lib/Target/TargetMachine.cpp
  llvm/trunk/test/CodeGen/X86/global-access-pie-copyrelocs.ll


Index: llvm/trunk/test/CodeGen/X86/global-access-pie-copyrelocs.ll
===================================================================
--- llvm/trunk/test/CodeGen/X86/global-access-pie-copyrelocs.ll
+++ llvm/trunk/test/CodeGen/X86/global-access-pie-copyrelocs.ll
@@ -63,6 +63,20 @@
   ret i32 %0
 }
 
+; ExternalWeak Linkage
+ at 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 at GOT(%eax), %eax
+; X64-LABEL: my_access_global_d:
+; X64:       movq e at GOTPCREL(%rip), %rax
+
+entry:
+  ret i32* @e
+}
+
 ; External Linkage, only declaration, store a value.
 
 define i32 @my_access_global_store_d() #0 {
Index: llvm/trunk/lib/Target/TargetMachine.cpp
===================================================================
--- llvm/trunk/lib/Target/TargetMachine.cpp
+++ llvm/trunk/lib/Target/TargetMachine.cpp
@@ -154,8 +154,9 @@
       return true;
 
     bool IsTLS = GV && GV->isThreadLocal();
-    bool IsAccessViaCopyRelocs =
-        Options.MCOptions.MCPIECopyRelocations && GV && isa<GlobalVariable>(GV);
+    bool IsAccessViaCopyRelocs = Options.MCOptions.MCPIECopyRelocations && GV &&
+                                 isa<GlobalVariable>(GV) &&
+                                 !GV->hasExternalWeakLinkage();
     Triple::ArchType Arch = TT.getArch();
     bool IsPPC =
         Arch == Triple::ppc || Arch == Triple::ppc64 || Arch == Triple::ppc64le;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36604.110826.patch
Type: text/x-patch
Size: 1494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170811/fb8bb330/attachment.bin>


More information about the llvm-commits mailing list