[PATCH] D38769: COFF: When generating code for LTO, use static reloc model on 32-bit x86.

Peter Collingbourne via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 10 17:47:17 PDT 2017


This revision was automatically updated to reflect the committed changes.
Closed by commit rL315400: COFF: When generating code for LTO, use static reloc model on 32-bit x86. (authored by pcc).

Changed prior to commit:
  https://reviews.llvm.org/D38769?vs=118496&id=118516#toc

Repository:
  rL LLVM

https://reviews.llvm.org/D38769

Files:
  lld/trunk/COFF/LTO.cpp
  lld/trunk/test/COFF/lto-reloc-model.ll


Index: lld/trunk/test/COFF/lto-reloc-model.ll
===================================================================
--- lld/trunk/test/COFF/lto-reloc-model.ll
+++ lld/trunk/test/COFF/lto-reloc-model.ll
@@ -0,0 +1,19 @@
+; RUN: llvm-as -o %t %s
+; RUN: lld-link /entry:main /subsystem:console /out:%t.exe %t
+; RUN: llvm-objdump -d %t.exe | FileCheck %s
+
+target datalayout = "e-m:x-p:32:32-i64:64-f80:32-n8:16:32-a:0:32-S32"
+target triple = "i686-pc-windows-msvc"
+
+ at foo = thread_local global i8 0
+
+module asm "__tls_index = 1"
+module asm "__tls_array = 2"
+
+define i8* @main() {
+  ; CHECK: movl 1, %eax
+  ; CHECK: movl %fs:2, %ecx
+  ; CHECK: movl (%ecx,%eax,4), %eax
+  ; CHECK: leal (%eax), %eax
+  ret i8* @foo
+}
Index: lld/trunk/COFF/LTO.cpp
===================================================================
--- lld/trunk/COFF/LTO.cpp
+++ lld/trunk/COFF/LTO.cpp
@@ -64,7 +64,13 @@
 static std::unique_ptr<lto::LTO> createLTO() {
   lto::Config Conf;
   Conf.Options = InitTargetOptionsFromCodeGenFlags();
-  Conf.RelocModel = Reloc::PIC_;
+  // Use static reloc model on 32-bit x86 because it usually results in more
+  // compact code, and because there are also known code generation bugs when
+  // using the PIC model (see PR34306).
+  if (Config->Machine == COFF::IMAGE_FILE_MACHINE_I386)
+    Conf.RelocModel = Reloc::Static;
+  else
+    Conf.RelocModel = Reloc::PIC_;
   Conf.DisableVerify = true;
   Conf.DiagHandler = diagnosticHandler;
   Conf.OptLevel = Config->LTOOptLevel;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D38769.118516.patch
Type: text/x-patch
Size: 1502 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171011/d32f269d/attachment.bin>


More information about the llvm-commits mailing list