Skip to content

Commit dc6441b

Browse files
committed
---
yaml --- r: 314271 b: refs/heads/rxwei-patch-6 c: 05903b5 h: refs/heads/master i: 314269: bcd937d 314267: 8f1d373 314263: 98ca29f 314255: a7671dd 314239: 20049fc
1 parent 4e40065 commit dc6441b

File tree

3 files changed

+117
-104
lines changed

3 files changed

+117
-104
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1422,7 +1422,7 @@ refs/heads/remove-AlignedCharArray: a09ee8660ce66898d5a5a04e2adb4a5ecf1c4644
14221422
refs/heads/revert-25193-gsoc-2019-parser: c66a8be4eb8cea9e606bcbfce52820ad02f23413
14231423
refs/heads/revert-25911-revert-25766-reenable-test-tsan-norace-deinit: 0f330b25b83d3c83ce993f535d4a83bb626aafa3
14241424
refs/heads/revert-26183-rename-adjoint-to-pullback: b16bd9f4bc54ae8ec31f412ac542dcf6f522d9ee
1425-
refs/heads/rxwei-patch-6: 27650113538da5a07d80b665036b79569eec862c
1425+
refs/heads/rxwei-patch-6: 05903b593cf9a03e089c0acf10869908cb805950
14261426
refs/heads/shahmishal-patch-3: f3e0bc73927d564bb35354dc6473a1981f2a864e
14271427
refs/heads/shahmishal/pr-swiftsyntax-test: 64ff140a6dfa78ecea27eeb6d29582650198f3e0
14281428
refs/heads/test-libdispatch-preset-on-swift-5.1-branch: 2ab0acdec00ee31d21490154081c3001648a8b85

branches/rxwei-patch-6/lib/Driver/DarwinToolChains.cpp

Lines changed: 111 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,116 @@ static void findARCLiteLibPath(const toolchains::Darwin &TC,
245245
}
246246
}
247247

