Skip to content

Add arm64 -> arm64e fallback to module loading #39083

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
Sep 10, 2021
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
19 changes: 19 additions & 0 deletions lib/Serialization/SerializedModuleLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,23 @@ namespace {
void forEachTargetModuleBasename(const ASTContext &Ctx,
llvm::function_ref<void(StringRef)> body) {
auto normalizedTarget = getTargetSpecificModuleTriple(Ctx.LangOpts.Target);

// An arm64 module can import an arm64e module.
Optional<llvm::Triple> normalizedAltTarget;
if ((normalizedTarget.getArch() == llvm::Triple::ArchType::aarch64) &&
(normalizedTarget.getSubArch() !=
llvm::Triple::SubArchType::AArch64SubArch_arm64e)) {
auto altTarget = normalizedTarget;
altTarget.setArchName("arm64e");
normalizedAltTarget = getTargetSpecificModuleTriple(altTarget);
}

body(normalizedTarget.str());

if (normalizedAltTarget) {
body(normalizedAltTarget->str());
}

// We used the un-normalized architecture as a target-specific
// module name. Fall back to that behavior.
body(Ctx.LangOpts.Target.getArchName());
Expand All @@ -61,6 +76,10 @@ void forEachTargetModuleBasename(const ASTContext &Ctx,
if (Ctx.LangOpts.Target.getArch() == llvm::Triple::ArchType::arm) {
body("arm");
}

if (normalizedAltTarget) {
body(normalizedAltTarget->getArchName());
}
}

enum class SearchPathKind {
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.2
// swift-module-flags: -target arm64e-apple-ios13.0 -enable-library-evolution -swift-version 5 -module-name PtrAuthFramework
import Swift

#if _ptrauth(_arm64e)
public let iOSPtrAuth: Bool = true
#else
public let iOSNotPtrAuth: Bool = true
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.2
// swift-module-flags: -target arm64e-apple-macos10.13 -enable-library-evolution -swift-version 5 -module-name PtrAuthFramework
import Swift

#if _ptrauth(_arm64e)
public let macOSPtrAuth: Bool = true
#else
public let macOSNotPtrAuth: Bool = true
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// swift-interface-format-version: 1.0
// swift-compiler-version: Apple Swift version 5.2
// swift-module-flags: -target arm64e-apple-tvos13.0 -enable-library-evolution -swift-version 5 -module-name PtrAuthFramework
import Swift

// Intentionally incompatible
#if _ptrauth(_arm64e)
public let tvOSPtrAuth: Bool = true
#else
public let tvOSNotPtrAuth: Bool = true
#endif
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-interface-format-version: 1.0
// swift-tools-version: Apple Swift version 5.1 (swiftlang-1100.0.38 clang-1100.0.20.14)
// swift-module-flags: -target arm64-apple-macos10.14 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name DummyFramework
// swift-module-flags: -target arm64-apple-macos10.14 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name BrokenFramework
import Swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-interface-format-version: 1.0
// swift-tools-version: Apple Swift version 5.1 (swiftlang-1100.0.38 clang-1100.0.20.14)
// swift-module-flags: -target arm64e-apple-macos10.14 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name DummyFramework
// swift-module-flags: -target arm64e-apple-macos10.14 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name BrokenFramework
import Swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-interface-format-version: 1.0
// swift-tools-version: Apple Swift version 5.1 (swiftlang-1100.0.38 clang-1100.0.20.14)
// swift-module-flags: -target x86_64-apple-macos10.14 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name DummyFramework
// swift-module-flags: -target x86_64-apple-macos10.14 -enable-objc-interop -enable-library-evolution -swift-version 5 -enforce-exclusivity=checked -O -module-name BrokenFramework
import Swift
45 changes: 40 additions & 5 deletions test/ModuleInterface/arm64e-fallback.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
// RUN: not %target-typecheck-verify-swift -target arm64e-apple-ios13.0 -F %S/Inputs 2>&1 | %FileCheck %s
// RUN: %empty-directory(%t)
// RUN: %target-typecheck-verify-swift -F %S/Inputs -module-cache-path %t -verify-ignore-unknown -Rmodule-interface-rebuild

// REQUIRES: OS=ios
// UNSUPPORTED: OS=maccatalyst
// PtrAuthFramework only supports these OSes.
//
// REQUIRES: OS=tvos || OS=macosx || OS=ios

import DummyFramework
// CHECK: no such module 'DummyFramework'
// When run on arm64, this tests that we fall back to the arm64e interface, but
// build it with `#if _ptrauth(_arm64e)` off.
//
// When run on arm64e, this tests that we build the same interface with
// `#if _ptrauth(_arm64e)` on.
//
// REQUIRES: CPU=arm64 || CPU=arm64e

import PtrAuthFramework // expected-remark{{rebuilding module 'PtrAuthFramework' from interface}}

#if os(iOS)

#if _ptrauth(_arm64e)
public let x: Bool = iOSPtrAuth
#else
public let x: Bool = iOSNotPtrAuth
#endif

#elseif os(macOS)

#if _ptrauth(_arm64e)
public let x: Bool = macOSPtrAuth
#else
public let x: Bool = macOSNotPtrAuth
#endif

#else

#if _ptrauth(_arm64e)
public let x: Bool = tvOSPtrAuth
#else
public let x: Bool = tvOSNotPtrAuth
#endif

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@
// RUN: not %target-swift-frontend-typecheck -disable-implicit-concurrency-module-import -target %target-cpu-apple-macosx13.0 -F %S/Inputs %s -module-cache-path %t/module-cache
// RUN: %target-swift-frontend-typecheck -disable-implicit-concurrency-module-import -target %target-cpu-apple-macosx13.0 -F %S/Inputs %s -module-cache-path %t/module-cache -backup-module-interface-path %S/Inputs/alternative-interfaces

import DummyFramework
import BrokenFramework