Skip to content

[pull] swiftwasm-release/5.8 from release/5.8 #5329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/AST/DiagnosticsDriver.def
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,9 @@ ERROR(cannot_find_migration_script, none,
ERROR(error_darwin_static_stdlib_not_supported, none,
"-static-stdlib is no longer supported on Apple platforms", ())

WARNING(warn_darwin_link_objc_deprecated, none,
"-link-objc-runtime is no longer supported on Apple platforms", ())

ERROR(error_darwin_only_supports_libcxx, none,
"The only C++ standard library supported on Apple platforms is libc++",
())
Expand Down
7 changes: 5 additions & 2 deletions include/swift/Option/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -805,11 +805,14 @@ def L_EQ : Joined<["-"], "L=">, Group<linker_option_Group>,
Flags<[FrontendOption, DoesNotAffectIncrementalBuild, ArgumentIsPath]>,
Alias<L>;

// Accept but ignore these flags. They were once used to control
// linking of arclite, which is no longer used on Darwin.
def link_objc_runtime : Flag<["-"], "link-objc-runtime">,
Flags<[DoesNotAffectIncrementalBuild]>;
Flags<[DoesNotAffectIncrementalBuild]>,
HelpText<"Deprecated">;
def no_link_objc_runtime : Flag<["-"], "no-link-objc-runtime">,
Flags<[HelpHidden, DoesNotAffectIncrementalBuild]>,
HelpText<"Don't link in additions to the Objective-C runtime">;
HelpText<"Deprecated">;

def static_stdlib: Flag<["-"], "static-stdlib">,
Flags<[DoesNotAffectIncrementalBuild]>,
Expand Down
97 changes: 6 additions & 91 deletions lib/Driver/DarwinToolChains.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,27 +221,6 @@ static void addVersionString(const ArgList &inputArgs, ArgStringList &arguments,
arguments.push_back(inputArgs.MakeArgString(os.str()));
}

/// Returns true if the compiler depends on features provided by the ObjC
/// runtime that are not present on the deployment target indicated by
/// \p triple.
static bool wantsObjCRuntime(const llvm::Triple &triple) {
assert((!triple.isTvOS() || triple.isiOS()) &&
"tvOS is considered a kind of iOS");

// When updating the versions listed here, please record the most recent
// feature being depended on and when it was introduced:
//
// - Make assigning 'nil' to an NSMutableDictionary subscript delete the
// entry, like it does for Swift.Dictionary, rather than trap.
if (triple.isiOS())
return triple.isOSVersionLT(9);
if (triple.isMacOSX())
return triple.isMacOSXVersionLT(10, 11);
if (triple.isWatchOS())
return false;
llvm_unreachable("unknown Darwin OS");
}

void
toolchains::Darwin::addLinkerInputArgs(InvocationInfo &II,
const JobContext &context) const {
Expand Down Expand Up @@ -278,48 +257,6 @@ toolchains::Darwin::addLinkerInputArgs(InvocationInfo &II,
file_types::TY_SwiftModuleFile, "-add_ast_path");
}

static void findARCLiteLibPath(const toolchains::Darwin &TC,
llvm::SmallVectorImpl<char> &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();
findXcodeClangLibPath("arc", ARCLiteLib);
}
}

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::addLTOLibArgs(ArgStringList &Arguments,
const JobContext &context) const {
if (!context.OI.LibLTOPath.empty()) {
Expand Down Expand Up @@ -741,8 +678,6 @@ toolchains::Darwin::constructInvocation(const DynamicLinkJobAction &job,
if (llvm::sys::fs::exists(CompilerRTPath))
Arguments.push_back(context.Args.MakeArgString(CompilerRTPath));

addArgsToLinkARCLite(Arguments, context);

if (job.shouldPerformLTO()) {
addLTOLibArgs(Arguments, context);
}
Expand Down Expand Up @@ -857,23 +792,6 @@ std::string toolchains::Darwin::getGlobalDebugPathRemapping() const {
return {};
}

static void validateLinkObjcRuntimeARCLiteLib(const toolchains::Darwin &TC,
DiagnosticEngine &diags,
const llvm::opt::ArgList &args) {
auto Triple = TC.getTriple();
if (args.hasFlag(options::OPT_link_objc_runtime,
options::OPT_no_link_objc_runtime,
/*Default=*/wantsObjCRuntime(Triple))) {
llvm::SmallString<128> ARCLiteLib;
findARCLiteLibPath(TC, ARCLiteLib);

if (ARCLiteLib.empty()) {
diags.diagnose(SourceLoc(),
diag::warn_arclite_not_found_when_link_objc_runtime);
}
}
}

static void validateDeploymentTarget(const toolchains::Darwin &TC,
DiagnosticEngine &diags,
const llvm::opt::ArgList &args) {
Expand Down Expand Up @@ -927,15 +845,6 @@ void
toolchains::Darwin::validateArguments(DiagnosticEngine &diags,
const llvm::opt::ArgList &args,
StringRef defaultTarget) const {
if (!getDriver().isDummyDriverForFrontendInvocation()) {
// Validating arclite library path when link-objc-runtime.
// If the driver is just set up to retrieve the swift-frontend invocation,
// we don't care about link-time, so we can skip this step, which may be
// expensive since it might call to `xcrun` to find `clang` and `arclite`
// relative to `clang`.
validateLinkObjcRuntimeARCLiteLib(*this, diags, args);
}

// Validating apple platforms deployment targets.
validateDeploymentTarget(*this, diags, args);
validateTargetVariant(*this, diags, args, defaultTarget);
Expand All @@ -945,6 +854,12 @@ toolchains::Darwin::validateArguments(DiagnosticEngine &diags,
diags.diagnose(SourceLoc(), diag::error_darwin_static_stdlib_not_supported);
}

// Validating darwin deprecated -link-objc-runtime.
if (args.hasArg(options::OPT_link_objc_runtime,
options::OPT_no_link_objc_runtime)) {
diags.diagnose(SourceLoc(), diag::warn_darwin_link_objc_deprecated);
}

// If a C++ standard library is specified, it has to be libc++.
if (auto arg = args.getLastArg(options::OPT_experimental_cxx_stdlib)) {
if (StringRef(arg->getValue()) != "libc++") {
Expand Down
3 changes: 0 additions & 3 deletions lib/Driver/ToolChains.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,6 @@ class LLVM_LIBRARY_VISIBILITY Darwin : public ToolChain {
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;
Expand Down
21 changes: 2 additions & 19 deletions test/Driver/linker-arclite.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,31 +2,14 @@
// 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 -driver-print-jobs -target x86_64-apple-macosx10.9 %S/../Inputs/empty.swift | %FileCheck %s

// CHECK: bin/ld{{"? }}
// CHECK-SAME: -force_load {{[^ ]+/lib/arc/libarclite_macosx.a}} -framework CoreFoundation
// CHECK-SAME: -o {{[^ ]+}}


// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-ios8.0-simulator %S/../Inputs/empty.swift | %FileCheck -check-prefix IOS_ARCLITE %s

// IOS_ARCLITE: bin/ld{{"? }}
// IOS_ARCLITE: -force_load {{[^ ]+/lib/arc/libarclite_iphonesimulator.a}}
// IOS_ARCLITE: -o {{[^ ]+}}

// The libarclite library is no longer used for any Darwin platform, so this now just verifies that we never request it

// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.11 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO_ARCLITE %s
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-macosx10.10 %S/../Inputs/empty.swift | %FileCheck -check-prefix ANY_ARCLITE %s
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-ios9-simulator %S/../Inputs/empty.swift | %FileCheck -check-prefix NO_ARCLITE %s
// RUN: %swiftc_driver -driver-print-jobs -target x86_64-apple-ios8-simulator %S/../Inputs/empty.swift | %FileCheck -check-prefix ANY_ARCLITE %s
// RUN: %swiftc_driver -driver-print-jobs -target arm64-apple-tvos9 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO_ARCLITE %s
// RUN: %swiftc_driver -driver-print-jobs -target armv7k-apple-watchos2 %S/../Inputs/empty.swift | %FileCheck -check-prefix NO_ARCLITE %s

// NO_ARCLITE: bin/ld{{"? }}
// NO_ARCLITE-NOT: arclite
// NO_ARCLITE-NOT: CoreFoundation
// NO_ARCLITE: -o {{[^ ]+}}

// ANY_ARCLITE: bin/ld{{"? }}
// ANY_ARCLITE: -force_load {{[^ ]+}}/lib/arc/libarclite_{{.+}}.a
// ANY_ARCLITE: -o {{[^ ]+}}
6 changes: 6 additions & 0 deletions test/Driver/options-apple.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// REQUIRES: swift_interpreter
// REQUIRES: OS=macosx

// RUN: %swift_driver -link-objc-runtime %s 2>&1 | %FileCheck -check-prefix LINK_OBJC_RUNTIME_WARNING %s
// RUN: %swift_driver -no-link-objc-runtime %s 2>&1 | %FileCheck -check-prefix LINK_OBJC_RUNTIME_WARNING %s
// LINK_OBJC_RUNTIME_WARNING: warning: -link-objc-runtime is no longer supported on Apple platforms
2 changes: 0 additions & 2 deletions test/Driver/options-interpreter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
// CHECK-L2: # DYLD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/macosx$}}

// RUN: env DYLD_LIBRARY_PATH=/abc/ SDKROOT=/sdkroot %swift_driver_plain -### -target x86_64-apple-macosx10.9 -L/foo/ -L/bar/ %s 2>&1 | %FileCheck -check-prefix=CHECK-L2-ENV %s
// CHECK-L2-ENV: warning: unable to find Objective-C runtime support library 'arclite'; pass '-no-link-objc-runtime' to silence this warning
// CHECK-L2-ENV: # DYLD_LIBRARY_PATH={{/foo/:/bar/:[^:]+/lib/swift/macosx:/sdkroot/usr/lib/swift:/abc/$}}

// RUN: %swift_driver_plain -### -target x86_64-apple-macosx10.9 %s | %FileCheck -check-prefix=CHECK-NO-FRAMEWORKS %s
Expand All @@ -53,7 +52,6 @@
// CHECK-F2-ENV: DYLD_FRAMEWORK_PATH=/foo/:/bar/:/abc/{{$}}

// RUN: env DYLD_FRAMEWORK_PATH=/abc/ SDKROOT=/sdkroot %swift_driver_plain -### -target x86_64-apple-macosx10.9 -F/foo/ -F/bar/ -L/foo2/ -L/bar2/ %s 2>&1 | %FileCheck -check-prefix=CHECK-COMPLEX %s
// CHECK-COMPLEX: warning: unable to find Objective-C runtime support library 'arclite'; pass '-no-link-objc-runtime' to silence this warning
// CHECK-COMPLEX: -F /foo/
// CHECK-COMPLEX: -F /bar/
// CHECK-COMPLEX: #
Expand Down