[llvm] r322739 - Use a got to access a hidden weak undefined on MachO.
Rafael Espindola via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 17 11:19:56 PST 2018
Author: rafael
Date: Wed Jan 17 11:19:55 2018
New Revision: 322739
URL: http://llvm.org/viewvc/llvm-project?rev=322739&view=rev
Log:
Use a got to access a hidden weak undefined on MachO.
Trying to link
__attribute__((weak, visibility("hidden"))) extern int foo;
int *main(void) {
return &foo;
}
on OS X fails with
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
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.
Modified:
llvm/trunk/lib/Target/TargetMachine.cpp
llvm/trunk/test/CodeGen/X86/hidden-vis-3.ll
Modified: llvm/trunk/lib/Target/TargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachine.cpp?rev=322739&r1=322738&r2=322739&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachine.cpp Wed Jan 17 11:19:55 2018
@@ -141,9 +141,7 @@ bool TargetMachine::shouldAssumeDSOLocal
// 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())
Modified: llvm/trunk/test/CodeGen/X86/hidden-vis-3.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/hidden-vis-3.ll?rev=322739&r1=322738&r2=322739&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/hidden-vis-3.ll (original)
+++ llvm/trunk/test/CodeGen/X86/hidden-vis-3.ll Wed Jan 17 11:19:55 2018
@@ -10,7 +10,7 @@ entry:
; 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]
More information about the llvm-commits
mailing list