diff --git a/Sources/Testing/SourceAttribution/Backtrace.swift b/Sources/Testing/SourceAttribution/Backtrace.swift index 552e16d68..52b6f0553 100644 --- a/Sources/Testing/SourceAttribution/Backtrace.swift +++ b/Sources/Testing/SourceAttribution/Backtrace.swift @@ -40,16 +40,6 @@ public struct Backtrace: Sendable { self.addresses = addresses.map { Address(UInt(bitPattern: $0)) } } -#if os(Android) && !SWT_NO_DYNAMIC_LINKING - /// The `backtrace()` function. - /// - /// This function was added to Android with API level 33, which is higher than - /// our minimum deployment target, so we look it up dynamically at runtime. - private static let _backtrace = symbol(named: "backtrace").map { - castCFunction(at: $0, to: (@convention(c) (UnsafeMutablePointer, CInt) -> CInt).self) - } -#endif - /// Get the current backtrace. /// /// - Parameters: @@ -77,8 +67,10 @@ public struct Backtrace: Sendable { } #elseif os(Android) #if !SWT_NO_DYNAMIC_LINKING - if let _backtrace { - initializedCount = .init(clamping: _backtrace(addresses.baseAddress!, .init(clamping: addresses.count))) + if #available(Android 33, *) { + initializedCount = addresses.withMemoryRebound(to: UnsafeMutableRawPointer.self) { addresses in + .init(clamping: backtrace(addresses.baseAddress!, .init(clamping: addresses.count))) + } } #endif #elseif os(Linux) || os(FreeBSD) || os(OpenBSD)