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

llvm-svn: 315400
This commit is contained in:
Peter Collingbourne 2017-10-11 00:46:58 +00:00
parent 85b1da1dc4
commit 8a40a7b15c
2 changed files with 26 additions and 1 deletions

View File

@ -64,7 +64,13 @@ static void saveBuffer(StringRef Buffer, const Twine &Path) {
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;

View File

@ -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"
@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
}