diff --git a/include/swift/Basic/Platform.h b/include/swift/Basic/Platform.h index 134b7a2cd43c6..04ee3253990e9 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 tripleRequiresRPathForSwiftInOS(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/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">; diff --git a/lib/Basic/Platform.cpp b/lib/Basic/Platform.cpp index 90bc7d52cc203..b72c9242f9eae 100644 --- a/lib/Basic/Platform.cpp +++ b/lib/Basic/Platform.cpp @@ -54,6 +54,24 @@ bool swift::tripleIsAnySimulator(const llvm::Triple &triple) { tripleIsAppleTVSimulator(triple); } + +bool swift::tripleRequiresRPathForSwiftInOS(const llvm::Triple &triple) { + if (triple.isMacOSX()) { + // 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()) { + return triple.isOSVersionLT(12, 2); + + } else if (triple.isWatchOS()) { + return triple.isOSVersionLT(5, 2); + } + + // Other platforms don't have Swift installed as part of the OS by default. + return false; +} + DarwinPlatformKind swift::getDarwinPlatformKind(const llvm::Triple &triple) { if (triple.isiOS()) { if (triple.isTvOS()) { diff --git a/lib/Driver/DarwinToolChains.cpp b/lib/Driver/DarwinToolChains.cpp index 0dc2bf7f22057..2a1efaaa1645c 100644 --- a/lib/Driver/DarwinToolChains.cpp +++ b/lib/Driver/DarwinToolChains.cpp @@ -224,56 +224,10 @@ static bool wantsObjCRuntime(const llvm::Triple &triple) { llvm_unreachable("unknown Darwin OS"); } -static void findARCLiteLibPath(const toolchains::Darwin &TC, - llvm::SmallVectorImpl &ARCLiteLib) { - auto& D = TC.getDriver(); - llvm::sys::path::append(ARCLiteLib, D.getSwiftProgramPath()); - - llvm::sys::path::remove_filename(ARCLiteLib); // 'swift' - llvm::sys::path::remove_filename(ARCLiteLib); // 'bin' - llvm::sys::path::append(ARCLiteLib, "lib", "arc"); - - if (!llvm::sys::fs::is_directory(ARCLiteLib)) { - // If we don't have a 'lib/arc/' directory, find the "arclite" library - // relative to the Clang in the active Xcode. - ARCLiteLib.clear(); - if (findXcodeClangPath(ARCLiteLib)) { - llvm::sys::path::remove_filename(ARCLiteLib); // 'clang' - llvm::sys::path::remove_filename(ARCLiteLib); // 'bin' - llvm::sys::path::append(ARCLiteLib, "lib", "arc"); - } - } -} - -ToolChain::InvocationInfo -toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, - const JobContext &context) const { - assert(context.Output.getPrimaryOutputType() == file_types::TY_Image && - "Invalid linker output type."); - - if (context.Args.hasFlag(options::OPT_static_executable, - options::OPT_no_static_executable, false)) { - llvm::report_fatal_error("-static-executable is not supported on Darwin"); - } - - const llvm::Triple &Triple = getTriple(); - - // Configure the toolchain. - // By default, use the system `ld` to link. - const char *LD = "ld"; - if (const Arg *A = context.Args.getLastArg(options::OPT_tools_directory)) { - StringRef toolchainPath(A->getValue()); - - // If there is a 'ld' in the toolchain folder, use that instead. - if (auto toolchainLD = - llvm::sys::findProgramByName("ld", {toolchainPath})) { - LD = context.Args.MakeArgString(toolchainLD.get()); - } - } - - InvocationInfo II = {LD}; +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")); @@ -297,71 +251,58 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, // "-add_ast_path" linker option. addInputsOfType(Arguments, context.InputActions, file_types::TY_SwiftModuleFile, "-add_ast_path"); +} - switch (job.getKind()) { - case LinkKind::None: - llvm_unreachable("invalid link kind"); - case LinkKind::Executable: - // The default for ld; no extra flags necessary. - break; - case LinkKind::DynamicLibrary: - Arguments.push_back("-dylib"); - break; - case LinkKind::StaticLibrary: - llvm_unreachable("the dynamic linker cannot build static libraries"); - } - - assert(Triple.isOSDarwin()); - - // FIXME: If we used Clang as a linker instead of going straight to ld, - // we wouldn't have to replicate a bunch of Clang's logic here. - - // Always link the regular compiler_rt if it's present. - // - // Note: Normally we'd just add this unconditionally, but it's valid to build - // Swift and use it as a linker without building compiler_rt. - SmallString<128> CompilerRTPath; - getClangLibraryPath(context.Args, CompilerRTPath); - llvm::sys::path::append( - CompilerRTPath, - Twine("libclang_rt.") + - getDarwinLibraryNameSuffixForTriple(Triple, /*simulator*/false) + - ".a"); - if (llvm::sys::fs::exists(CompilerRTPath)) - Arguments.push_back(context.Args.MakeArgString(CompilerRTPath)); +static void findARCLiteLibPath(const toolchains::Darwin &TC, + llvm::SmallVectorImpl &ARCLiteLib) { + auto& D = TC.getDriver(); + llvm::sys::path::append(ARCLiteLib, D.getSwiftProgramPath()); + + llvm::sys::path::remove_filename(ARCLiteLib); // 'swift' + llvm::sys::path::remove_filename(ARCLiteLib); // 'bin' + llvm::sys::path::append(ARCLiteLib, "lib", "arc"); - 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 (!llvm::sys::fs::is_directory(ARCLiteLib)) { + // If we don't have a 'lib/arc/' directory, find the "arclite" library + // relative to the Clang in the active Xcode. + ARCLiteLib.clear(); + if (findXcodeClangPath(ARCLiteLib)) { + llvm::sys::path::remove_filename(ARCLiteLib); // 'clang' + llvm::sys::path::remove_filename(ARCLiteLib); // 'bin' + llvm::sys::path::append(ARCLiteLib, "lib", "arc"); + } + } +} - if (!ARCLiteLib.empty()) { - llvm::sys::path::append(ARCLiteLib, "libarclite_"); - ARCLiteLib += getPlatformNameForTriple(Triple); - ARCLiteLib += ".a"; +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; - Arguments.push_back("-force_load"); - Arguments.push_back(context.Args.MakeArgString(ARCLiteLib)); + llvm::SmallString<128> ARCLiteLib; + findARCLiteLibPath(*this, ARCLiteLib); - // Arclite depends on CoreFoundation. - Arguments.push_back("-framework"); - Arguments.push_back("CoreFoundation"); - } - } + if (!ARCLiteLib.empty()) { + llvm::sys::path::append(ARCLiteLib, "libarclite_"); + ARCLiteLib += getPlatformNameForTriple(getTriple()); + ARCLiteLib += ".a"; - for (const Arg *arg : - context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) { - Arguments.push_back("-F"); - Arguments.push_back(arg->getValue()); - } + Arguments.push_back("-force_load"); + Arguments.push_back(context.Args.MakeArgString(ARCLiteLib)); - if (context.Args.hasArg(options::OPT_enable_app_extension)) { - // Keep this string fixed in case the option used by the - // compiler itself changes. - Arguments.push_back("-application_extension"); + // Arclite depends on CoreFoundation. + Arguments.push_back("-framework"); + Arguments.push_back("CoreFoundation"); } +} +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. @@ -379,22 +320,12 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, (context.OI.SelectedSanitizers & SanitizerKind::Fuzzer)) addLinkSanitizerLibArgsForDarwin(context.Args, Arguments, "fuzzer", *this, /*shared=*/false); +} - if (context.Args.hasArg(options::OPT_embed_bitcode, - options::OPT_embed_bitcode_marker)) { - Arguments.push_back("-bitcode_bundle"); - } - - if (!context.OI.SDKPath.empty()) { - Arguments.push_back("-syslibroot"); - Arguments.push_back(context.Args.MakeArgString(context.OI.SDKPath)); - } - - Arguments.push_back("-lobjc"); - Arguments.push_back("-lSystem"); - - Arguments.push_back("-arch"); - Arguments.push_back(context.Args.MakeArgString(getTriple().getArchName())); +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. @@ -414,7 +345,7 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, } } else if (job.getKind() == LinkKind::Executable) { runtimeCompatibilityVersion - = getSwiftRuntimeCompatibilityVersionForTarget(Triple); + = getSwiftRuntimeCompatibilityVersionForTarget(getTriple()); } if (runtimeCompatibilityVersion) { @@ -447,24 +378,64 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, } } + // 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); - // 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)); } - // 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 (!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 + // /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")); } +} +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); @@ -498,7 +469,12 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, Arguments.push_back(context.Args.MakeArgString(LibProfile)); } +} +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()) { @@ -531,6 +507,107 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, Triple.getMacOSXVersion(major, minor, micro); addVersionString(context.Args, Arguments, major, minor, micro); } +} + +ToolChain::InvocationInfo +toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job, + const JobContext &context) const { + assert(context.Output.getPrimaryOutputType() == file_types::TY_Image && + "Invalid linker output type."); + + if (context.Args.hasFlag(options::OPT_static_executable, + options::OPT_no_static_executable, false)) { + llvm::report_fatal_error("-static-executable is not supported on Darwin"); + } + + const llvm::Triple &Triple = getTriple(); + + // Configure the toolchain. + // By default, use the system `ld` to link. + const char *LD = "ld"; + if (const Arg *A = context.Args.getLastArg(options::OPT_tools_directory)) { + StringRef toolchainPath(A->getValue()); + + // If there is a 'ld' in the toolchain folder, use that instead. + if (auto toolchainLD = + llvm::sys::findProgramByName("ld", {toolchainPath})) { + LD = context.Args.MakeArgString(toolchainLD.get()); + } + } + + InvocationInfo II = {LD}; + ArgStringList &Arguments = II.Arguments; + + addLinkerInputArgs(II, context); + + switch (job.getKind()) { + case LinkKind::None: + llvm_unreachable("invalid link kind"); + case LinkKind::Executable: + // The default for ld; no extra flags necessary. + break; + case LinkKind::DynamicLibrary: + Arguments.push_back("-dylib"); + break; + case LinkKind::StaticLibrary: + llvm_unreachable("the dynamic linker cannot build static libraries"); + } + + assert(Triple.isOSDarwin()); + + // FIXME: If we used Clang as a linker instead of going straight to ld, + // we wouldn't have to replicate a bunch of Clang's logic here. + + // Always link the regular compiler_rt if it's present. + // + // Note: Normally we'd just add this unconditionally, but it's valid to build + // Swift and use it as a linker without building compiler_rt. + SmallString<128> CompilerRTPath; + getClangLibraryPath(context.Args, CompilerRTPath); + llvm::sys::path::append( + CompilerRTPath, + Twine("libclang_rt.") + + getDarwinLibraryNameSuffixForTriple(Triple, /*simulator*/false) + + ".a"); + if (llvm::sys::fs::exists(CompilerRTPath)) + Arguments.push_back(context.Args.MakeArgString(CompilerRTPath)); + + addArgsToLinkARCLite(Arguments, context); + + for (const Arg *arg : + context.Args.filtered(options::OPT_F, options::OPT_Fsystem)) { + Arguments.push_back("-F"); + Arguments.push_back(arg->getValue()); + } + + if (context.Args.hasArg(options::OPT_enable_app_extension)) { + // Keep this string fixed in case the option used by the + // compiler itself changes. + Arguments.push_back("-application_extension"); + } + + addSanitizerArgs(Arguments, job, context); + + if (context.Args.hasArg(options::OPT_embed_bitcode, + options::OPT_embed_bitcode_marker)) { + Arguments.push_back("-bitcode_bundle"); + } + + if (!context.OI.SDKPath.empty()) { + Arguments.push_back("-syslibroot"); + Arguments.push_back(context.Args.MakeArgString(context.OI.SDKPath)); + } + + Arguments.push_back("-lobjc"); + Arguments.push_back("-lSystem"); + + Arguments.push_back("-arch"); + Arguments.push_back(context.Args.MakeArgString(getTriple().getArchName())); + + addArgsToLinkStdlib(Arguments, job, context); + + 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 b0d182923c4aa..936599c4cf36d 100644 --- a/lib/Driver/ToolChains.h +++ b/lib/Driver/ToolChains.h @@ -26,6 +26,27 @@ 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; + + 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; + + void addProfileGenerationArgs(llvm::opt::ArgStringList &Arguments, + 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, 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 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,