Skip to content

Commit 2240a39

Browse files
committed
Add arm64 -> arm64e fallback
If we are building for ARM64 but we try to import a module with only an ARM64e interface, fall back to importing said interface. This is the reverse of a similar fallback briefly introduced last year, but removed in #31196.
1 parent 9358d76 commit 2240a39

File tree

8 files changed

+90
-17
lines changed

8 files changed

+90
-17
lines changed

lib/Serialization/SerializedModuleLoader.cpp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,23 @@ namespace {
4646
void forEachTargetModuleBasename(const ASTContext &Ctx,
4747
llvm::function_ref<void(StringRef)> body) {
4848
auto normalizedTarget = getTargetSpecificModuleTriple(Ctx.LangOpts.Target);
49+
50+
// An arm64 module can import an arm64e module.
51+
Optional<llvm::Triple> normalizedAltTarget;
52+
if ((normalizedTarget.getArch() == llvm::Triple::ArchType::aarch64) &&
53+
(normalizedTarget.getSubArch() !=
54+
llvm::Triple::SubArchType::AArch64SubArch_arm64e)) {
55+
auto altTarget = normalizedTarget;
56+
altTarget.setArchName("arm64e");
57+
normalizedAltTarget = getTargetSpecificModuleTriple(altTarget);
58+
}
59+
4960
body(normalizedTarget.str());
5061

62+
if (normalizedAltTarget) {
63+
body(normalizedAltTarget->str());
64+
}
65+
5166
// We used the un-normalized architecture as a target-specific
5267
// module name. Fall back to that behavior.
5368
body(Ctx.LangOpts.Target.getArchName());
@@ -61,6 +76,10 @@ void forEachTargetModuleBasename(const ASTContext &Ctx,
6176
if (Ctx.LangOpts.Target.getArch() == llvm::Triple::ArchType::arm) {
6277
body("arm");
6378
}
79+
80+
if (normalizedAltTarget) {
81+
body(normalizedAltTarget->getArchName());
82+
}
6483
}
6584

6685
enum class SearchPathKind {

test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64-apple-ios.swiftinterface

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64.swiftinterface

Lines changed: 0 additions & 4 deletions
This file was deleted.

test/ModuleInterface/Inputs/DummyFramework.framework/Modules/DummyFramework.swiftmodule/arm64e.swiftinterface

Lines changed: 0 additions & 4 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-compiler-version: Apple Swift version 5.2
3+
// swift-module-flags: -target arm64e-apple-ios13.0 -enable-library-evolution -swift-version 5 -module-name PtrAuthFramework
4+
import Swift
5+
6+
#if _ptrauth(_arm64e)
7+
public let iOSPtrAuth: Bool = true
8+
#else
9+
public let iOSNotPtrAuth: Bool = true
10+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-compiler-version: Apple Swift version 5.2
3+
// swift-module-flags: -target arm64e-apple-macos10.13 -enable-library-evolution -swift-version 5 -module-name PtrAuthFramework
4+
import Swift
5+
6+
#if _ptrauth(_arm64e)
7+
public let macOSPtrAuth: Bool = true
8+
#else
9+
public let macOSNotPtrAuth: Bool = true
10+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// swift-interface-format-version: 1.0
2+
// swift-compiler-version: Apple Swift version 5.2
3+
// swift-module-flags: -target arm64e-apple-tvos13.0 -enable-library-evolution -swift-version 5 -module-name PtrAuthFramework
4+
import Swift
5+
6+
// Intentionally incompatible
7+
#if _ptrauth(_arm64e)
8+
public let tvOSPtrAuth: Bool = true
9+
#else
10+
public let tvOSNotPtrAuth: Bool = true
11+
#endif
Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,42 @@
1-
// RUN: not %target-typecheck-verify-swift -target arm64e-apple-ios13.0 -F %S/Inputs 2>&1 | %FileCheck %s
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-typecheck-verify-swift -F %S/Inputs -module-cache-path %t -verify-ignore-unknown -Rmodule-interface-rebuild
23

3-
// REQUIRES: OS=ios
4-
// UNSUPPORTED: OS=maccatalyst
4+
// PtrAuthFramework only supports these OSes.
5+
//
6+
// REQUIRES: OS=tvos || OS=macosx || OS=ios
57

6-
import DummyFramework
7-
// CHECK: no such module 'DummyFramework'
8+
// When run on arm64, this tests that we fall back to the arm64e interface, but
9+
// build it with `#if _ptrauth(_arm64e)` off.
10+
//
11+
// When run on arm64e, this tests that we build the same interface with
12+
// `#if _ptrauth(_arm64e)` on.
13+
//
14+
// REQUIRES: CPU=arm64 || CPU=arm64e
15+
16+
import PtrAuthFramework // expected-remark{{rebuilding module 'PtrAuthFramework' from interface}}
17+
18+
#if os(iOS)
19+
20+
#if _ptrauth(_arm64e)
21+
public let x: Bool = iOSPtrAuth
22+
#else
23+
public let x: Bool = iOSNotPtrAuth
24+
#endif
25+
26+
#elseif os(macOS)
27+
28+
#if _ptrauth(_arm64e)
29+
public let x: Bool = macOSPtrAuth
30+
#else
31+
public let x: Bool = macOSNotPtrAuth
32+
#endif
33+
34+
#else
35+
36+
#if _ptrauth(_arm64e)
37+
public let x: Bool = tvOSPtrAuth
38+
#else
39+
public let x: Bool = tvOSNotPtrAuth
40+
#endif
41+
42+
#endif

0 commit comments

Comments
 (0)