248+
void
249+
toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments,
250+
const DynamicLinkJobAction &job,
251+
const JobContext &context) const {
252+
253+
// Link compatibility libraries, if we're deploying back to OSes that
254+
// have an older Swift runtime.
255+
SmallString<128> SharedResourceDirPath;
256+
getResourceDirPath(SharedResourceDirPath, context.Args, /*Shared=*/true);
257+
Optional<llvm::VersionTuple> runtimeCompatibilityVersion;
258+
259+
if (context.Args.hasArg(options::OPT_runtime_compatibility_version)) {
260+
auto value = context.Args.getLastArgValue(
261+
options::OPT_runtime_compatibility_version);
262+
if (value.equals("5.0")) {
263+
runtimeCompatibilityVersion = llvm::VersionTuple(5, 0);
264+
} else if (value.equals("none")) {
265+
runtimeCompatibilityVersion = None;
266+
} else {
267+
// TODO: diagnose unknown runtime compatibility version?
268+
}
269+
} else if (job.getKind() == LinkKind::Executable) {
270+
runtimeCompatibilityVersion
271+
= getSwiftRuntimeCompatibilityVersionForTarget(getTriple());
272+
}
273+
274+
if (runtimeCompatibilityVersion) {
275+
if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) {
276+
// Swift 5.0 compatibility library
277+
SmallString<128> BackDeployLib;
278+
BackDeployLib.append(SharedResourceDirPath);
279+
llvm::sys::path::append(BackDeployLib, "libswiftCompatibility50.a");
280+
281+
if (llvm::sys::fs::exists(BackDeployLib)) {
282+
Arguments.push_back("-force_load");
283+
Arguments.push_back(context.Args.MakeArgString(BackDeployLib));
284+
}
285+
}
286+
}
287+
288+
if (job.getKind() == LinkKind::Executable) {
289+
if (runtimeCompatibilityVersion)
290+
if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) {
291+
// Swift 5.0 dynamic replacement compatibility library.
292+
SmallString<128> BackDeployLib;
293+
BackDeployLib.append(SharedResourceDirPath);
294+
llvm::sys::path::append(BackDeployLib,
295+
"libswiftCompatibilityDynamicReplacements.a");
296+
297+
if (llvm::sys::fs::exists(BackDeployLib)) {
298+
Arguments.push_back("-force_load");
299+
Arguments.push_back(context.Args.MakeArgString(BackDeployLib));
300+
}
301+
}
302+
}
303+
304+
// Add the runtime library link path, which is platform-specific and found
305+
// relative to the compiler.
306+
SmallVector<std::string, 4> RuntimeLibPaths;
307+
getRuntimeLibraryPaths(RuntimeLibPaths, context.Args,
308+
context.OI.SDKPath, /*Shared=*/true);
309+
310+
for (auto path : RuntimeLibPaths) {
311+
Arguments.push_back("-L");
312+
Arguments.push_back(context.Args.MakeArgString(path));
313+
}
314+
315+
if (context.Args.hasArg(options::OPT_toolchain_stdlib_rpath)) {
316+
// If the user has explicitly asked for a toolchain stdlib, we should
317+
// provide one using -rpath. This used to be the default behaviour but it
318+
// was considered annoying in at least the SwiftPM scenario (see
319+
// https://bugs.swift.org/browse/SR-1967) and is obsolete in all scenarios
320+
// of deploying for Swift-in-the-OS. We keep it here as an optional
321+
// behaviour so that people downloading snapshot toolchains for testing new
322+
// stdlibs will be able to link to the stdlib bundled in that toolchain.
323+
for (auto path : RuntimeLibPaths) {
324+
Arguments.push_back("-rpath");
325+
Arguments.push_back(context.Args.MakeArgString(path));
326+
}
327+
} else if (tripleHasSwiftInTheOS(getTriple()) ||
328+
context.Args.hasArg(options::OPT_no_stdlib_rpath)) {
329+
// If targeting an OS with Swift in /usr/lib/swift, the LC_ID_DYLIB
330+
// install_name the stdlib will be an absolute path like
331+
// /usr/lib/swift/libswiftCore.dylib, and we do not need to provide an rpath
332+
// at all.
333+
//
334+
// Also, if the user explicitly asks for no rpath entry, we assume they know
335+
// what they're doing and do not add one here.
336+
} else {
337+
// The remaining cases are back-deploying (to OSs predating
338+
// Swift-in-the-OS). In these cases, the stdlib will be giving us (via
339+
// stdlib/linker-support/magic-symbols-for-install-name.c) an LC_ID_DYLIB
340+
// install_name that is rpath-relative, like @rpath/libswiftCore.dylib.
341+
//
342+
// If we're linking an app bundle, it's possible there's an embedded stdlib
343+
// in there, in which case we'd want to put @executable_path/../Frameworks
344+
// in the rpath to find and prefer it, but (a) we don't know when we're
345+
// linking an app bundle and (b) we probably _never_ will be because Xcode
346+
// links using clang, not the swift driver.
347+
//
348+
// So that leaves us with the case of linking a command-line app. These are
349+
// only supported by installing a secondary package that puts some frozen
350+
// Swift-in-OS libraries in the /usr/lib/swift location. That's the best we
351+
// can give for rpath, though it might fail at runtime if the support
352+
// package isn't installed.
353+
Arguments.push_back("-rpath");
354+
Arguments.push_back(context.Args.MakeArgString("/usr/lib/swift"));
355+
}
356+
}
357+
248358
ToolChain::InvocationInfo
249359
toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
250360
const JobContext &context) const {
@@ -396,109 +506,7 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
396506
Arguments.push_back("-arch");
397507
Arguments.push_back(context.Args.MakeArgString(getTriple().getArchName()));
398508

399-
// Link compatibility libraries, if we're deploying back to OSes that
400-
// have an older Swift runtime.
401-
SmallString<128> SharedResourceDirPath;
402-
getResourceDirPath(SharedResourceDirPath, context.Args, /*Shared=*/true);
403-
Optional<llvm::VersionTuple> runtimeCompatibilityVersion;
404-
405-
if (context.Args.hasArg(options::OPT_runtime_compatibility_version)) {
406-
auto value = context.Args.getLastArgValue(
407-
options::OPT_runtime_compatibility_version);
408-
if (value.equals("5.0")) {
409-
runtimeCompatibilityVersion = llvm::VersionTuple(5, 0);
410-
} else if (value.equals("none")) {
411-
runtimeCompatibilityVersion = None;
412-
} else {
413-
// TODO: diagnose unknown runtime compatibility version?
414-
}
415-
} else if (job.getKind() == LinkKind::Executable) {
416-
runtimeCompatibilityVersion
417-
= getSwiftRuntimeCompatibilityVersionForTarget(Triple);
418-
}
419-
420-
if (runtimeCompatibilityVersion) {
421-
if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) {
422-
// Swift 5.0 compatibility library
423-
SmallString<128> BackDeployLib;
424-
BackDeployLib.append(SharedResourceDirPath);
425-
llvm::sys::path::append(BackDeployLib, "libswiftCompatibility50.a");
426-
427-
if (llvm::sys::fs::exists(BackDeployLib)) {
428-
Arguments.push_back("-force_load");
429-
Arguments.push_back(context.Args.MakeArgString(BackDeployLib));
430-
}
431-
}
432-
}
433-
434-
if (job.getKind() == LinkKind::Executable) {
435-
if (runtimeCompatibilityVersion)
436-
if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) {
437-
// Swift 5.0 dynamic replacement compatibility library.
438-
SmallString<128> BackDeployLib;
439-
BackDeployLib.append(SharedResourceDirPath);
440-
llvm::sys::path::append(BackDeployLib,
441-
"libswiftCompatibilityDynamicReplacements.a");
442-
443-
if (llvm::sys::fs::exists(BackDeployLib)) {
444-
Arguments.push_back("-force_load");
445-
Arguments.push_back(context.Args.MakeArgString(BackDeployLib));
446-
}
447-
}
448-
}
449-
450-
SmallVector<std::string, 4> RuntimeLibPaths;
451-
getRuntimeLibraryPaths(RuntimeLibPaths, context.Args,
452-
context.OI.SDKPath, /*Shared=*/true);
453-
454-
// Add the runtime library link path, which is platform-specific and found
455-
// relative to the compiler.
456-
for (auto path : RuntimeLibPaths) {
457-
Arguments.push_back("-L");
458-
Arguments.push_back(context.Args.MakeArgString(path));
459-
}
460-
461-
if (context.Args.hasArg(options::OPT_toolchain_stdlib_rpath)) {
462-
// If the user has explicitly asked for a toolchain stdlib, we should
463-
// provide one using -rpath. This used to be the default behaviour but it
464-
// was considered annoying in at least the SwiftPM scenario (see
465-
// https://bugs.swift.org/browse/SR-1967) and is obsolete in all scenarios
466-
// of deploying for Swift-in-the-OS. We keep it here as an optional
467-
// behaviour so that people downloading snapshot toolchains for testing new
468-
// stdlibs will be able to link to the stdlib bundled in that toolchain.
469-
for (auto path : RuntimeLibPaths) {
470-
Arguments.push_back("-rpath");
471-
Arguments.push_back(context.Args.MakeArgString(path));
472-
}
473-
} else if (tripleHasSwiftInTheOS(Triple) ||
474-
context.Args.hasArg(options::OPT_no_stdlib_rpath)) {
475-
// If targeting an OS with Swift in /usr/lib/swift, the LC_ID_DYLIB
476-
// install_name the stdlib will be an absolute path like
477-
// /usr/lib/swift/libswiftCore.dylib, and we do not need to provide an rpath
478-
// at all.
479-
//
480-
// Also, if the user explicitly asks for no rpath entry, we assume they know
481-
// what they're doing and do not add one here.
482-
} else {
483-
// The remaining cases are back-deploying (to OSs predating
484-
// Swift-in-the-OS). In these cases, the stdlib will be giving us (via
485-
// stdlib/linker-support/magic-symbols-for-install-name.c) an LC_ID_DYLIB
486-
// install_name that is rpath-relative, like @rpath/libswiftCore.dylib.
487-
//
488-
// If we're linking an app bundle, it's possible there's an embedded stdlib
489-
// in there, in which case we'd want to put @executable_path/../Frameworks
490-
// in the rpath to find and prefer it, but (a) we don't know when we're
491-
// linking an app bundle and (b) we probably _never_ will be because Xcode
492-
// links using clang, not the swift driver.
493-
//
494-
// So that leaves us with the case of linking a command-line app. These are
495-
// only supported by installing a secondary package that puts some frozen
496-
// Swift-in-OS libraries in the /usr/lib/swift location. That's the best we
497-
// can give for rpath, though it might fail at runtime if the support
498-
// package isn't installed.
499-
Arguments.push_back("-rpath");
500-
Arguments.push_back(context.Args.MakeArgString("/usr/lib/swift"));
501-
}
509+
addArgsToLinkStdlib(Arguments, job, context);
502510

503511
if (context.Args.hasArg(options::OPT_profile_generate)) {
504512
SmallString<128> LibProfile;

branches/rxwei-patch-6/lib/Driver/ToolChains.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ namespace toolchains {
2626

2727
class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
2828
protected:
29+
30+
void addArgsToLinkStdlib(llvm::opt::ArgStringList &Arguments,
31+
const DynamicLinkJobAction &job,
32+
const JobContext &context) const;
33+
2934
InvocationInfo constructInvocation(const InterpretJobAction &job,
3035
const JobContext &context) const override;
3136
InvocationInfo constructInvocation(const DynamicLinkJobAction &job,

0 commit comments

Comments
 (0)