[PATCH] D42009: Use a got to access a hidden weak undefined on MachO
Rafael Avila de Espindola via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 12 13:24:34 PST 2018
espindola created this revision.
espindola added reviewers: rnk, mehdi_amini.
Herald added a subscriber: hiraditya.
Trying to link
__attribute__((weak, visibility("hidden"))) extern int foo;
int *main(void) {
return &foo;
}
on OS X fails with
final section layout:
__TEXT/__text addr=0x100000FAB, size=0x0000000D, fileOffset=0x00000FAB, type=1
__TEXT/__unwind_info addr=0x100000FB8, size=0x00000048, fileOffset=0x00000FB8, type=22
ld: 32-bit RIP relative reference out of range (-4294971318 max is +/-2GB): from _main (0x100000FAB) to _foo at 0x00001000 (0x00000000) in '_main' from test.o for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
The problem being that 0 cannot be computed as a fixed difference from %rip. Exactly the same issue exists on ELF and we can use the same solution.
https://reviews.llvm.org/D42009
Files:
llvm/lib/Target/TargetMachine.cpp
llvm/test/CodeGen/X86/hidden-vis-3.ll
Index: llvm/test/CodeGen/X86/hidden-vis-3.ll
===================================================================
--- llvm/test/CodeGen/X86/hidden-vis-3.ll
+++ llvm/test/CodeGen/X86/hidden-vis-3.ll
@@ -10,7 +10,7 @@
; X32: movl _y, %eax
; X64: _t:
-; X64: movl _y(%rip), %eax
+; X64: movq _y at GOTPCREL(%rip), %rax
%0 = load i32, i32* @x, align 4 ; <i32> [#uses=1]
%1 = load i32, i32* @y, align 4 ; <i32> [#uses=1]
Index: llvm/lib/Target/TargetMachine.cpp
===================================================================
--- llvm/lib/Target/TargetMachine.cpp
+++ llvm/lib/Target/TargetMachine.cpp
@@ -141,9 +141,7 @@
// produce a 0 if it turns out the symbol is undefined. While this
// is ABI and relocation depended, it seems worth it to handle it
// here.
- // FIXME: this is probably not ELF specific.
- if (GV && isPositionIndependent() && TT.isOSBinFormatELF() &&
- GV->hasExternalWeakLinkage())
+ if (GV && isPositionIndependent() && GV->hasExternalWeakLinkage())
return false;
if (GV && !GV->hasDefaultVisibility())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42009.129696.patch
Type: text/x-patch
Size: 1063 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180112/fecf67ba/attachment.bin>
More information about the llvm-commits
mailing list