Skip to content

Commit 0f508f6

Browse files
committed
Add Embedded Swift Cxx exception personality
Users frequently run into a missing runtime symbol for Cxx exceptions (`_swift_exceptionPersonality`) when mixing Embedded Swift and Cxx with exceptions enabled. This leads to a confusing an hard to debug linker error. This commit adds an implementation of this function to the Embedded Swift runtime which simply fatal errors if a cxx exception is caught in a Swift frame. Issue: rdar://164423867 Issue: #85490
1 parent 3545603 commit 0f508f6

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

stdlib/public/core/EmbeddedRuntime.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,3 +579,19 @@ func _embeddedReportFatalErrorInFile(prefix: StaticString, message: UnsafeBuffer
579579
if message.count > 0 { print(": ", terminator: "") }
580580
unsafe print(message)
581581
}
582+
583+
// CXX Exception Personality
584+
585+
typealias _Unwind_Action = CInt
586+
typealias _Unwind_Reason_Code = CInt
587+
588+
@_cdecl("_swift_exceptionPersonality")
589+
func _swift_exceptionPersonality(
590+
version: CInt,
591+
actions: _Unwind_Action,
592+
exceptionClass: UInt64,
593+
exceptionObject: UnsafeMutableRawPointer,
594+
context: UnsafeMutableRawPointer
595+
) -> _Unwind_Reason_Code {
596+
fatalError("C++ exception handling detected but the Embedded Swift runtime does not support exceptions")
597+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// RUN: %empty-directory(%t)
2+
// RUN: %target-swift-frontend %s -enable-experimental-feature Embedded -O -c -o %t/main.o -cxx-interoperability-mode=default
3+
// RUN: %target-clang %target-clang-resource-dir-opt %t/main.o -o %t/a.out -dead_strip
4+
// RUN: %target-run %t/a.out | %FileCheck %s
5+
6+
// REQUIRES: swift_in_compiler
7+
// REQUIRES: executable_test
8+
// REQUIRES: swift_feature_Embedded
9+
10+
@_expose(Cxx)
11+
func f1() {
12+
print("OK!")
13+
}
14+
15+
f1()
16+
17+
// CHECK: OK!

0 commit comments

Comments
 (0)