@@ -51,13 +51,13 @@ toolchains::GenericUnix::constructInvocation(const InterpretJobAction &job,
5151 const JobContext &context) const {
5252 InvocationInfo II = ToolChain::constructInvocation (job, context);
5353
54- SmallVector<std::string, 4 > runtimeLibraryPaths ;
55- getRuntimeLibraryPaths (runtimeLibraryPaths , context.Args , context. OI . SDKPath ,
56- /* Shared=*/ true );
54+ SmallString< 128 > runtimeLibraryPath ;
55+ getRuntimeLibraryPath (runtimeLibraryPath , context.Args ,
56+ /* Shared=*/ true );
5757
5858 addPathEnvironmentVariableIfNeeded (II.ExtraEnvironment , " LD_LIBRARY_PATH" ,
5959 " :" , options::OPT_L, context.Args ,
60- runtimeLibraryPaths );
60+ runtimeLibraryPath );
6161 return II;
6262}
6363
@@ -190,25 +190,24 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
190190 staticStdlib = true ;
191191 }
192192
193- SmallVector<std::string, 4 > RuntimeLibPaths;
194- getRuntimeLibraryPaths (RuntimeLibPaths, context.Args , context.OI .SDKPath ,
195- /* Shared=*/ !(staticExecutable || staticStdlib));
193+ SmallString<128 > SharedRuntimeLibPath;
194+ getRuntimeLibraryPath (SharedRuntimeLibPath, context.Args , /* Shared=*/ true );
196195
196+ SmallString<128 > StaticRuntimeLibPath;
197+ getRuntimeLibraryPath (StaticRuntimeLibPath, context.Args , /* Shared=*/ false );
198+
199+ // Add the runtime library link path, which is platform-specific and found
200+ // relative to the compiler.
197201 if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker ()) {
198202 // FIXME: We probably shouldn't be adding an rpath here unless we know
199203 // ahead of time the standard library won't be copied.
200- for (auto path : RuntimeLibPaths) {
201- Arguments.push_back (" -Xlinker" );
202- Arguments.push_back (" -rpath" );
203- Arguments.push_back (" -Xlinker" );
204- Arguments.push_back (context.Args .MakeArgString (path));
205- }
204+ Arguments.push_back (" -Xlinker" );
205+ Arguments.push_back (" -rpath" );
206+ Arguments.push_back (" -Xlinker" );
207+ Arguments.push_back (context.Args .MakeArgString (SharedRuntimeLibPath));
206208 }
207209
208- SmallString<128 > SharedResourceDirPath;
209- getResourceDirPath (SharedResourceDirPath, context.Args , /* Shared=*/ true );
210-
211- SmallString<128 > swiftrtPath = SharedResourceDirPath;
210+ SmallString<128 > swiftrtPath = SharedRuntimeLibPath;
212211 llvm::sys::path::append (swiftrtPath,
213212 swift::getMajorArchitectureName (getTriple ()));
214213 llvm::sys::path::append (swiftrtPath, " swiftrt.o" );
@@ -240,34 +239,36 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
240239 Twine (" @" ) + OutputInfo.getPrimaryOutputFilename ()));
241240 }
242241
243- // Add the runtime library link paths.
244- for (auto path : RuntimeLibPaths) {
245- Arguments.push_back (" -L" );
246- Arguments.push_back (context.Args .MakeArgString (path));
247- }
248-
249- // Link the standard library. In two paths, we do this using a .lnk file;
250- // if we're going that route, we'll set `linkFilePath` to the path to that
251- // file.
252- SmallString<128 > linkFilePath;
253- getResourceDirPath (linkFilePath, context.Args , /* Shared=*/ false );
242+ // Link the standard library.
243+ Arguments.push_back (" -L" );
254244
255245 if (staticExecutable) {
246+ Arguments.push_back (context.Args .MakeArgString (StaticRuntimeLibPath));
247+
248+ SmallString<128 > linkFilePath = StaticRuntimeLibPath;
256249 llvm::sys::path::append (linkFilePath, " static-executable-args.lnk" );
250+ auto linkFile = linkFilePath.str ();
251+
252+ if (llvm::sys::fs::is_regular_file (linkFile)) {
253+ Arguments.push_back (context.Args .MakeArgString (Twine (" @" ) + linkFile));
254+ } else {
255+ llvm::report_fatal_error (
256+ " -static-executable not supported on this platform" );
257+ }
257258 } else if (staticStdlib) {
258- llvm::sys::path::append (linkFilePath, " static-stdlib-args.lnk" );
259- } else {
260- linkFilePath.clear ();
261- Arguments.push_back (" -lswiftCore" );
262- }
259+ Arguments.push_back (context.Args .MakeArgString (StaticRuntimeLibPath));
263260
264- if (!linkFilePath.empty ()) {
261+ SmallString<128 > linkFilePath = StaticRuntimeLibPath;
262+ llvm::sys::path::append (linkFilePath, " static-stdlib-args.lnk" );
265263 auto linkFile = linkFilePath.str ();
266264 if (llvm::sys::fs::is_regular_file (linkFile)) {
267265 Arguments.push_back (context.Args .MakeArgString (Twine (" @" ) + linkFile));
268266 } else {
269267 llvm::report_fatal_error (linkFile + " not found" );
270268 }
269+ } else {
270+ Arguments.push_back (context.Args .MakeArgString (SharedRuntimeLibPath));
271+ Arguments.push_back (" -lswiftCore" );
271272 }
272273
273274 // Explicitly pass the target to the linker
@@ -288,7 +289,7 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
288289 }
289290
290291 if (context.Args .hasArg (options::OPT_profile_generate)) {
291- SmallString<128 > LibProfile (SharedResourceDirPath );
292+ SmallString<128 > LibProfile (SharedRuntimeLibPath );
292293 llvm::sys::path::remove_filename (LibProfile); // remove platform name
293294 llvm::sys::path::append (LibProfile, " clang" , " lib" );
294295
0 commit comments