Skip to content

Commit

Permalink
[MinGW] Allow using LTO when lld is used as linker
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D53195

llvm-svn: 344412
  • Loading branch information
mstorsjo committed Oct 12, 2018
1 parent 22297d9 commit 4b75df2
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
9 changes: 9 additions & 0 deletions clang/lib/Driver/ToolChains/MinGW.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -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;
}
Expand Down
4 changes: 4 additions & 0 deletions clang/lib/Driver/ToolChains/MinGW.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ class LLVM_LIBRARY_VISIBILITY MinGW : public ToolChain {
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;
Expand Down Expand Up @@ -99,6 +101,8 @@ class LLVM_LIBRARY_VISIBILITY MinGW : public ToolChain {
void findGccLibDir();
llvm::ErrorOr<std::string> findGcc();
llvm::ErrorOr<std::string> findClangRelativeSysroot();

bool NativeLLVMSupport;
};

} // end namespace toolchains
Expand Down
4 changes: 4 additions & 0 deletions clang/test/Driver/mingw-lto.c
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4b75df2

Please sign in to comment.