mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
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
This commit is contained in:
@@ -432,7 +432,7 @@ func isValidPointerForNativeRetain(object: Builtin.RawPointer) -> Bool {
|
||||
#if _pointerBitWidth(_64)
|
||||
if unsafe (objectBits & HeapObject.immortalObjectPointerBit) != 0 { return false }
|
||||
#endif
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -750,3 +750,19 @@ func _embeddedReportFatalErrorInFile(prefix: StaticString, message: UnsafeBuffer
|
||||
if message.count > 0 { print(": ", terminator: "") }
|
||||
unsafe print(message)
|
||||
}
|
||||
|
||||
// CXX Exception Personality
|
||||
|
||||
public typealias _Unwind_Action = CInt
|
||||
public typealias _Unwind_Reason_Code = CInt
|
||||
|
||||
@c @used
|
||||
public func _swift_exceptionPersonality(
|
||||
version: CInt,
|
||||
actions: _Unwind_Action,
|
||||
exceptionClass: UInt64,
|
||||
exceptionObject: UnsafeMutableRawPointer,
|
||||
context: UnsafeMutableRawPointer
|
||||
) -> _Unwind_Reason_Code {
|
||||
fatalError("C++ exception handling detected but the Embedded Swift runtime does not support exceptions")
|
||||
}
|
||||
|
||||
17
test/embedded/linkage/cxx-exceptions.swift
Normal file
17
test/embedded/linkage/cxx-exceptions.swift
Normal file
@@ -0,0 +1,17 @@
|
||||
// RUN: %empty-directory(%t)
|
||||
// RUN: %target-swift-frontend %s -enable-experimental-feature Embedded -O -c -o %t/main.o -cxx-interoperability-mode=default
|
||||
// RUN: %target-clang %target-clang-resource-dir-opt %t/main.o -o %t/a.out -dead_strip
|
||||
// RUN: %target-run %t/a.out | %FileCheck %s
|
||||
|
||||
// REQUIRES: swift_in_compiler
|
||||
// REQUIRES: executable_test
|
||||
// REQUIRES: swift_feature_Embedded
|
||||
|
||||
@_expose(Cxx)
|
||||
func f1() {
|
||||
print("OK!")
|
||||
}
|
||||
|
||||
f1()
|
||||
|
||||
// CHECK: OK!
|
||||
Reference in New Issue
Block a user