From 7a0b4f99a3e90d24e152e5e077839971e7678cfd Mon Sep 17 00:00:00 2001 From: Filip Navara Date: Sat, 12 Aug 2023 20:54:12 +0200 Subject: [PATCH] [NativeAOT] Do not use private APIs on iOS/macOS (#90430) * Use custom implementation of _dyld_find_unwind_sections on Apple platforms since it's a private API and it blocks uploads to TestFlight, iOS App Store, and Mac App Store. * Link against local ICU libraries on iOS-like platforms * Update src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets * Add comment * Update src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp Co-authored-by: Jan Kotas --------- Co-authored-by: Jan Kotas --- .../Microsoft.NETCore.Native.Unix.targets | 3 ++ .../nativeaot/Runtime/unix/UnwindHelpers.cpp | 33 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) 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