[llvm] r310773 - D36604: PR34148: Do not assume we can use a copy relocation for an `external_weak` global
Richard Smith via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 11 16:52:28 PDT 2017
Author: rsmith
Date: Fri Aug 11 16:52:28 2017
New Revision: 310773
URL: http://llvm.org/viewvc/llvm-project?rev=310773&view=rev
Log:
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
Modified:
llvm/trunk/lib/Target/TargetMachine.cpp
llvm/trunk/test/CodeGen/X86/global-access-pie-copyrelocs.ll
Modified: llvm/trunk/lib/Target/TargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachine.cpp?rev=310773&r1=310772&r2=310773&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachine.cpp Fri Aug 11 16:52:28 2017
@@ -154,8 +154,9 @@ bool TargetMachine::shouldAssumeDSOLocal
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;
Modified: llvm/trunk/test/CodeGen/X86/global-access-pie-copyrelocs.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/global-access-pie-copyrelocs.ll?rev=310773&r1=310772&r2=310773&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/global-access-pie-copyrelocs.ll (original)
+++ llvm/trunk/test/CodeGen/X86/global-access-pie-copyrelocs.ll Fri Aug 11 16:52:28 2017
@@ -63,6 +63,20 @@ entry:
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 {
More information about the llvm-commits
mailing list