Skip to content

Commit b8b3144

Browse files
authored
Merge pull request #15388 from lanza/merge-grlp
2 parents 3dfd737 + 21f7d87 commit b8b3144

File tree

1 file changed

+11
-32
lines changed

1 file changed

+11
-32
lines changed

lib/Driver/ToolChains.cpp

Lines changed: 11 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1061,7 +1061,8 @@ static void addPathEnvironmentVariableIfNeeded(Job::EnvironmentVector &env,
10611061
/// relative to the compiler.
10621062
static void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
10631063
const llvm::opt::ArgList &args,
1064-
const ToolChain &TC) {
1064+
const ToolChain &TC,
1065+
bool shared) {
10651066
// FIXME: Duplicated from CompilerInvocation, but in theory the runtime
10661067
// library link path and the standard library module import path don't
10671068
// need to be the same.
@@ -1073,7 +1074,7 @@ static void getRuntimeLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
10731074
runtimeLibPath.append(programPath.begin(), programPath.end());
10741075
llvm::sys::path::remove_filename(runtimeLibPath); // remove /swift
10751076
llvm::sys::path::remove_filename(runtimeLibPath); // remove /bin
1076-
llvm::sys::path::append(runtimeLibPath, "lib", "swift");
1077+
llvm::sys::path::append(runtimeLibPath, "lib", shared ? "swift" : "swift_static");
10771078
}
10781079
llvm::sys::path::append(runtimeLibPath,
10791080
getPlatformNameForTriple(TC.getTriple()));
@@ -1083,43 +1084,21 @@ static void getClangLibraryPath(const ToolChain &TC, const ArgList &Args,
10831084
SmallString<128> &LibPath) {
10841085
const llvm::Triple &T = TC.getTriple();
10851086

1086-
getRuntimeLibraryPath(LibPath, Args, TC);
1087+
getRuntimeLibraryPath(LibPath, Args, TC, /*Shared=*/ true);
10871088
// Remove platform name.
10881089
llvm::sys::path::remove_filename(LibPath);
10891090
llvm::sys::path::append(LibPath, "clang", "lib",
10901091
T.isOSDarwin() ? "darwin"
10911092
: getPlatformNameForTriple(T));
10921093
}
10931094

1094-
/// Get the runtime library link path for static linking,
1095-
/// which is platform-specific and found relative to the compiler.
1096-
static void getRuntimeStaticLibraryPath(SmallVectorImpl<char> &runtimeLibPath,
1097-
const llvm::opt::ArgList &args,
1098-
const ToolChain &TC) {
1099-
// FIXME: Duplicated from CompilerInvocation, but in theory the runtime
1100-
// library link path and the standard library module import path don't
1101-
// need to be the same.
1102-
if (const Arg *A = args.getLastArg(options::OPT_resource_dir)) {
1103-
StringRef value = A->getValue();
1104-
runtimeLibPath.append(value.begin(), value.end());
1105-
} else {
1106-
auto programPath = TC.getDriver().getSwiftProgramPath();
1107-
runtimeLibPath.append(programPath.begin(), programPath.end());
1108-
llvm::sys::path::remove_filename(runtimeLibPath); // remove /swift
1109-
llvm::sys::path::remove_filename(runtimeLibPath); // remove /bin
1110-
llvm::sys::path::append(runtimeLibPath, "lib", "swift_static");
1111-
}
1112-
llvm::sys::path::append(runtimeLibPath,
1113-
getPlatformNameForTriple(TC.getTriple()));
1114-
}
1115-
11161095
ToolChain::InvocationInfo
11171096
toolchains::Darwin::constructInvocation(const InterpretJobAction &job,
11181097
const JobContext &context) const {
11191098
InvocationInfo II = ToolChain::constructInvocation(job, context);
11201099

11211100
SmallString<128> runtimeLibraryPath;
1122-
getRuntimeLibraryPath(runtimeLibraryPath, context.Args, *this);
1101+
getRuntimeLibraryPath(runtimeLibraryPath, context.Args, *this, /*Shared=*/ true);
11231102

11241103
addPathEnvironmentVariableIfNeeded(II.ExtraEnvironment, "DYLD_LIBRARY_PATH",
11251104
":", options::OPT_L, context.Args,
@@ -1224,7 +1203,7 @@ addLinkRuntimeLibForLinux(const ArgList &Args, ArgStringList &Arguments,
12241203
StringRef LinuxLibName,
12251204
const ToolChain &TC) {
12261205
SmallString<128> Dir;
1227-
getRuntimeLibraryPath(Dir, Args, TC);
1206+
getRuntimeLibraryPath(Dir, Args, TC, /*Shared=*/ true);
12281207
// Remove platform name.
12291208
llvm::sys::path::remove_filename(Dir);
12301209
llvm::sys::path::append(Dir, "clang", "lib", "linux");
@@ -1432,15 +1411,15 @@ toolchains::Darwin::constructInvocation(const LinkJobAction &job,
14321411
// Add the runtime library link path, which is platform-specific and found
14331412
// relative to the compiler.
14341413
SmallString<128> RuntimeLibPath;
1435-
getRuntimeLibraryPath(RuntimeLibPath, context.Args, *this);
1414+
getRuntimeLibraryPath(RuntimeLibPath, context.Args, *this, /*Shared=*/ true);
14361415

14371416
// Link the standard library.
14381417
Arguments.push_back("-L");
14391418
if (context.Args.hasFlag(options::OPT_static_stdlib,
14401419
options::OPT_no_static_stdlib,
14411420
false)) {
14421421
SmallString<128> StaticRuntimeLibPath;
1443-
getRuntimeStaticLibraryPath(StaticRuntimeLibPath, context.Args, *this);
1422+
getRuntimeLibraryPath(StaticRuntimeLibPath, context.Args, *this, /*Shared=*/ false);
14441423
Arguments.push_back(context.Args.MakeArgString(StaticRuntimeLibPath));
14451424
Arguments.push_back("-lc++");
14461425
Arguments.push_back("-framework");
@@ -1539,7 +1518,7 @@ toolchains::GenericUnix::constructInvocation(const InterpretJobAction &job,
15391518
InvocationInfo II = ToolChain::constructInvocation(job, context);
15401519

15411520
SmallString<128> runtimeLibraryPath;
1542-
getRuntimeLibraryPath(runtimeLibraryPath, context.Args, *this);
1521+
getRuntimeLibraryPath(runtimeLibraryPath, context.Args, *this, /*Shared=*/ true);
15431522

15441523
addPathEnvironmentVariableIfNeeded(II.ExtraEnvironment, "LD_LIBRARY_PATH",
15451524
":", options::OPT_L, context.Args,
@@ -1673,10 +1652,10 @@ toolchains::GenericUnix::constructInvocation(const LinkJobAction &job,
16731652
}
16741653

16751654
SmallString<128> SharedRuntimeLibPath;
1676-
getRuntimeLibraryPath(SharedRuntimeLibPath, context.Args, *this);
1655+
getRuntimeLibraryPath(SharedRuntimeLibPath, context.Args, *this, /*Shared=*/ true);
16771656

16781657
SmallString<128> StaticRuntimeLibPath;
1679-
getRuntimeStaticLibraryPath(StaticRuntimeLibPath, context.Args, *this);
1658+
getRuntimeLibraryPath(StaticRuntimeLibPath, context.Args, *this, /*Shared=*/ false);
16801659

16811660
// Add the runtime library link path, which is platform-specific and found
16821661
// relative to the compiler.

0 commit comments

Comments
 (0)