diff --git a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets index 2bfc05597c968..409fcb654e919 100644 --- a/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets +++ b/src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets @@ -69,6 +69,9 @@ The .NET Foundation licenses this file to you under the MIT license. + + + diff --git a/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp b/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp index 9d12e7a91933f..c1a20ad92fde2 100644 --- a/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp +++ b/src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp @@ -8,7 +8,7 @@ #define UNW_STEP_SUCCESS 1 #define UNW_STEP_END 0 -#ifdef __APPLE__ +#if defined(TARGET_APPLE) #include #endif @@ -883,3 +883,34 @@ bool UnwindHelpers::GetUnwindProcInfo(PCODE pc, UnwindInfoSections &uwInfoSectio uc.getInfo(procInfo); return true; } + +#if defined(TARGET_APPLE) +// Apple considers _dyld_find_unwind_sections to be private API that cannot be used +// by apps submitted to App Store and TestFlight, both for iOS-like and macOS platforms. +// We reimplement it using public API surface. +// +// Ref: https://github.com/llvm/llvm-project/blob/c37145cab12168798a603e22af6b6bf6f606b705/libunwind/src/AddressSpace.hpp#L67-L93 +bool _dyld_find_unwind_sections(void* addr, dyld_unwind_sections* info) +{ + // Find mach-o image containing address. + Dl_info dlinfo; + if (!dladdr(addr, &dlinfo)) + return false; + + const struct mach_header_64 *mh = (const struct mach_header_64 *)dlinfo.dli_fbase; + + // Initialize the return struct + info->mh = (const struct mach_header *)mh; + info->dwarf_section = getsectiondata(mh, "__TEXT", "__eh_frame", &info->dwarf_section_length); + info->compact_unwind_section = getsectiondata(mh, "__TEXT", "__unwind_info", &info->compact_unwind_section_length); + + if (!info->dwarf_section) { + info->dwarf_section_length = 0; + } + if (!info->compact_unwind_section) { + info->compact_unwind_section_length = 0; + } + + return true; +} +#endif