Skip to content

Commit 15a0dea

Browse files
committed
[clang] recognize any *-ld.lld variant
If we create a cross toolchain with a ${triple}-ld.lld symlink, clang finds that symlink and when it uses it, it's not recognized as "lld". Let's resolve that symlink and consider it when determining lld-ness. For example, clang provides hexagon-link specific link arguments such as `-mcpu=hexagonv65` and `-march=hexagon` when hexagon-unknown-linux-musl-ld.lld is found. lld rejects this with the following error: hexagon-unknown-linux-musl-ld.lld: error: unknown emulation: cpu=hexagonv65
1 parent ce66b56 commit 15a0dea

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

clang/lib/Driver/ToolChain.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const {
964964
StringRef UseLinker = A ? A->getValue() : CLANG_DEFAULT_LINKER;
965965

966966
// --ld-path= takes precedence over -fuse-ld= and specifies the executable
967-
// name. -B, COMPILER_PATH and PATH and consulted if the value does not
967+
// name. -B, COMPILER_PATH and PATH are consulted if the value does not
968968
// contain a path component separator.
969969
// -fuse-ld=lld can be used with --ld-path= to inform clang that the binary
970970
// that --ld-path= points to is lld.
@@ -974,8 +974,11 @@ std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const {
974974
if (llvm::sys::path::parent_path(Path).empty())
975975
Path = GetProgramPath(A->getValue());
976976
if (llvm::sys::fs::can_execute(Path)) {
977+
SmallString<256> RealPath;
978+
if (llvm::sys::fs::real_path(Path, RealPath))
979+
RealPath = llvm::sys::path::stem(RealPath);
977980
if (LinkerIsLLD)
978-
*LinkerIsLLD = UseLinker == "lld";
981+
*LinkerIsLLD = UseLinker == "lld" || RealPath == "lld";
979982
return std::string(Path);
980983
}
981984
}
@@ -1014,8 +1017,11 @@ std::string ToolChain::GetLinkerPath(bool *LinkerIsLLD) const {
10141017

10151018
std::string LinkerPath(GetProgramPath(LinkerName.c_str()));
10161019
if (llvm::sys::fs::can_execute(LinkerPath)) {
1020+
SmallString<256> RealPath;
1021+
if (llvm::sys::fs::real_path(LinkerPath, RealPath))
1022+
RealPath = llvm::sys::path::stem(RealPath);
10171023
if (LinkerIsLLD)
1018-
*LinkerIsLLD = UseLinker == "lld";
1024+
*LinkerIsLLD = UseLinker == "lld" || RealPath == "lld";
10191025
return LinkerPath;
10201026
}
10211027
}

clang/lib/Driver/ToolChains/Hexagon.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,11 @@ constructHexagonLinkArgs(Compilation &C, const JobAction &JA,
294294
bool IncStartFiles = !Args.hasArg(options::OPT_nostartfiles);
295295
bool IncDefLibs = !Args.hasArg(options::OPT_nodefaultlibs);
296296
bool UseG0 = false;
297-
const char *Exec = Args.MakeArgString(HTC.GetLinkerPath());
298-
bool UseLLD = (llvm::sys::path::filename(Exec).equals_insensitive("ld.lld") ||
299-
llvm::sys::path::stem(Exec).equals_insensitive("ld.lld"));
297+
bool UseLLD = false;
298+
const char *Exec = Args.MakeArgString(HTC.GetLinkerPath(&UseLLD));
299+
UseLLD = UseLLD ||
300+
llvm::sys::path::filename(Exec).equals_insensitive("ld.lld") ||
301+
llvm::sys::path::stem(Exec).equals_insensitive("ld.lld");
300302
bool UseShared = IsShared && !IsStatic;
301303
StringRef CpuVer = toolchains::HexagonToolChain::GetTargetCPUVersion(Args);
302304

0 commit comments

Comments
 (0)