From c2556ebf7d882e9668a240c00244f2b95107785d Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 20 Nov 2018 19:17:09 -0800 Subject: [PATCH 01/12] Add swift::tripleHasSwiftInTheOS helper. --- include/swift/Basic/Platform.h | 4 ++++ lib/Basic/Platform.cpp | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/include/swift/Basic/Platform.h b/include/swift/Basic/Platform.h index 134b7a2cd43c6..8f355de3b3ba2 100644 --- a/include/swift/Basic/Platform.h +++ b/include/swift/Basic/Platform.h @@ -46,6 +46,10 @@ namespace swift { /// Return true if the given triple represents any simulator. bool tripleIsAnySimulator(const llvm::Triple &triple); + /// Returns true if the given triple represents an OS that ships with ABI-stable + /// swift libraries (eg. in /usr/lib/swift). + bool tripleHasSwiftInTheOS(const llvm::Triple &triple); + /// Returns the platform name for a given target triple. /// /// For example, the iOS simulator has the name "iphonesimulator", while real diff --git a/lib/Basic/Platform.cpp b/lib/Basic/Platform.cpp index 90bc7d52cc203..b01d82aeeedba 100644 --- a/lib/Basic/Platform.cpp +++ b/lib/Basic/Platform.cpp @@ -54,6 +54,25 @@ bool swift::tripleIsAnySimulator(const llvm::Triple &triple) { tripleIsAppleTVSimulator(triple); } + +bool swift::tripleHasSwiftInTheOS(const llvm::Triple &triple) { + unsigned major, minor, revision; + if (triple.isMacOSX()) { + triple.getMacOSXVersion(major, minor, revision); + return llvm::VersionTuple(major, minor, revision) >= + llvm::VersionTuple(10, 14, 4); + } else if (triple.isiOS()) { + triple.getiOSVersion(major, minor, revision); + return llvm::VersionTuple(major, minor, revision) >= + llvm::VersionTuple(12, 2); + } else if (triple.isWatchOS()) { + triple.getOSVersion(major, minor, revision); + return llvm::VersionTuple(major, minor, revision) >= + llvm::VersionTuple(5, 2); + } + return false; +} + DarwinPlatformKind swift::getDarwinPlatformKind(const llvm::Triple &triple) { if (triple.isiOS()) { if (triple.isTvOS()) { From 383a885b97797e478c80718068531ca0ee42b357 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 20 Nov 2018 20:58:04 -0800 Subject: [PATCH 02/12] Add -toolchain-stdlib-rpath and -no-stdlib-rpath. --- include/swift/Option/Options.td | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/swift/Option/Options.td b/include/swift/Option/Options.td index 9c9bdf5d8b99c..597ce4cfc5712 100644 --- a/include/swift/Option/Options.td +++ b/include/swift/Option/Options.td @@ -502,6 +502,12 @@ def static_stdlib: Flag<["-"], "static-stdlib">, def no_static_stdlib: Flag<["-"], "no-static-stdlib">, Flags<[HelpHidden,DoesNotAffectIncrementalBuild]>, HelpText<"Don't statically link the Swift standard library">; +def toolchain_stdlib_rpath: Flag<["-"], "toolchain-stdlib-rpath">, + Flags<[HelpHidden,DoesNotAffectIncrementalBuild]>, + HelpText<"Add an rpath entry for the toolchain's standard library, rather than the OS's">; +def no_stdlib_rpath: Flag<["-"], "no-stdlib-rpath">, + Flags<[HelpHidden,DoesNotAffectIncrementalBuild]>, + HelpText<"Don't add any rpath entries.">; def static_executable : Flag<["-"], "static-executable">, HelpText<"Statically link the executable">; From 27650113538da5a07d80b665036b79569eec862c Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 1 Aug 2019 14:18:38 -0700 Subject: [PATCH 03/12] Modify toolchains::Darwin linking logic to account for Swift-in-the-OS. Manual re-application of a patch by Graydon Hoare. --- lib/Driver/DarwinToolChains.cpp | 43 ++++++++++++++++++++++++++++++--- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index 0dc2bf7f22057..947fb226a53a9 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -458,11 +458,46 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, Arguments.push_back(context.Args.MakeArgString(path)); } - // FIXME: We probably shouldn't be adding an rpath here unless we know ahead - // of time the standard library won't be copied. SR-1967 - for (auto path : RuntimeLibPaths) { + if (context.Args.hasArg(options::OPT_toolchain_stdlib_rpath)) { + // If the user has explicitly asked for a toolchain stdlib, we should + // provide one using -rpath. This used to be the default behaviour but it + // was considered annoying in at least the SwiftPM scenario (see + // https://bugs.swift.org/browse/SR-1967) and is obsolete in all scenarios + // of deploying for Swift-in-the-OS. We keep it here as an optional + // behaviour so that people downloading snapshot toolchains for testing new + // stdlibs will be able to link to the stdlib bundled in that toolchain. + for (auto path : RuntimeLibPaths) { + Arguments.push_back("-rpath"); + Arguments.push_back(context.Args.MakeArgString(path)); + } + } else if (tripleHasSwiftInTheOS(Triple) || + context.Args.hasArg(options::OPT_no_stdlib_rpath)) { + // If targeting an OS with Swift in /usr/lib/swift, the LC_ID_DYLIB + // install_name the stdlib will be an absolute path like + // /usr/lib/swift/libswiftCore.dylib, and we do not need to provide an rpath + // at all. + // + // Also, if the user explicitly asks for no rpath entry, we assume they know + // what they're doing and do not add one here. + } else { + // The remaining cases are back-deploying (to OSs predating + // Swift-in-the-OS). In these cases, the stdlib will be giving us (via + // stdlib/linker-support/magic-symbols-for-install-name.c) an LC_ID_DYLIB + // install_name that is rpath-relative, like @rpath/libswiftCore.dylib. + // + // If we're linking an app bundle, it's possible there's an embedded stdlib + // in there, in which case we'd want to put @executable_path/../Frameworks + // in the rpath to find and prefer it, but (a) we don't know when we're + // linking an app bundle and (b) we probably _never_ will be because Xcode + // links using clang, not the swift driver. + // + // So that leaves us with the case of linking a command-line app. These are + // only supported by installing a secondary package that puts some frozen + // Swift-in-OS libraries in the /usr/lib/swift location. That's the best we + // can give for rpath, though it might fail at runtime if the support + // package isn't installed. Arguments.push_back("-rpath"); - Arguments.push_back(context.Args.MakeArgString(path)); + Arguments.push_back(context.Args.MakeArgString("/usr/lib/swift")); } if (context.Args.hasArg(options::OPT_profile_generate)) { From 05903b593cf9a03e089c0acf10869908cb805950 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 1 Aug 2019 14:45:27 -0700 Subject: [PATCH 04/12] Factor out toolchains::Darwin::addArgsToLinkStdlib. --- lib/Driver/DarwinToolChains.cpp | 214 +++++++++++++++++--------------- lib/Driver/ToolChains.h | 5 + 2 files changed, 116 insertions(+), 103 deletions(-) diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index 947fb226a53a9..af9d5d9fc2ee4 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -245,6 +245,116 @@ static void findARCLiteLibPath(const toolchains::Darwin &TC, } } +void +toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments, + const DynamicLinkJobAction &job, + const JobContext &context) const { + + // Link compatibility libraries, if we're deploying back to OSes that + // have an older Swift runtime. + SmallString<128> SharedResourceDirPath; + getResourceDirPath(SharedResourceDirPath, context.Args, /*Shared=*/true); + Optional runtimeCompatibilityVersion; + + if (context.Args.hasArg(options::OPT_runtime_compatibility_version)) { + auto value = context.Args.getLastArgValue( + options::OPT_runtime_compatibility_version); + if (value.equals("5.0")) { + runtimeCompatibilityVersion = llvm::VersionTuple(5, 0); + } else if (value.equals("none")) { + runtimeCompatibilityVersion = None; + } else { + // TODO: diagnose unknown runtime compatibility version? + } + } else if (job.getKind() == LinkKind::Executable) { + runtimeCompatibilityVersion + = getSwiftRuntimeCompatibilityVersionForTarget(getTriple()); + } + + if (runtimeCompatibilityVersion) { + if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) { + // Swift 5.0 compatibility library + SmallString<128> BackDeployLib; + BackDeployLib.append(SharedResourceDirPath); + llvm::sys::path::append(BackDeployLib, "libswiftCompatibility50.a"); + + if (llvm::sys::fs::exists(BackDeployLib)) { + Arguments.push_back("-force_load"); + Arguments.push_back(context.Args.MakeArgString(BackDeployLib)); + } + } + } + + if (job.getKind() == LinkKind::Executable) { + if (runtimeCompatibilityVersion) + if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) { + // Swift 5.0 dynamic replacement compatibility library. + SmallString<128> BackDeployLib; + BackDeployLib.append(SharedResourceDirPath); + llvm::sys::path::append(BackDeployLib, + "libswiftCompatibilityDynamicReplacements.a"); + + if (llvm::sys::fs::exists(BackDeployLib)) { + Arguments.push_back("-force_load"); + Arguments.push_back(context.Args.MakeArgString(BackDeployLib)); + } + } + } + + // Add the runtime library link path, which is platform-specific and found + // relative to the compiler. + SmallVector RuntimeLibPaths; + getRuntimeLibraryPaths(RuntimeLibPaths, context.Args, + context.OI.SDKPath, /*Shared=*/true); + + for (auto path : RuntimeLibPaths) { + Arguments.push_back("-L"); + Arguments.push_back(context.Args.MakeArgString(path)); + } + + if (context.Args.hasArg(options::OPT_toolchain_stdlib_rpath)) { + // If the user has explicitly asked for a toolchain stdlib, we should + // provide one using -rpath. This used to be the default behaviour but it + // was considered annoying in at least the SwiftPM scenario (see + // https://bugs.swift.org/browse/SR-1967) and is obsolete in all scenarios + // of deploying for Swift-in-the-OS. We keep it here as an optional + // behaviour so that people downloading snapshot toolchains for testing new + // stdlibs will be able to link to the stdlib bundled in that toolchain. + for (auto path : RuntimeLibPaths) { + Arguments.push_back("-rpath"); + Arguments.push_back(context.Args.MakeArgString(path)); + } + } else if (tripleHasSwiftInTheOS(getTriple()) || + context.Args.hasArg(options::OPT_no_stdlib_rpath)) { + // If targeting an OS with Swift in /usr/lib/swift, the LC_ID_DYLIB + // install_name the stdlib will be an absolute path like + // /usr/lib/swift/libswiftCore.dylib, and we do not need to provide an rpath + // at all. + // + // Also, if the user explicitly asks for no rpath entry, we assume they know + // what they're doing and do not add one here. + } else { + // The remaining cases are back-deploying (to OSs predating + // Swift-in-the-OS). In these cases, the stdlib will be giving us (via + // stdlib/linker-support/magic-symbols-for-install-name.c) an LC_ID_DYLIB + // install_name that is rpath-relative, like @rpath/libswiftCore.dylib. + // + // If we're linking an app bundle, it's possible there's an embedded stdlib + // in there, in which case we'd want to put @executable_path/../Frameworks + // in the rpath to find and prefer it, but (a) we don't know when we're + // linking an app bundle and (b) we probably _never_ will be because Xcode + // links using clang, not the swift driver. + // + // So that leaves us with the case of linking a command-line app. These are + // only supported by installing a secondary package that puts some frozen + // Swift-in-OS libraries in the /usr/lib/swift location. That's the best we + // can give for rpath, though it might fail at runtime if the support + // package isn't installed. + Arguments.push_back("-rpath"); + Arguments.push_back(context.Args.MakeArgString("/usr/lib/swift")); + } +} + ToolChain::InvocationInfo toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, const JobContext &context) const { @@ -396,109 +506,7 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, Arguments.push_back("-arch"); Arguments.push_back(context.Args.MakeArgString(getTriple().getArchName())); - // Link compatibility libraries, if we're deploying back to OSes that - // have an older Swift runtime. - SmallString<128> SharedResourceDirPath; - getResourceDirPath(SharedResourceDirPath, context.Args, /*Shared=*/true); - Optional runtimeCompatibilityVersion; - - if (context.Args.hasArg(options::OPT_runtime_compatibility_version)) { - auto value = context.Args.getLastArgValue( - options::OPT_runtime_compatibility_version); - if (value.equals("5.0")) { - runtimeCompatibilityVersion = llvm::VersionTuple(5, 0); - } else if (value.equals("none")) { - runtimeCompatibilityVersion = None; - } else { - // TODO: diagnose unknown runtime compatibility version? - } - } else if (job.getKind() == LinkKind::Executable) { - runtimeCompatibilityVersion - = getSwiftRuntimeCompatibilityVersionForTarget(Triple); - } - - if (runtimeCompatibilityVersion) { - if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) { - // Swift 5.0 compatibility library - SmallString<128> BackDeployLib; - BackDeployLib.append(SharedResourceDirPath); - llvm::sys::path::append(BackDeployLib, "libswiftCompatibility50.a"); - - if (llvm::sys::fs::exists(BackDeployLib)) { - Arguments.push_back("-force_load"); - Arguments.push_back(context.Args.MakeArgString(BackDeployLib)); - } - } - } - - if (job.getKind() == LinkKind::Executable) { - if (runtimeCompatibilityVersion) - if (*runtimeCompatibilityVersion <= llvm::VersionTuple(5, 0)) { - // Swift 5.0 dynamic replacement compatibility library. - SmallString<128> BackDeployLib; - BackDeployLib.append(SharedResourceDirPath); - llvm::sys::path::append(BackDeployLib, - "libswiftCompatibilityDynamicReplacements.a"); - - if (llvm::sys::fs::exists(BackDeployLib)) { - Arguments.push_back("-force_load"); - Arguments.push_back(context.Args.MakeArgString(BackDeployLib)); - } - } - } - - SmallVector RuntimeLibPaths; - getRuntimeLibraryPaths(RuntimeLibPaths, context.Args, - context.OI.SDKPath, /*Shared=*/true); - - // Add the runtime library link path, which is platform-specific and found - // relative to the compiler. - for (auto path : RuntimeLibPaths) { - Arguments.push_back("-L"); - Arguments.push_back(context.Args.MakeArgString(path)); - } - - if (context.Args.hasArg(options::OPT_toolchain_stdlib_rpath)) { - // If the user has explicitly asked for a toolchain stdlib, we should - // provide one using -rpath. This used to be the default behaviour but it - // was considered annoying in at least the SwiftPM scenario (see - // https://bugs.swift.org/browse/SR-1967) and is obsolete in all scenarios - // of deploying for Swift-in-the-OS. We keep it here as an optional - // behaviour so that people downloading snapshot toolchains for testing new - // stdlibs will be able to link to the stdlib bundled in that toolchain. - for (auto path : RuntimeLibPaths) { - Arguments.push_back("-rpath"); - Arguments.push_back(context.Args.MakeArgString(path)); - } - } else if (tripleHasSwiftInTheOS(Triple) || - context.Args.hasArg(options::OPT_no_stdlib_rpath)) { - // If targeting an OS with Swift in /usr/lib/swift, the LC_ID_DYLIB - // install_name the stdlib will be an absolute path like - // /usr/lib/swift/libswiftCore.dylib, and we do not need to provide an rpath - // at all. - // - // Also, if the user explicitly asks for no rpath entry, we assume they know - // what they're doing and do not add one here. - } else { - // The remaining cases are back-deploying (to OSs predating - // Swift-in-the-OS). In these cases, the stdlib will be giving us (via - // stdlib/linker-support/magic-symbols-for-install-name.c) an LC_ID_DYLIB - // install_name that is rpath-relative, like @rpath/libswiftCore.dylib. - // - // If we're linking an app bundle, it's possible there's an embedded stdlib - // in there, in which case we'd want to put @executable_path/../Frameworks - // in the rpath to find and prefer it, but (a) we don't know when we're - // linking an app bundle and (b) we probably _never_ will be because Xcode - // links using clang, not the swift driver. - // - // So that leaves us with the case of linking a command-line app. These are - // only supported by installing a secondary package that puts some frozen - // Swift-in-OS libraries in the /usr/lib/swift location. That's the best we - // can give for rpath, though it might fail at runtime if the support - // package isn't installed. - Arguments.push_back("-rpath"); - Arguments.push_back(context.Args.MakeArgString("/usr/lib/swift")); - } + addArgsToLinkStdlib(Arguments, job, context); if (context.Args.hasArg(options::OPT_profile_generate)) { SmallString<128> LibProfile; diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index b0d182923c4aa..9b4a7e6c24e26 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -26,6 +26,11 @@ namespace toolchains { class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain { protected: + + void addArgsToLinkStdlib(llvm::opt::ArgStringList &Arguments, + const DynamicLinkJobAction &job, + const JobContext &context) const; + InvocationInfo constructInvocation(const InterpretJobAction &job, const JobContext &context) const override; InvocationInfo constructInvocation(const DynamicLinkJobAction &job, From 7cc1b135e361365a176b3ee5a6a8b3b1f1870654 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 20 Nov 2018 21:18:01 -0800 Subject: [PATCH 05/12] Factor out toolchains::Darwin::addArgsToLinkARCLite. --- lib/Driver/DarwinToolChains.cpp | 45 +++++++++++++++++++-------------- lib/Driver/ToolChains.h | 3 +++ 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index af9d5d9fc2ee4..cd035b043b99b 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -245,6 +245,31 @@ static void findARCLiteLibPath(const toolchains::Darwin &TC, } } +void +toolchains::Darwin::addArgsToLinkARCLite(ArgStringList &Arguments, + const JobContext &context) const { + if (!context.Args.hasFlag(options::OPT_link_objc_runtime, + options::OPT_no_link_objc_runtime, + /*Default=*/wantsObjCRuntime(getTriple()))) + return; + + llvm::SmallString<128> ARCLiteLib; + findARCLiteLibPath(*this, ARCLiteLib); + + if (!ARCLiteLib.empty()) { + llvm::sys::path::append(ARCLiteLib, "libarclite_"); + ARCLiteLib += getPlatformNameForTriple(getTriple()); + ARCLiteLib += ".a"; + + Arguments.push_back("-force_load"); + Arguments.push_back(context.Args.MakeArgString(ARCLiteLib)); + + // Arclite depends on CoreFoundation. + Arguments.push_back("-framework"); + Arguments.push_back("CoreFoundation"); + } +} + void toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments, const DynamicLinkJobAction &job, @@ -440,25 +465,7 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, if (llvm::sys::fs::exists(CompilerRTPath)) Arguments.push_back(context.Args.MakeArgString(CompilerRTPath)); - if (context.Args.hasFlag(options::OPT_link_objc_runtime, - options::OPT_no_link_objc_runtime, - /*Default=*/wantsObjCRuntime(Triple))) { - llvm::SmallString<128> ARCLiteLib; - findARCLiteLibPath(*this, ARCLiteLib); - - if (!ARCLiteLib.empty()) { - llvm::sys::path::append(ARCLiteLib, "libarclite_"); - ARCLiteLib += getPlatformNameForTriple(Triple); - ARCLiteLib += ".a"; - - Arguments.push_back("-force_load"); - Arguments.push_back(context.Args.MakeArgString(ARCLiteLib)); - - // Arclite depends on CoreFoundation. - Arguments.push_back("-framework"); - Arguments.push_back("CoreFoundation"); - } - } + addArgsToLinkARCLite(Arguments, context); for (const Arg *arg : context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) { diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 9b4a7e6c24e26..0ee7bf0aaf432 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -27,6 +27,9 @@ namespace toolchains { class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain { protected: + void addArgsToLinkARCLite(llvm::opt::ArgStringList &Arguments, + const JobContext &context) const; + void addArgsToLinkStdlib(llvm::opt::ArgStringList &Arguments, const DynamicLinkJobAction &job, const JobContext &context) const; From 7953d59571ba1662c27dbbf9f83a3796c10b7724 Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 20 Nov 2018 21:22:51 -0800 Subject: [PATCH 06/12] Factor out toolchains::Darwin::addDeploymentTargetArgs. --- lib/Driver/DarwinToolChains.cpp | 71 ++++++++++++++++++--------------- lib/Driver/ToolChains.h | 3 ++ 2 files changed, 42 insertions(+), 32 deletions(-) diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index cd035b043b99b..3f87d181f97a7 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -380,6 +380,44 @@ toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments, } } +void +toolchains::Darwin::addDeploymentTargetArgs(ArgStringList &Arguments, + const JobContext &context) const { + const llvm::Triple &Triple = getTriple(); + // FIXME: Properly handle deployment targets. + assert(Triple.isiOS() || Triple.isWatchOS() || Triple.isMacOSX()); + if (Triple.isiOS()) { + bool isiOSSimulator = tripleIsiOSSimulator(Triple); + if (Triple.isTvOS()) { + if (isiOSSimulator) + Arguments.push_back("-tvos_simulator_version_min"); + else + Arguments.push_back("-tvos_version_min"); + } else { + if (isiOSSimulator) + Arguments.push_back("-ios_simulator_version_min"); + else + Arguments.push_back("-iphoneos_version_min"); + } + unsigned major, minor, micro; + Triple.getiOSVersion(major, minor, micro); + addVersionString(context.Args, Arguments, major, minor, micro); + } else if (Triple.isWatchOS()) { + if (tripleIsWatchSimulator(Triple)) + Arguments.push_back("-watchos_simulator_version_min"); + else + Arguments.push_back("-watchos_version_min"); + unsigned major, minor, micro; + Triple.getOSVersion(major, minor, micro); + addVersionString(context.Args, Arguments, major, minor, micro); + } else { + Arguments.push_back("-macosx_version_min"); + unsigned major, minor, micro; + Triple.getMacOSXVersion(major, minor, micro); + addVersionString(context.Args, Arguments, major, minor, micro); + } +} + ToolChain::InvocationInfo toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, const JobContext &context) const { @@ -549,38 +587,7 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, Arguments.push_back(context.Args.MakeArgString(LibProfile)); } - // FIXME: Properly handle deployment targets. - assert(Triple.isiOS() || Triple.isWatchOS() || Triple.isMacOSX()); - if (Triple.isiOS()) { - bool isiOSSimulator = tripleIsiOSSimulator(Triple); - if (Triple.isTvOS()) { - if (isiOSSimulator) - Arguments.push_back("-tvos_simulator_version_min"); - else - Arguments.push_back("-tvos_version_min"); - } else { - if (isiOSSimulator) - Arguments.push_back("-ios_simulator_version_min"); - else - Arguments.push_back("-iphoneos_version_min"); - } - unsigned major, minor, micro; - Triple.getiOSVersion(major, minor, micro); - addVersionString(context.Args, Arguments, major, minor, micro); - } else if (Triple.isWatchOS()) { - if (tripleIsWatchSimulator(Triple)) - Arguments.push_back("-watchos_simulator_version_min"); - else - Arguments.push_back("-watchos_version_min"); - unsigned major, minor, micro; - Triple.getOSVersion(major, minor, micro); - addVersionString(context.Args, Arguments, major, minor, micro); - } else { - Arguments.push_back("-macosx_version_min"); - unsigned major, minor, micro; - Triple.getMacOSXVersion(major, minor, micro); - addVersionString(context.Args, Arguments, major, minor, micro); - } + addDeploymentTargetArgs(Arguments, context); Arguments.push_back("-no_objc_category_merging"); diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 0ee7bf0aaf432..2e9c39f0ec7ec 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -34,6 +34,9 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain { const DynamicLinkJobAction &job, const JobContext &context) const; + void addDeploymentTargetArgs(llvm::opt::ArgStringList &Arguments, + const JobContext &context) const; + InvocationInfo constructInvocation(const InterpretJobAction &job, const JobContext &context) const override; InvocationInfo constructInvocation(const DynamicLinkJobAction &job, From 71dd7417bedafddf0933c2e968c71b2f898619ba Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 20 Nov 2018 21:27:09 -0800 Subject: [PATCH 07/12] Factor out toolchains::Darwin::addProfileGenerationArgs. --- lib/Driver/DarwinToolChains.cpp | 74 ++++++++++++++++++--------------- lib/Driver/ToolChains.h | 3 ++ 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index 3f87d181f97a7..0eb9743b89ccd 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -380,6 +380,45 @@ toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments, } } +void +toolchains::Darwin::addProfileGenerationArgs(ArgStringList &Arguments, + const JobContext &context) const { + const llvm::Triple &Triple = getTriple(); + if (context.Args.hasArg(options::OPT_profile_generate)) { + SmallString<128> LibProfile; + getClangLibraryPath(context.Args, LibProfile); + + StringRef RT; + if (Triple.isiOS()) { + if (Triple.isTvOS()) + RT = "tvos"; + else + RT = "ios"; + } else if (Triple.isWatchOS()) { + RT = "watchos"; + } else { + assert(Triple.isMacOSX()); + RT = "osx"; + } + + StringRef Sim; + if (tripleIsAnySimulator(Triple)) { + Sim = "sim"; + } + + llvm::sys::path::append(LibProfile, + "libclang_rt.profile_" + RT + Sim + ".a"); + + // FIXME: Continue accepting the old path for simulator libraries for now. + if (!Sim.empty() && !llvm::sys::fs::exists(LibProfile)) { + llvm::sys::path::remove_filename(LibProfile); + llvm::sys::path::append(LibProfile, "libclang_rt.profile_" + RT + ".a"); + } + + Arguments.push_back(context.Args.MakeArgString(LibProfile)); + } +} + void toolchains::Darwin::addDeploymentTargetArgs(ArgStringList &Arguments, const JobContext &context) const { @@ -553,40 +592,7 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, addArgsToLinkStdlib(Arguments, job, context); - if (context.Args.hasArg(options::OPT_profile_generate)) { - SmallString<128> LibProfile; - getClangLibraryPath(context.Args, LibProfile); - - StringRef RT; - if (Triple.isiOS()) { - if (Triple.isTvOS()) - RT = "tvos"; - else - RT = "ios"; - } else if (Triple.isWatchOS()) { - RT = "watchos"; - } else { - assert(Triple.isMacOSX()); - RT = "osx"; - } - - StringRef Sim; - if (tripleIsAnySimulator(Triple)) { - Sim = "sim"; - } - - llvm::sys::path::append(LibProfile, - "libclang_rt.profile_" + RT + Sim + ".a"); - - // FIXME: Continue accepting the old path for simulator libraries for now. - if (!Sim.empty() && !llvm::sys::fs::exists(LibProfile)) { - llvm::sys::path::remove_filename(LibProfile); - llvm::sys::path::append(LibProfile, "libclang_rt.profile_" + RT + ".a"); - } - - Arguments.push_back(context.Args.MakeArgString(LibProfile)); - } - + addProfileGenerationArgs(Arguments, context); addDeploymentTargetArgs(Arguments, context); Arguments.push_back("-no_objc_category_merging"); diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 2e9c39f0ec7ec..58eeab40a0839 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -34,6 +34,9 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain { const DynamicLinkJobAction &job, const JobContext &context) const; + void addProfileGenerationArgs(llvm::opt::ArgStringList &Arguments, + const JobContext &context) const; + void addDeploymentTargetArgs(llvm::opt::ArgStringList &Arguments, const JobContext &context) const; From 7fb43af6e5cd543655ad0d4088e75167ffe91f61 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 1 Aug 2019 14:36:01 -0700 Subject: [PATCH 08/12] Factor out toolchains::Darwin::addSanitizerArgs. --- lib/Driver/DarwinToolChains.cpp | 41 +++++++++++++++++++-------------- lib/Driver/ToolChains.h | 4 ++++ 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index 0eb9743b89ccd..2187c92a52899 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -270,6 +270,29 @@ toolchains::Darwin::addArgsToLinkARCLite(ArgStringList &Arguments, } } +void +toolchains::Darwin::addSanitizerArgs(ArgStringList &Arguments, + const DynamicLinkJobAction &job, + const JobContext &context) const { + // Linking sanitizers will add rpaths, which might negatively interact when + // other rpaths are involved, so we should make sure we add the rpaths after + // all user-specified rpaths. + if (context.OI.SelectedSanitizers & SanitizerKind::Address) + addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "asan", *this); + + if (context.OI.SelectedSanitizers & SanitizerKind::Thread) + addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "tsan", *this); + + if (context.OI.SelectedSanitizers & SanitizerKind::Undefined) + addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "ubsan", *this); + + // Only link in libFuzzer for executables. + if (job.getKind() == LinkKind::Executable && + (context.OI.SelectedSanitizers & SanitizerKind::Fuzzer)) + addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "fuzzer", *this, + /*shared=*/false); +} + void toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments, const DynamicLinkJobAction &job, @@ -556,23 +579,7 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, Arguments.push_back("-application_extension"); } - // Linking sanitizers will add rpaths, which might negatively interact when - // other rpaths are involved, so we should make sure we add the rpaths after - // all user-specified rpaths. - if (context.OI.SelectedSanitizers & SanitizerKind::Address) - addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "asan", *this); - - if (context.OI.SelectedSanitizers & SanitizerKind::Thread) - addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "tsan", *this); - - if (context.OI.SelectedSanitizers & SanitizerKind::Undefined) - addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "ubsan", *this); - - // Only link in libFuzzer for executables. - if (job.getKind() == LinkKind::Executable && - (context.OI.SelectedSanitizers & SanitizerKind::Fuzzer)) - addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "fuzzer", *this, - /*shared=*/false); + addSanitizerArgs(Arguments, job, context); if (context.Args.hasArg(options::OPT_embed_bitcode, options::OPT_embed_bitcode_marker)) { diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 58eeab40a0839..9365af405b0c1 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -30,6 +30,10 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain { void addArgsToLinkARCLite(llvm::opt::ArgStringList &Arguments, const JobContext &context) const; + void addSanitizerArgs(llvm::opt::ArgStringList &Arguments, + const DynamicLinkJobAction &job, + const JobContext &context) const; + void addArgsToLinkStdlib(llvm::opt::ArgStringList &Arguments, const DynamicLinkJobAction &job, const JobContext &context) const; From fa244b2334f74a439169b4dbdf4d44c753d1db3e Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Tue, 20 Nov 2018 21:43:36 -0800 Subject: [PATCH 09/12] Factor out toolchains::Darwin::addLinkerInputArgs. --- lib/Driver/DarwinToolChains.cpp | 53 +++++++++++++++++++-------------- lib/Driver/ToolChains.h | 3 ++ 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index 2187c92a52899..ce380e96d2aa8 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -224,6 +224,35 @@ static bool wantsObjCRuntime(const llvm::Triple &triple) { llvm_unreachable("unknown Darwin OS"); } +void +toolchains::Darwin::addLinkerInputArgs(InvocationInfo &II, + const JobContext &context) const { + ArgStringList &Arguments = II.Arguments; + if (context.shouldUseInputFileList()) { + Arguments.push_back("-filelist"); + Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList")); + II.FilelistInfos.push_back({Arguments.back(), file_types::TY_Object, + FilelistInfo::WhichFiles::Input}); + } else { + addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, + file_types::TY_Object); + } + + addInputsOfType(Arguments, context.InputActions, file_types::TY_Object); + + if (context.OI.CompilerMode == OutputInfo::Mode::SingleCompile) + addInputsOfType(Arguments, context.Inputs, context.Args, + file_types::TY_SwiftModuleFile, "-add_ast_path"); + else + addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, + file_types::TY_SwiftModuleFile, "-add_ast_path"); + + // Add all .swiftmodule file inputs as arguments, preceded by the + // "-add_ast_path" linker option. + addInputsOfType(Arguments, context.InputActions, + file_types::TY_SwiftModuleFile, "-add_ast_path"); +} + static void findARCLiteLibPath(const toolchains::Darwin &TC, llvm::SmallVectorImpl &ARCLiteLib) { auto& D = TC.getDriver(); @@ -509,29 +538,7 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, InvocationInfo II = {LD}; ArgStringList &Arguments = II.Arguments; - if (context.shouldUseInputFileList()) { - Arguments.push_back("-filelist"); - Arguments.push_back(context.getTemporaryFilePath("inputs", "LinkFileList")); - II.FilelistInfos.push_back({Arguments.back(), file_types::TY_Object, - FilelistInfo::WhichFiles::Input}); - } else { - addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, - file_types::TY_Object); - } - - addInputsOfType(Arguments, context.InputActions, file_types::TY_Object); - - if (context.OI.CompilerMode == OutputInfo::Mode::SingleCompile) - addInputsOfType(Arguments, context.Inputs, context.Args, - file_types::TY_SwiftModuleFile, "-add_ast_path"); - else - addPrimaryInputsOfType(Arguments, context.Inputs, context.Args, - file_types::TY_SwiftModuleFile, "-add_ast_path"); - - // Add all .swiftmodule file inputs as arguments, preceded by the - // "-add_ast_path" linker option. - addInputsOfType(Arguments, context.InputActions, - file_types::TY_SwiftModuleFile, "-add_ast_path"); + addLinkerInputArgs(II, context); switch (job.getKind()) { case LinkKind::None: diff --git a/lib/Driver/ToolChains.h b/lib/Driver/ToolChains.h index 9365af405b0c1..936599c4cf36d 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -27,6 +27,9 @@ namespace toolchains { class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain { protected: + void addLinkerInputArgs(InvocationInfo &II, + const JobContext &context) const; + void addArgsToLinkARCLite(llvm::opt::ArgStringList &Arguments, const JobContext &context) const; From 0c17a70c72e187890a9407fa444aa7dfc85d140f Mon Sep 17 00:00:00 2001 From: Graydon Hoare Date: Fri, 23 Nov 2018 17:13:07 -0800 Subject: [PATCH 10/12] Add -toolchain-stdlib-rpath to test configs, to run in-tree. --- test/lit.cfg | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/lit.cfg b/test/lit.cfg index ede72624511aa..d9570c2b37dd7 100644 --- a/test/lit.cfg +++ b/test/lit.cfg @@ -380,12 +380,12 @@ if kIsWindows: config.swift_driver_test_options, config.swift_stdlib_msvc_runtime)) ) config.substitutions.append( ('%swiftc_driver', - "%r %s %s %s" % (config.swiftc, mcp_opt, - config.swift_test_options, - config.swift_driver_test_options)) ) + "%r -toolchain-stdlib-rpath %s %s %s" % (config.swiftc, mcp_opt, + config.swift_test_options, + config.swift_driver_test_options)) ) else: config.substitutions.append( ('%swift_driver', "env SDKROOT= %r %s %s %s" % (config.swift, mcp_opt, config.swift_test_options, config.swift_driver_test_options)) ) - config.substitutions.append( ('%swiftc_driver', "env SDKROOT= %r %s %s %s" % (config.swiftc, mcp_opt, config.swift_test_options, config.swift_driver_test_options)) ) + config.substitutions.append( ('%swiftc_driver', "env SDKROOT= %r -toolchain-stdlib-rpath %s %s %s" % (config.swiftc, mcp_opt, config.swift_test_options, config.swift_driver_test_options)) ) config.substitutions.append( ('%sil-opt', "%r %s %s" % (config.sil_opt, mcp_opt, config.sil_test_options)) ) config.substitutions.append( ('%sil-func-extractor', "%r %s" % (config.sil_func_extractor, mcp_opt)) ) config.substitutions.append( ('%sil-llvm-gen', "%r %s" % (config.sil_llvm_gen, mcp_opt)) ) @@ -771,7 +771,8 @@ if run_vendor == 'apple': (run_cpu, run_os, run_vers, clang_mcp_opt)) config.target_build_swift = ( - "%s %s %s -F %r -Xlinker -rpath -Xlinker %r %s %s %s %s" % + ("%s %s %s -F %r -toolchain-stdlib-rpath " + + "-Xlinker -rpath -Xlinker %r %s %s %s %s") % (xcrun_prefix, config.swiftc, target_options, extra_frameworks_dir, "/tmp/swifttest-device/lib", @@ -805,7 +806,7 @@ if run_vendor == 'apple': (run_cpu, run_os, run_vers, clang_mcp_opt)) config.target_build_swift = ( - "%s %s %s -F %r %s %s %s %s" % + "%s %s %s -F %r -toolchain-stdlib-rpath %s %s %s %s" % (xcrun_prefix, config.swiftc, target_options, extra_frameworks_dir, sdk_overlay_linker_opt, config.swift_test_options, @@ -839,7 +840,9 @@ if run_vendor == 'apple': (run_cpu, run_os, run_vers, clang_mcp_opt)) config.target_build_swift = ( - "%s %s %s -F %r -Xlinker -rpath -Xlinker %r %s %s %s %s -F %r -Xlinker -rpath -Xlinker %r" + ("%s %s %s -F %r -toolchain-stdlib-rpath " + + "-Xlinker -rpath -Xlinker %r %s %s %s %s " + + "-F %r -Xlinker -rpath -Xlinker %r") % (xcrun_prefix, config.swiftc, target_options, extra_frameworks_dir, extra_frameworks_dir, sdk_overlay_linker_opt, config.swift_test_options, @@ -889,7 +892,7 @@ if run_vendor == 'apple': subst_target_swift_ide_test_mock_sdk_after = \ target_options_for_mock_sdk_after config.target_swiftc_driver = ( - "%s %s %s" % + "%s %s -toolchain-stdlib-rpath %s" % (xcrun_prefix, config.swiftc, target_options)) config.target_clang = ( "%s clang++ %s" % @@ -1009,7 +1012,7 @@ elif run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'windows-cygnus', 'wi % (libdispatch_source_dir, libdispatch_swift_module_dir, libdispatch_artifact_dir)) config.target_build_swift = ( - '%s -target %s %s %s %s %s %s' + '%s -target %s -toolchain-stdlib-rpath %s %s %s %s %s' % (config.swiftc, config.variant_triple, resource_dir_opt, mcp_opt, config.swift_test_options, config.swift_driver_test_options, swift_execution_tests_extra_flags)) @@ -1037,7 +1040,7 @@ elif run_os in ['linux-gnu', 'linux-gnueabihf', 'freebsd', 'windows-cygnus', 'wi subst_target_swift_ide_test_mock_sdk = config.target_swift_ide_test subst_target_swift_ide_test_mock_sdk_after = "" config.target_swiftc_driver = ( - "%s -target %s %s %s" % + "%s -target %s -toolchain-stdlib-rpath %s %s" % (config.swiftc, config.variant_triple, resource_dir_opt, mcp_opt)) config.target_swift_modulewrap = ( '%s -modulewrap -target %s' % @@ -1153,6 +1156,7 @@ elif run_os == 'linux-androideabi' or run_os == 'linux-android': config.target_swiftc_driver = ' '.join([ config.swiftc, '-target', config.variant_triple, + '-toolchain-stdlib-rpath', '-Xcc', '--sysroot={}'.format(config.variant_sdk), '-Xclang-linker', '--sysroot={}'.format(config.variant_sdk), '-tools-directory', tools_directory, From 87b7ee1bc0a0700b864e0a0cee9426231951524d Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 29 Nov 2018 14:02:16 -0800 Subject: [PATCH 11/12] Tweak Swift-in-OS check to account for linker limitations The backwards-deployment install name trickery we're using doesn't handle "patch" components in version numbers, so we still need to provide an rpath even when deploying to macOS 10.14.4. --- include/swift/Basic/Platform.h | 6 +++--- lib/Basic/Platform.cpp | 21 ++++++++++----------- lib/Driver/DarwinToolChains.cpp | 2 +- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/include/swift/Basic/Platform.h b/include/swift/Basic/Platform.h index 8f355de3b3ba2..04ee3253990e9 100644 --- a/include/swift/Basic/Platform.h +++ b/include/swift/Basic/Platform.h @@ -46,9 +46,9 @@ namespace swift { /// Return true if the given triple represents any simulator. bool tripleIsAnySimulator(const llvm::Triple &triple); - /// Returns true if the given triple represents an OS that ships with ABI-stable - /// swift libraries (eg. in /usr/lib/swift). - bool tripleHasSwiftInTheOS(const llvm::Triple &triple); + /// Returns true if the given triple represents an OS that ships with + /// ABI-stable swift libraries (eg. in /usr/lib/swift). + bool tripleRequiresRPathForSwiftInOS(const llvm::Triple &triple); /// Returns the platform name for a given target triple. /// diff --git a/lib/Basic/Platform.cpp b/lib/Basic/Platform.cpp index b01d82aeeedba..b72c9242f9eae 100644 --- a/lib/Basic/Platform.cpp +++ b/lib/Basic/Platform.cpp @@ -55,21 +55,20 @@ bool swift::tripleIsAnySimulator(const llvm::Triple &triple) { } -bool swift::tripleHasSwiftInTheOS(const llvm::Triple &triple) { - unsigned major, minor, revision; +bool swift::tripleRequiresRPathForSwiftInOS(const llvm::Triple &triple) { if (triple.isMacOSX()) { - triple.getMacOSXVersion(major, minor, revision); - return llvm::VersionTuple(major, minor, revision) >= - llvm::VersionTuple(10, 14, 4); + // macOS 10.14.4 contains a copy of Swift, but the linker will still use an + // rpath-based install name until 10.15. + return triple.isMacOSXVersionLT(10, 15); + } else if (triple.isiOS()) { - triple.getiOSVersion(major, minor, revision); - return llvm::VersionTuple(major, minor, revision) >= - llvm::VersionTuple(12, 2); + return triple.isOSVersionLT(12, 2); + } else if (triple.isWatchOS()) { - triple.getOSVersion(major, minor, revision); - return llvm::VersionTuple(major, minor, revision) >= - llvm::VersionTuple(5, 2); + return triple.isOSVersionLT(5, 2); } + + // Other platforms don't have Swift installed as part of the OS by default. return false; } diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index ce380e96d2aa8..2a1efaaa1645c 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -401,7 +401,7 @@ toolchains::Darwin::addArgsToLinkStdlib(ArgStringList &Arguments, Arguments.push_back("-rpath"); Arguments.push_back(context.Args.MakeArgString(path)); } - } else if (tripleHasSwiftInTheOS(getTriple()) || + } else if (!tripleRequiresRPathForSwiftInOS(getTriple()) || context.Args.hasArg(options::OPT_no_stdlib_rpath)) { // If targeting an OS with Swift in /usr/lib/swift, the LC_ID_DYLIB // install_name the stdlib will be an absolute path like From 3694686cf667be00e7d1baece23295f30ff531d0 Mon Sep 17 00:00:00 2001 From: Jordan Rose Date: Thu, 1 Aug 2019 15:00:40 -0700 Subject: [PATCH 12/12] [test] Add tests for Darwin Driver rpath work --- test/Driver/linker-rpath.swift | 42 ++++++++++++++++++++++++++++++++++ test/Driver/sdk.swift | 1 - 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 test/Driver/linker-rpath.swift diff --git a/test/Driver/linker-rpath.swift b/test/Driver/linker-rpath.swift new file mode 100644 index 0000000000000..82b0dca4d17d5 --- /dev/null +++ b/test/Driver/linker-rpath.swift @@ -0,0 +1,42 @@ +// REQUIRES: OS=macosx +// Note: This is really about the /host/ environment, but since there are RUN +// lines for multiple targets anyway it doesn't make a huge difference. + +// RUN: %swiftc_driver_plain -driver-print-jobs -target x86_64-apple-macosx10.9 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target x86_64-apple-macosx10.14 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target x86_64-apple-macosx10.14.3 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target x86_64-apple-macosx10.14.4 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target x86_64-apple-macosx10.15 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO-RPATH %s + +// RUN: %swiftc_driver_plain -driver-print-jobs -target arm64-apple-ios12 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target arm64-apple-ios12.1 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target arm64-apple-ios12.2 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO-RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target arm64-apple-ios13 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO-RPATH %s + +// RUN: %swiftc_driver_plain -driver-print-jobs -target arm64-apple-tvos12 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target arm64-apple-tvos12.1 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target arm64-apple-tvos12.2 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO-RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target arm64-apple-tvos13 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO-RPATH %s + +// RUN: %swiftc_driver_plain -driver-print-jobs -target armv7k-apple-watchos5 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target armv7k-apple-watchos5.1 %S/../Inputs/empty.swift | %FileCheck -check-prefix RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target armv7k-apple-watchos5.2 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO-RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target armv7k-apple-watchos6 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO-RPATH %s + +// RPATH: bin/ld{{"? }} +// RPATH-SAME: -rpath {{"?/usr/lib/swift(-.+)?"? }} +// RPATH-SAME: -o {{[^ ]+}} + +// NO-RPATH-NOT: -rpath{{ }} + +// ### Test with -no-stdlib-rpath +// RUN: %swiftc_driver_plain -driver-print-jobs -target x86_64-apple-macosx10.9 %S/../Inputs/empty.swift -no-stdlib-rpath | %FileCheck -check-prefix NO-RPATH %s +// RUN: %swiftc_driver_plain -driver-print-jobs -target x86_64-apple-macosx10.15 %S/../Inputs/empty.swift -no-stdlib-rpath | %FileCheck -check-prefix NO-RPATH %s + +// ### Test with -toolchain-stdlib-rpath +// RUN: %swiftc_driver_plain -driver-print-jobs -toolchain-stdlib-rpath -target x86_64-apple-macosx10.9 %S/../Inputs/empty.swift -resource-dir garbage/ | %FileCheck -check-prefix TOOLCHAIN-RPATH -DPLATFORM=%target-sdk-name %s +// RUN: %swiftc_driver_plain -driver-print-jobs -toolchain-stdlib-rpath -target x86_64-apple-macosx10.15 %S/../Inputs/empty.swift -resource-dir garbage/ | %FileCheck -check-prefix TOOLCHAIN-RPATH -DPLATFORM=%target-sdk-name %s + +// TOOLCHAIN-RPATH: bin/ld{{"? }} +// TOOLCHAIN-RPATH-SAME: -rpath garbage/[[PLATFORM]]{{ }} +// TOOLCHAIN-RPATH-SAME: -o {{[^ ]+}} diff --git a/test/Driver/sdk.swift b/test/Driver/sdk.swift index 8281b949a32a7..2accb502e4319 100644 --- a/test/Driver/sdk.swift +++ b/test/Driver/sdk.swift @@ -16,7 +16,6 @@ // OSX: {{.*}}.o{{[ "]}} // OSX: {{-syslibroot|--sysroot}} {{[^ ]*}}/Inputs/clang-importer-sdk // OSX: -L {{[^ ]*}}/Inputs/clang-importer-sdk{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}swift -// OSX: -rpath {{[^ ]*}}/Inputs/clang-importer-sdk{{/|\\\\}}usr{{/|\\\\}}lib{{/|\\\\}}swift // LINUX-NOT: warning: no such SDK: // LINUX: bin{{/|\\\\}}swift