From a23bf1786be7c0738a4cf999c2957155bb32d5af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Storsj=C3=B6?= Date: Wed, 19 Jul 2023 14:48:50 +0300 Subject: [PATCH] [clang] [MinGW] Pass LTO options to the linker This matches what is done on other platforms too. This fixes one part of https://github.com/mstorsjo/llvm-mingw/issues/349. Differential Revision: https://reviews.llvm.org/D158411 --- clang/lib/Driver/ToolChains/MinGW.cpp | 6 ++++++ clang/test/Driver/mingw-lto.c | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/clang/lib/Driver/ToolChains/MinGW.cpp b/clang/lib/Driver/ToolChains/MinGW.cpp index b47041dcca70..4674e7fa268f 100644 --- a/clang/lib/Driver/ToolChains/MinGW.cpp +++ b/clang/lib/Driver/ToolChains/MinGW.cpp @@ -238,6 +238,12 @@ void tools::MinGW::Linker::ConstructJob(Compilation &C, const JobAction &JA, AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA); + if (D.isUsingLTO()) { + assert(!Inputs.empty() && "Must have at least one input."); + addLTOOptions(TC, Args, CmdArgs, Output, Inputs[0], + D.getLTOMode() == LTOK_Thin); + } + if (C.getDriver().IsFlangMode()) { addFortranRuntimeLibraryPath(TC, Args, CmdArgs); addFortranRuntimeLibs(TC, CmdArgs); diff --git a/clang/test/Driver/mingw-lto.c b/clang/test/Driver/mingw-lto.c index 6f5652ddfb86..c10ad6b821bd 100644 --- a/clang/test/Driver/mingw-lto.c +++ b/clang/test/Driver/mingw-lto.c @@ -1,4 +1,6 @@ // The default linker doesn't support LLVM bitcode // RUN: not %clang --target=i686-pc-windows-gnu %s -flto -fuse-ld=bfd // When using lld, this is allowed though. -// RUN: %clang --target=i686-pc-windows-gnu -### %s -flto -fuse-ld=lld -B%S/Inputs/lld +// RUN: %clang --target=i686-pc-windows-gnu -### %s -flto -fuse-ld=lld -B%S/Inputs/lld -femulated-tls 2>&1 | FileCheck %s + +// CHECK: "-plugin-opt=-emulated-tls"