@@ -951,7 +951,19 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
951951 const Driver &D = getDriver ();
952952 const llvm::Triple &Triple = getTriple ();
953953
954- InvocationInfo II{" ld" };
954+ // Configure the toolchain.
955+ // By default, use the system `ld` to link.
956+ const char *LD = " ld" ;
957+ if (const Arg *A = context.Args .getLastArg (options::OPT_tools_directory)) {
958+ StringRef toolchainPath (A->getValue ());
959+
960+ // If there is a 'ld' in the toolchain folder, use that instead.
961+ if (auto toolchainLD = llvm::sys::findProgramByName (" ld" , {toolchainPath})) {
962+ LD = context.Args .MakeArgString (toolchainLD.get ());
963+ }
964+ }
965+
966+ InvocationInfo II = {LD};
955967 ArgStringList &Arguments = II.Arguments ;
956968
957969 if (context.Args .hasArg (options::OPT_driver_use_filelists) ||
@@ -1269,14 +1281,14 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
12691281 case LinkKind::None:
12701282 llvm_unreachable (" invalid link kind" );
12711283 case LinkKind::Executable:
1272- // Default case, nothing extra needed
1284+ // Default case, nothing extra needed.
12731285 break ;
12741286 case LinkKind::DynamicLibrary:
12751287 Arguments.push_back (" -shared" );
12761288 break ;
12771289 }
12781290
1279- // Select the linker to use
1291+ // Select the linker to use.
12801292 std::string Linker;
12811293 if (const Arg *A = context.Args .getLastArg (options::OPT_use_ld)) {
12821294 Linker = A->getValue ();
@@ -1287,6 +1299,22 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
12871299 Arguments.push_back (context.Args .MakeArgString (" -fuse-ld=" + Linker));
12881300 }
12891301
1302+ // Configure the toolchain.
1303+ // By default, use the system clang++ to link.
1304+ const char * Clang = " clang++" ;
1305+ if (const Arg *A = context.Args .getLastArg (options::OPT_tools_directory)) {
1306+ StringRef toolchainPath (A->getValue ());
1307+
1308+ // If there is a clang in the toolchain folder, use that instead.
1309+ if (auto toolchainClang = llvm::sys::findProgramByName (" clang++" , {toolchainPath})) {
1310+ Clang = context.Args .MakeArgString (toolchainClang.get ());
1311+ }
1312+
1313+ // Look for binutils in the toolchain folder.
1314+ Arguments.push_back (" -B" );
1315+ Arguments.push_back (context.Args .MakeArgString (A->getValue ()));
1316+ }
1317+
12901318 std::string Target = getTargetForLinker ();
12911319 if (!Target.empty ()) {
12921320 Arguments.push_back (" -target" );
@@ -1393,7 +1421,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
13931421 Arguments.push_back (" -o" );
13941422 Arguments.push_back (context.Output .getPrimaryOutputFilename ().c_str ());
13951423
1396- return {" clang++ " , Arguments};
1424+ return {Clang , Arguments};
13971425}
13981426
13991427std::string
0 commit comments