@@ -951,7 +951,19 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
951
951
const Driver &D = getDriver ();
952
952
const llvm::Triple &Triple = getTriple ();
953
953
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};
955
967
ArgStringList &Arguments = II.Arguments ;
956
968
957
969
if (context.Args .hasArg (options::OPT_driver_use_filelists) ||
@@ -1269,14 +1281,14 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
1269
1281
case LinkKind::None:
1270
1282
llvm_unreachable (" invalid link kind" );
1271
1283
case LinkKind::Executable:
1272
- // Default case, nothing extra needed
1284
+ // Default case, nothing extra needed.
1273
1285
break ;
1274
1286
case LinkKind::DynamicLibrary:
1275
1287
Arguments.push_back (" -shared" );
1276
1288
break ;
1277
1289
}
1278
1290
1279
- // Select the linker to use
1291
+ // Select the linker to use.
1280
1292
std::string Linker;
1281
1293
if (const Arg *A = context.Args .getLastArg (options::OPT_use_ld)) {
1282
1294
Linker = A->getValue ();
@@ -1287,6 +1299,22 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
1287
1299
Arguments.push_back (context.Args .MakeArgString (" -fuse-ld=" + Linker));
1288
1300
}
1289
1301
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
+
1290
1318
std::string Target = getTargetForLinker ();
1291
1319
if (!Target.empty ()) {
1292
1320
Arguments.push_back (" -target" );
@@ -1393,7 +1421,7 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
1393
1421
Arguments.push_back (" -o" );
1394
1422
Arguments.push_back (context.Output .getPrimaryOutputFilename ().c_str ());
1395
1423
1396
- return {" clang++ " , Arguments};
1424
+ return {Clang , Arguments};
1397
1425
}
1398
1426
1399
1427
std::string
0 commit comments