[PATCH] D36639: More fixes for weak undef and pic
Rafael Ávila de Espíndola via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Aug 11 14:55:03 PDT 2017
rafael created this revision.
I am going on vacation in a few hours and will not have time to finish this. Feel free to take over.
It turns out that at least on relocations that have produce a 0 at runtime, we cannot assume it is local. If we do, the architecture dependent part will assume it can always compute 0 from a position in the file. While 0 might always be in range, it will have a different offset in different executions.
If this goes in as is, there will be some code that is redundant and can be cleaned up.
https://reviews.llvm.org/D36639
Files:
lib/Target/TargetMachine.cpp
test/CodeGen/X86/global-access-pie-copyrelocs.ll
test/CodeGen/X86/hidden-vis-3.ll
test/CodeGen/X86/weak-undef.ll
Index: test/CodeGen/X86/weak-undef.ll
===================================================================
--- test/CodeGen/X86/weak-undef.ll
+++ test/CodeGen/X86/weak-undef.ll
@@ -8,7 +8,7 @@
; CHECK: bar1:
; CHECK: movq foo1 at GOTPCREL(%rip), %rax
; I386: bar1:
-; I386: leal foo1 at GOTOFF(%eax), %eax
+; I386: movl foo1 at GOT(%eax), %eax
@foo2 = external hidden global i32, align 4
define i32* @bar2() {
@@ -25,9 +25,9 @@
ret void
}
; CHECK: bar3:
-; CHECK: callq foo3
+; CHECK: callq foo3 at PLT
; I386: bar3:
-; I386: calll foo3
+; I386: calll foo3 at PLT
declare external hidden void @foo4()
define void @bar4() {
@@ -46,7 +46,7 @@
; CHECK: bar5:
; CHECK: movq foo5 at GOTPCREL(%rip), %rax
; I386: bar5:
-; I386: leal foo5 at GOTOFF(%eax), %eax
+; I386: movl foo5 at GOT(%eax), %eax
declare external hidden i32 @foo6()
define i32()* @bar6() {
Index: test/CodeGen/X86/hidden-vis-3.ll
===================================================================
--- test/CodeGen/X86/hidden-vis-3.ll
+++ test/CodeGen/X86/hidden-vis-3.ll
@@ -10,7 +10,8 @@
; X32: movl _y, %eax
; X64: _t:
-; X64: movl _y(%rip), %eax
+; X64: movq _y at GOTPCREL(%rip), %rax
+; X64: movl (%rax), %eax
%0 = load i32, i32* @x, align 4 ; <i32> [#uses=1]
%1 = load i32, i32* @y, align 4 ; <i32> [#uses=1]
Index: test/CodeGen/X86/global-access-pie-copyrelocs.ll
===================================================================
--- test/CodeGen/X86/global-access-pie-copyrelocs.ll
+++ 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: lib/Target/TargetMachine.cpp
===================================================================
--- lib/Target/TargetMachine.cpp
+++ lib/Target/TargetMachine.cpp
@@ -134,6 +134,16 @@
if (TT.isOSBinFormatCOFF() || (TT.isOSWindows() && TT.isOSBinFormatMachO()))
return true;
+ // A weak undef symbol might resolve to 0. We have to assume it is
+ // not local, as we have no control of where in memory we will end
+ // up.
+ // FIXME: is this true for all architectures?
+ // FIXME2: this is false for some relocations. For example, it should be valid
+ // to produce "call foo" instead of "call foo at plt". It is not clear if that is
+ // a problem.
+ if (GV && GV->hasExternalWeakLinkage() && isPositionIndependent())
+ return false;
+
if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility()))
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D36639.110819.patch
Type: text/x-patch
Size: 2841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170811/b7d62802/attachment.bin>
More information about the llvm-commits
mailing list