[lld] r315400 - COFF: When generating code for LTO, use static reloc model on 32-bit x86.
Peter Collingbourne via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 10 17:46:58 PDT 2017
Author: pcc
Date: Tue Oct 10 17:46:58 2017
New Revision: 315400
URL: http://llvm.org/viewvc/llvm-project?rev=315400&view=rev
Log:
COFF: When generating code for LTO, use static reloc model on 32-bit x86.
Fixes PR34306.
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 bug).
Based on a patch by Carlo Kok.
Differential Revision: https://reviews.llvm.org/D38769
Added:
lld/trunk/test/COFF/lto-reloc-model.ll
Modified:
lld/trunk/COFF/LTO.cpp
Modified: lld/trunk/COFF/LTO.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/LTO.cpp?rev=315400&r1=315399&r2=315400&view=diff
==============================================================================
--- lld/trunk/COFF/LTO.cpp (original)
+++ lld/trunk/COFF/LTO.cpp Tue Oct 10 17:46:58 2017
@@ -64,7 +64,13 @@ static void saveBuffer(StringRef Buffer,
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;
Added: lld/trunk/test/COFF/lto-reloc-model.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/lto-reloc-model.ll?rev=315400&view=auto
==============================================================================
--- lld/trunk/test/COFF/lto-reloc-model.ll (added)
+++ lld/trunk/test/COFF/lto-reloc-model.ll Tue Oct 10 17:46:58 2017
@@ -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
+}
More information about the llvm-commits
mailing list