forked from OSchip/llvm-project
[Driver] Allow setting the default linker during build
This change allows setting the default linker used by the Clang driver when configuring the build. Differential Revision: https://reviews.llvm.org/D25263 llvm-svn: 289668
This commit is contained in:
parent
f5bf03c7ef
commit
fe2c2b082f
|
@ -198,6 +198,9 @@ set(ENABLE_LINKER_BUILD_ID OFF CACHE BOOL "pass --build-id to ld")
|
|||
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
|
||||
|
|
|
@ -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}"
|
||||
|
||||
|
|
|
@ -105,7 +105,6 @@ private:
|
|||
|
||||
protected:
|
||||
MultilibSet Multilibs;
|
||||
const char *DefaultLinker = "ld";
|
||||
|
||||
ToolChain(const Driver &D, const llvm::Triple &T,
|
||||
const llvm::opt::ArgList &Args);
|
||||
|
@ -272,6 +271,11 @@ public:
|
|||
return 0;
|
||||
}
|
||||
|
||||
/// GetDefaultLinker - Get the default linker to use.
|
||||
virtual const char *getDefaultLinker() const {
|
||||
return "ld";
|
||||
}
|
||||
|
||||
/// GetDefaultRuntimeLibType - Get the default runtime library variant to use.
|
||||
virtual RuntimeLibType GetDefaultRuntimeLibType() const {
|
||||
return ToolChain::RLT_Libgcc;
|
||||
|
|
|
@ -351,33 +351,31 @@ std::string ToolChain::GetProgramPath(const char *Name) const {
|
|||
}
|
||||
|
||||
std::string ToolChain::GetLinkerPath() const {
|
||||
if (Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
|
||||
StringRef UseLinker = A->getValue();
|
||||
const Arg* A = Args.getLastArg(options::OPT_fuse_ld_EQ);
|
||||
StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
|
||||
|
||||
if (llvm::sys::path::is_absolute(UseLinker)) {
|
||||
// If we're passed -fuse-ld= with what looks like an absolute path,
|
||||
// don't attempt to second-guess that.
|
||||
if (llvm::sys::fs::exists(UseLinker))
|
||||
return UseLinker;
|
||||
} else {
|
||||
// If we're passed -fuse-ld= with no argument, or with the argument ld,
|
||||
// then use whatever the default system linker is.
|
||||
if (UseLinker.empty() || UseLinker == "ld")
|
||||
return GetProgramPath("ld");
|
||||
if (llvm::sys::path::is_absolute(UseLinker)) {
|
||||
// If we're passed what looks like an absolute path, don't attempt to
|
||||
// second-guess that.
|
||||
if (llvm::sys::fs::exists(UseLinker))
|
||||
return UseLinker;
|
||||
} else if (UseLinker.empty() || UseLinker == "ld") {
|
||||
// If we're passed -fuse-ld= with no argument, or with the argument ld,
|
||||
// then use whatever the default system linker is.
|
||||
return GetProgramPath(getDefaultLinker());
|
||||
} else {
|
||||
llvm::SmallString<8> LinkerName("ld.");
|
||||
LinkerName.append(UseLinker);
|
||||
|
||||
llvm::SmallString<8> LinkerName("ld.");
|
||||
LinkerName.append(UseLinker);
|
||||
|
||||
std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
|
||||
if (llvm::sys::fs::exists(LinkerPath))
|
||||
return LinkerPath;
|
||||
}
|
||||
|
||||
getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
|
||||
return "";
|
||||
std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
|
||||
if (llvm::sys::fs::exists(LinkerPath))
|
||||
return LinkerPath;
|
||||
}
|
||||
|
||||
return GetProgramPath(DefaultLinker);
|
||||
if (A)
|
||||
getDriver().Diag(diag::err_drv_invalid_linker_name) << A->getAsString(Args);
|
||||
|
||||
return GetProgramPath(getDefaultLinker());
|
||||
}
|
||||
|
||||
types::ID ToolChain::LookupTypeForExtension(StringRef Ext) const {
|
||||
|
|
|
@ -3059,9 +3059,6 @@ MipsLLVMToolChain::MipsLLVMToolChain(const Driver &D,
|
|||
LibSuffix = tools::mips::getMipsABILibSuffix(Args, Triple);
|
||||
getFilePaths().clear();
|
||||
getFilePaths().push_back(computeSysRoot() + "/usr/lib" + LibSuffix);
|
||||
|
||||
// Use LLD by default.
|
||||
DefaultLinker = "lld";
|
||||
}
|
||||
|
||||
void MipsLLVMToolChain::AddClangSystemIncludeArgs(
|
||||
|
@ -4749,9 +4746,6 @@ Fuchsia::Fuchsia(const Driver &D, const llvm::Triple &Triple,
|
|||
|
||||
getFilePaths().push_back(D.SysRoot + "/lib");
|
||||
getFilePaths().push_back(D.ResourceDir + "/lib/fuchsia");
|
||||
|
||||
// Use LLD by default.
|
||||
DefaultLinker = "lld";
|
||||
}
|
||||
|
||||
Tool *Fuchsia::buildAssembler() const {
|
||||
|
@ -5173,9 +5167,6 @@ WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
|
|||
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; }
|
||||
|
|
|
@ -961,6 +961,10 @@ public:
|
|||
: RuntimeLibType::RLT_CompilerRT;
|
||||
}
|
||||
|
||||
const char *getDefaultLinker() const override {
|
||||
return "lld";
|
||||
}
|
||||
|
||||
private:
|
||||
Multilib SelectedMultilib;
|
||||
std::string LibSuffix;
|
||||
|
@ -1090,6 +1094,10 @@ public:
|
|||
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;
|
||||
|
@ -1289,6 +1297,10 @@ private:
|
|||
const llvm::opt::ArgList &DriverArgs,
|
||||
llvm::opt::ArgStringList &CC1Args) const override;
|
||||
|
||||
const char *getDefaultLinker() const override {
|
||||
return "lld";
|
||||
}
|
||||
|
||||
Tool *buildLinker() const override;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in New Issue