r262996 - Accept absolute paths in the -fuse-ld option.
Peter Zotov via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 8 21:18:17 PST 2016
Author: whitequark
Date: Tue Mar 8 23:18:16 2016
New Revision: 262996
URL: http://llvm.org/viewvc/llvm-project?rev=262996&view=rev
Log:
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
Modified:
cfe/trunk/lib/Driver/ToolChain.cpp
cfe/trunk/test/Driver/fuse-ld.c
Modified: cfe/trunk/lib/Driver/ToolChain.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Driver/ToolChain.cpp?rev=262996&r1=262995&r2=262996&view=diff
==============================================================================
--- cfe/trunk/lib/Driver/ToolChain.cpp (original)
+++ cfe/trunk/lib/Driver/ToolChain.cpp Tue Mar 8 23:18:16 2016
@@ -342,19 +342,26 @@ std::string ToolChain::GetProgramPath(co
std::string ToolChain::GetLinkerPath() const {
if (Arg *A = Args.getLastArg(options::OPT_fuse_ld_EQ)) {
- StringRef Suffix = A->getValue();
+ StringRef UseLinker = 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");
+ 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(Suffix);
+ llvm::SmallString<8> LinkerName("ld.");
+ LinkerName.append(UseLinker);
- std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
- if (llvm::sys::fs::exists(LinkerPath))
- return LinkerPath;
+ 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 "";
Modified: cfe/trunk/test/Driver/fuse-ld.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Driver/fuse-ld.c?rev=262996&r1=262995&r2=262996&view=diff
==============================================================================
--- cfe/trunk/test/Driver/fuse-ld.c (original)
+++ cfe/trunk/test/Driver/fuse-ld.c Tue Mar 8 23:18:16 2016
@@ -1,4 +1,10 @@
// RUN: %clang %s -### \
+// RUN: -fuse-ld=/usr/local/bin/or1k-linux-ld 2>&1 \
+// RUN: | FileCheck %s --check-prefix=CHECK-ABSOLUTE-LD
+// CHECK-ABSOLUTE-LD: /usr/local/bin/or1k-linux-ld
+
+
+// RUN: %clang %s -### \
// RUN: -target x86_64-unknown-freebsd 2>&1 \
// RUN: | FileCheck %s --check-prefix=CHECK-FREEBSD-LD
// CHECK-FREEBSD-LD: ld
More information about the cfe-commits
mailing list