Index: CMakeLists.txt =================================================================== --- CMakeLists.txt +++ CMakeLists.txt @@ -198,6 +198,9 @@ set(ENABLE_X86_RELAX_RELOCATIONS OFF CACHE BOOL "enable x86 relax relocations by default") +set(CLANG_DEFAULT_LINKER "" CACHE STRING + "Default linker to use (linker name or absolute path, empty for platform default)") + set(CLANG_DEFAULT_CXX_STDLIB "" CACHE STRING "Default C++ stdlib to use (\"libstdc++\" or \"libc++\", empty for platform default") if (NOT(CLANG_DEFAULT_CXX_STDLIB STREQUAL "" OR Index: include/clang/Config/config.h.cmake =================================================================== --- include/clang/Config/config.h.cmake +++ include/clang/Config/config.h.cmake @@ -8,6 +8,9 @@ /* Bug report URL. */ #define BUG_REPORT_URL "${BUG_REPORT_URL}" +/* Default linker to use. */ +#define CLANG_DEFAULT_LINKER "${CLANG_DEFAULT_LINKER}" + /* Default C++ stdlib to use. */ #define CLANG_DEFAULT_CXX_STDLIB "${CLANG_DEFAULT_CXX_STDLIB}" Index: include/clang/Driver/ToolChain.h =================================================================== --- include/clang/Driver/ToolChain.h +++ include/clang/Driver/ToolChain.h @@ -104,7 +104,6 @@ protected: MultilibSet Multilibs; - const char *DefaultLinker = "ld"; ToolChain(const Driver &D, const llvm::Triple &T, const llvm::opt::ArgList &Args); @@ -450,6 +449,8 @@ /// \brief On Windows, returns the version of cl.exe. On other platforms, /// returns an empty VersionTuple. virtual VersionTuple getMSVCVersionFromExe() const { return VersionTuple(); } + + virtual const char *getDefaultLinker() const; }; /// Set a ToolChain's effective triple. Reset it when the registration object Index: lib/Driver/ToolChain.cpp =================================================================== --- lib/Driver/ToolChain.cpp +++ lib/Driver/ToolChain.cpp @@ -374,10 +374,9 @@ } getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args); - return ""; } - return GetProgramPath(DefaultLinker); + return GetProgramPath(getDefaultLinker()); } types::ID ToolChain::LookupTypeForExtension(StringRef Ext) const { @@ -719,3 +718,7 @@ void ToolChain::AddIAMCUIncludeArgs(const ArgList &DriverArgs, ArgStringList &CC1Args) const {} + +const char *ToolChain::getDefaultLinker() const { + return CLANG_DEFAULT_LINKER; +} Index: lib/Driver/ToolChains.h =================================================================== --- lib/Driver/ToolChains.h +++ lib/Driver/ToolChains.h @@ -926,6 +926,10 @@ : RuntimeLibType::RLT_CompilerRT; } + const char *getDefaultLinker() const override { + return "lld"; + } + private: Multilib SelectedMultilib; std::string LibSuffix; @@ -1055,6 +1059,10 @@ void AddCXXStdlibLibArgs(const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs) const override; + const char *getDefaultLinker() const override { + return "lld"; + } + protected: Tool *buildAssembler() const override; Tool *buildLinker() const override; @@ -1241,6 +1249,10 @@ const llvm::opt::ArgList &DriverArgs, llvm::opt::ArgStringList &CC1Args) const override; + const char *getDefaultLinker() const override { + return "lld"; + } + Tool *buildLinker() const override; }; Index: lib/Driver/ToolChains.cpp =================================================================== --- lib/Driver/ToolChains.cpp +++ lib/Driver/ToolChains.cpp @@ -2976,9 +2976,6 @@ LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple); getFilePaths().clear(); getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix); - - // Use LLD by default. - DefaultLinker = "lld"; } void MipsLLVMToolChain::AddClangSystemIncludeArgs( @@ -4842,9 +4839,6 @@ getFilePaths().push_back(D.SysRoot + "/lib"); getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia"); - - // Use LLD by default. - DefaultLinker = "lld"; } Tool *Fuchsia::buildAssembler() const { @@ -5222,9 +5216,6 @@ assert(Triple.isArch32Bit() != Triple.isArch64Bit()); getFilePaths().push_back( getDriver().SysRoot + "/lib" + (Triple.isArch32Bit() ? "32" : "64")); - - // Use LLD by default. - DefaultLinker = "lld"; } bool WebAssembly::IsMathErrnoDefault() const { return false; }