[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 15:17:13 PDT 2017
pcc created this revision.
Herald added subscribers: inglorion, mehdi_amini.
This is because it usually results in more compact code, and because
there are also known code generation bugs when using the PIC model
(see PR34306).
Based on a patch by Carlo Kok.
https://reviews.llvm.org/D38769
Files:
lld/COFF/LTO.cpp
lld/test/COFF/lto-reloc-model.ll
Index: lld/test/COFF/lto-reloc-model.ll
===================================================================
--- /dev/null
+++ lld/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/COFF/LTO.cpp
===================================================================
--- lld/COFF/LTO.cpp
+++ lld/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.118496.patch
Type: text/x-patch
Size: 1443 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20171010/0525038f/attachment.bin>
More information about the llvm-commits
mailing list