[llvm] r283140 - X86: Do not produce GOT relocations on windows

Matthias Braun via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 3 13:11:24 PDT 2016


Author: matze
Date: Mon Oct  3 15:11:24 2016
New Revision: 283140

URL: http://llvm.org/viewvc/llvm-project?rev=283140&view=rev
Log:
X86: Do not produce GOT relocations on windows

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

Added:
    llvm/trunk/test/CodeGen/X86/x86-64-pic-12.ll
Modified:
    llvm/trunk/lib/Target/TargetMachine.cpp

Modified: llvm/trunk/lib/Target/TargetMachine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachine.cpp?rev=283140&r1=283139&r2=283140&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachine.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachine.cpp Mon Oct  3 15:11:24 2016
@@ -127,8 +127,11 @@ bool TargetMachine::shouldAssumeDSOLocal
   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()))

Added: llvm/trunk/test/CodeGen/X86/x86-64-pic-12.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/x86-64-pic-12.ll?rev=283140&view=auto
==============================================================================
--- llvm/trunk/test/CodeGen/X86/x86-64-pic-12.ll (added)
+++ llvm/trunk/test/CodeGen/X86/x86-64-pic-12.ll Mon Oct  3 15:11:24 2016
@@ -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"
+
+ at 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
+}




More information about the llvm-commits mailing list