]> granicus.if.org Git - clang/commitdiff
[MinGW] Allow using LTO when lld is used as linker
authorMartin Storsjo <martin@martin.st>
Fri, 12 Oct 2018 20:15:51 +0000 (20:15 +0000)
committerMartin Storsjo <martin@martin.st>
Fri, 12 Oct 2018 20:15:51 +0000 (20:15 +0000)
Differential Revision: https://reviews.llvm.org/D53195

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344412 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Driver/ToolChains/MinGW.cpp
lib/Driver/ToolChains/MinGW.h
test/Driver/mingw-lto.c [new file with mode: 0644]

index f9e641e63fffcf037bb446f86484a7308ae8138f..4a68205f95e3ed1e03ebc64051ab3d66852c0c43 100644 (file)
@@ -10,6 +10,7 @@
 #include "MinGW.h"
 #include "InputInfo.h"
 #include "CommonArgs.h"
+#include "clang/Config/config.h"
 #include "clang/Driver/Compilation.h"
 #include "clang/Driver/Driver.h"
 #include "clang/Driver/DriverDiagnostic.h"
@@ -376,6 +377,10 @@ toolchains::MinGW::MinGW(const Driver &D, const llvm::Triple &Triple,
   getFilePaths().push_back(Base + "lib");
   // openSUSE
   getFilePaths().push_back(Base + Arch + "/sys-root/mingw/lib");
+
+  NativeLLVMSupport =
+      Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER)
+          .equals_lower("lld");
 }
 
 bool toolchains::MinGW::IsIntegratedAssemblerDefault() const { return true; }
@@ -403,6 +408,10 @@ Tool *toolchains::MinGW::buildLinker() const {
   return new tools::MinGW::Linker(*this);
 }
 
+bool toolchains::MinGW::HasNativeLLVMSupport() const {
+  return NativeLLVMSupport;
+}
+
 bool toolchains::MinGW::IsUnwindTablesDefault(const ArgList &Args) const {
   return getArch() == llvm::Triple::x86_64;
 }
index 450044d45127db282eb9a01d2e22136a97451009..04d23006ee75df124f81d856c67f57b6994fed57 100644 (file)
@@ -59,6 +59,8 @@ public:
   MinGW(const Driver &D, const llvm::Triple &Triple,
         const llvm::opt::ArgList &Args);
 
+  bool HasNativeLLVMSupport() const override;
+
   bool IsIntegratedAssemblerDefault() const override;
   bool IsUnwindTablesDefault(const llvm::opt::ArgList &Args) const override;
   bool isPICDefault() const override;
@@ -99,6 +101,8 @@ private:
   void findGccLibDir();
   llvm::ErrorOr<std::string> findGcc();
   llvm::ErrorOr<std::string> findClangRelativeSysroot();
+
+  bool NativeLLVMSupport;
 };
 
 } // end namespace toolchains
diff --git a/test/Driver/mingw-lto.c b/test/Driver/mingw-lto.c
new file mode 100644 (file)
index 0000000..8bb4aed
--- /dev/null
@@ -0,0 +1,4 @@
+// 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