@@ -51,13 +51,13 @@ toolchains::GenericUnix::constructInvocation(const InterpretJobAction &job,
5151 const JobContext &context) const {
5252 InvocationInfo II = ToolChain::constructInvocation (job, context);
5353
54- SmallString< 128 > runtimeLibraryPath ;
55- getRuntimeLibraryPath (runtimeLibraryPath , context.Args ,
56- /* Shared=*/ true );
54+ SmallVector<std::string, 4 > runtimeLibraryPaths ;
55+ getRuntimeLibraryPaths (runtimeLibraryPaths , context.Args , context. OI . SDKPath ,
56+ /* Shared=*/ true );
5757
5858 addPathEnvironmentVariableIfNeeded (II.ExtraEnvironment , " LD_LIBRARY_PATH" ,
5959 " :" , options::OPT_L, context.Args ,
60- runtimeLibraryPath );
60+ runtimeLibraryPaths );
6161 return II;
6262}
6363
@@ -190,24 +190,25 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
190190 staticStdlib = true ;
191191 }
192192
193- SmallString<128 > SharedRuntimeLibPath;
194- getRuntimeLibraryPath (SharedRuntimeLibPath, context.Args , /* Shared=*/ true );
193+ SmallVector<std::string, 4 > RuntimeLibPaths;
194+ getRuntimeLibraryPaths (RuntimeLibPaths, context.Args , context.OI .SDKPath ,
195+ /* Shared=*/ !(staticExecutable || staticStdlib));
195196
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.
201197 if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker ()) {
202198 // FIXME: We probably shouldn't be adding an rpath here unless we know
203199 // ahead of time the standard library won't be copied.
204- Arguments.push_back (" -Xlinker" );
205- Arguments.push_back (" -rpath" );
206- Arguments.push_back (" -Xlinker" );
207- Arguments.push_back (context.Args .MakeArgString (SharedRuntimeLibPath));
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+ }
208206 }
209207
210- SmallString<128 > swiftrtPath = SharedRuntimeLibPath;
208+ SmallString<128 > SharedResourceDirPath;
209+ getResourceDirPath (SharedResourceDirPath, context.Args , /* Shared=*/ true );
210+
211+ SmallString<128 > swiftrtPath = SharedResourceDirPath;
211212 llvm::sys::path::append (swiftrtPath,
212213 swift::getMajorArchitectureName (getTriple ()));
213214 llvm::sys::path::append (swiftrtPath, " swiftrt.o" );
@@ -239,36 +240,34 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
239240 Twine (" @" ) + OutputInfo.getPrimaryOutputFilename ()));
240241 }
241242
242- // Link the standard library.
243- Arguments.push_back (" -L" );
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+ }
244248
245- if (staticExecutable) {
246- Arguments.push_back (context.Args .MakeArgString (StaticRuntimeLibPath));
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 );
247254
248- SmallString< 128 > linkFilePath = StaticRuntimeLibPath;
255+ if (staticExecutable) {
249256 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- }
258257 } else if (staticStdlib) {
259- Arguments.push_back (context.Args .MakeArgString (StaticRuntimeLibPath));
260-
261- SmallString<128 > linkFilePath = StaticRuntimeLibPath;
262258 llvm::sys::path::append (linkFilePath, " static-stdlib-args.lnk" );
259+ } else {
260+ linkFilePath.clear ();
261+ Arguments.push_back (" -lswiftCore" );
262+ }
263+
264+ if (!linkFilePath.empty ()) {
263265 auto linkFile = linkFilePath.str ();
264266 if (llvm::sys::fs::is_regular_file (linkFile)) {
265267 Arguments.push_back (context.Args .MakeArgString (Twine (" @" ) + linkFile));
266268 } else {
267269 llvm::report_fatal_error (linkFile + " not found" );
268270 }
269- } else {
270- Arguments.push_back (context.Args .MakeArgString (SharedRuntimeLibPath));
271- Arguments.push_back (" -lswiftCore" );
272271 }
273272
274273 // Explicitly pass the target to the linker
@@ -289,7 +288,7 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
289288 }
290289
291290 if (context.Args .hasArg (options::OPT_profile_generate)) {
292- SmallString<128 > LibProfile (SharedRuntimeLibPath );
291+ SmallString<128 > LibProfile (SharedResourceDirPath );
293292 llvm::sys::path::remove_filename (LibProfile); // remove platform name
294293 llvm::sys::path::append (LibProfile, " clang" , " lib" );
295294
0 commit comments