]> granicus.if.org Git - llvm/commitdiff
X86: Do not produce GOT relocations on windows
authorMatthias Braun <matze@braunis.de>
Mon, 3 Oct 2016 20:11:24 +0000 (20:11 +0000)
committerMatthias Braun <matze@braunis.de>
Mon, 3 Oct 2016 20:11:24 +0000 (20:11 +0000)
Windows has no GOT relocations the way elf/darwin has. Some people use
x86_64-pc-win32-macho to build EFI firmware; Do not produce GOT
relocations for this target.

Differential Revision: https://reviews.llvm.org/D24627

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@283140 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/TargetMachine.cpp
test/CodeGen/X86/x86-64-pic-12.ll [new file with mode: 0644]

index 17caed973910a2269bf8506d89310135ecacfbe8..d7b34f84afc60291e4c799fa14221c464b4132ff 100644 (file)
@@ -127,8 +127,11 @@ bool TargetMachine::shouldAssumeDSOLocal(const Module &M,
   if (GV && GV->hasDLLImportStorageClass())
     return false;
 
-  // Every other GV is local on COFF
-  if (TT.isOSBinFormatCOFF())
+  // Every other GV is local on COFF.
+  // Make an exception for windows OS in the triple: Some firmwares builds use
+  // *-win32-macho triples. This (accidentally?) produced windows relocations
+  // without GOT tables in older clang versions; Keep this behaviour.
+  if (TT.isOSBinFormatCOFF() || TT.isOSWindows())
     return true;
 
   if (GV && (GV->hasLocalLinkage() || !GV->hasDefaultVisibility()))
diff --git a/test/CodeGen/X86/x86-64-pic-12.ll b/test/CodeGen/X86/x86-64-pic-12.ll
new file mode 100644 (file)
index 0000000..fa8b8ac
--- /dev/null
@@ -0,0 +1,27 @@
+; RUN: llc -o - %s -relocation-model=pic | FileCheck %s
+; Check that we do not get GOT relocations with the x86_64-pc-windows-macho
+; triple.
+target triple = "x86_64-pc-windows-macho"
+
+@g = common global i32 0, align 4
+
+declare i32 @extbar()
+
+; CHECK-LABEL: bar:
+; CHECK: callq _extbar
+; CHECK: leaq _extbar(%rip),
+; CHECK-NOT: @GOT
+define i8* @bar() {
+  call i32 @extbar()
+  ret i8* bitcast (i32 ()* @extbar to i8*)
+}
+
+; CHECK-LABEL: foo:
+; CHECK: callq _bar
+; CHECK: movl _g(%rip),
+; CHECK-NOT: @GOT
+define i32 @foo() {
+  call i8* @bar()
+  %gval = load i32, i32* @g, align 4
+  ret i32 %gval
+}