[PATCH] D158411: [clang] [MinGW] Pass LTO options to the linker

Martin Storsjö via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 21 04:47:47 PDT 2023


mstorsjo created this revision.
mstorsjo added a reviewer: MaskRay.
Herald added subscribers: ormris, steven_wu, hiraditya, inglorion.
Herald added a project: All.
mstorsjo requested review of this revision.
Herald added a project: clang.

This matches what is done on other platforms too.

This fixes one part of
https://github.com/mstorsjo/llvm-mingw/issues/349.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158411

Files:
  clang/lib/Driver/ToolChains/MinGW.cpp
  clang/test/Driver/mingw-lto.c


Index: clang/test/Driver/mingw-lto.c
===================================================================
--- clang/test/Driver/mingw-lto.c
+++ 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"
Index: clang/lib/Driver/ToolChains/MinGW.cpp
===================================================================
--- clang/lib/Driver/ToolChains/MinGW.cpp
+++ clang/lib/Driver/ToolChains/MinGW.cpp
@@ -238,6 +238,12 @@
 
   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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158411.551985.patch
Type: text/x-patch
Size: 1217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230821/a07ab439/attachment.bin>


More information about the cfe-commits mailing list