summaryrefslogtreecommitdiffstats
path: root/clang/lib/Driver/ToolChain.cpp
diff options
context:
space:
mode:
authorPeter Zotov <whitequark@whitequark.org>2016-03-09 05:18:16 +0000
committerPeter Zotov <whitequark@whitequark.org>2016-03-09 05:18:16 +0000
commite43b7413597d8102a4412f9de41102e55f4f2ec9 (patch)
tree778eea25363d431d44df2f12466ef330620a9c72 /clang/lib/Driver/ToolChain.cpp
parentddfa1a6c18afd4cfe78778e7f29145801b6d8fbe (diff)
downloadbcm5719-llvm-e43b7413597d8102a4412f9de41102e55f4f2ec9.tar.gz
bcm5719-llvm-e43b7413597d8102a4412f9de41102e55f4f2ec9.zip
Accept absolute paths in the -fuse-ld option.
This patch extends the -fuse-ld option to accept a full path to an executable and use it verbatim to invoke the linker. There are generally two reasons to desire this. The first reason relates to the sad truth is that Clang is retargetable, Binutils are not. While any Clang from a binary distribution is sufficient to compile code for a wide range of architectures and prefixed BFD linkers (e.g. installed as /usr/bin/arm-none-linux-gnueabi-ld) as well as cross-compiled libc's (for non-bare-metal targets) are widely available, including on all Debian derivatives, it is impossible to use them together because the -fuse-ld= option allows to specify neither a linker prefix nor a full path to one. The second reason is linker development, both when porting existing linkers to new architectures and when working on a new linker such as LLD. Differential Revision: http://reviews.llvm.org/D17952 llvm-svn: 262996
Diffstat (limited to 'clang/lib/Driver/ToolChain.cpp')
-rw-r--r--clang/lib/Driver/ToolChain.cpp33
1 files changed, 20 insertions, 13 deletions
diff --git a/clang/lib/Driver/ToolChain.cpp b/clang/lib/Driver/ToolChain.cpp
index 97eee59d127..c1305f1b790 100644
--- a/clang/lib/Driver/ToolChain.cpp
+++ b/clang/lib/Driver/ToolChain.cpp
@@ -342,19 +342,26 @@ std::string ToolChain::GetProgramPath(const char *Name) const {
std::string ToolChain::GetLinkerPath() const {
if (Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
- StringRef Suffix = A->getValue();
-
- // If we're passed -fuse-ld= with no argument, or with the argument ld,
- // then use whatever the default system linker is.
- if (Suffix.empty() || Suffix == "ld")
- return GetProgramPath("ld");
-
- llvm::SmallString<8> LinkerName("ld.");
- LinkerName.append(Suffix);
-
- std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
- if (llvm::sys::fs::exists(LinkerPath))
- return LinkerPath;
+ StringRef UseLinker = A->getValue();
+
+ 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");
+
+ 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 "";
OpenPOWER on IntegriCloud