@@ -51,13 +51,13 @@ toolchains::GenericUnix::constructInvocation(const InterpretJobAction &job,
51
51
const JobContext &context) const {
52
52
InvocationInfo II = ToolChain::constructInvocation (job, context);
53
53
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 );
57
57
58
58
addPathEnvironmentVariableIfNeeded (II.ExtraEnvironment , " LD_LIBRARY_PATH" ,
59
59
" :" , options::OPT_L, context.Args ,
60
- runtimeLibraryPath );
60
+ runtimeLibraryPaths );
61
61
return II;
62
62
}
63
63
@@ -190,24 +190,25 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
190
190
staticStdlib = true ;
191
191
}
192
192
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));
195
196
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.
201
197
if (!(staticExecutable || staticStdlib) && shouldProvideRPathToLinker ()) {
202
198
// FIXME: We probably shouldn't be adding an rpath here unless we know
203
199
// 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
+ }
208
206
}
209
207
210
- SmallString<128 > swiftrtPath = SharedRuntimeLibPath;
208
+ SmallString<128 > SharedResourceDirPath;
209
+ getResourceDirPath (SharedResourceDirPath, context.Args , /* Shared=*/ true );
210
+
211
+ SmallString<128 > swiftrtPath = SharedResourceDirPath;
211
212
llvm::sys::path::append (swiftrtPath,
212
213
swift::getMajorArchitectureName (getTriple ()));
213
214
llvm::sys::path::append (swiftrtPath, " swiftrt.o" );
@@ -239,36 +240,34 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
239
240
Twine (" @" ) + OutputInfo.getPrimaryOutputFilename ()));
240
241
}
241
242
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
+ }
244
248
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 );
247
254
248
- SmallString< 128 > linkFilePath = StaticRuntimeLibPath;
255
+ if (staticExecutable) {
249
256
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
- }
258
257
} else if (staticStdlib) {
259
- Arguments.push_back (context.Args .MakeArgString (StaticRuntimeLibPath));
260
-
261
- SmallString<128 > linkFilePath = StaticRuntimeLibPath;
262
258
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 ()) {
263
265
auto linkFile = linkFilePath.str ();
264
266
if (llvm::sys::fs::is_regular_file (linkFile)) {
265
267
Arguments.push_back (context.Args .MakeArgString (Twine (" @" ) + linkFile));
266
268
} else {
267
269
llvm::report_fatal_error (linkFile + " not found" );
268
270
}
269
- } else {
270
- Arguments.push_back (context.Args .MakeArgString (SharedRuntimeLibPath));
271
- Arguments.push_back (" -lswiftCore" );
272
271
}
273
272
274
273
// Explicitly pass the target to the linker
@@ -289,7 +288,7 @@ toolchains::GenericUnix::constructInvocation(const DynamicLinkJobAction &job,
289
288
}
290
289
291
290
if (context.Args .hasArg (options::OPT_profile_generate)) {
292
- SmallString<128 > LibProfile (SharedRuntimeLibPath );
291
+ SmallString<128 > LibProfile (SharedResourceDirPath );
293
292
llvm::sys::path::remove_filename (LibProfile); // remove platform name
294
293
llvm::sys::path::append (LibProfile, " clang" , " lib" );
295
294
0 commit comments