Index: lld/COFF/LTO.cpp =================================================================== --- lld/COFF/LTO.cpp +++ lld/COFF/LTO.cpp @@ -64,7 +64,13 @@ static std::unique_ptr 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; 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" + +@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 +}