Skip to content

Commit 7a0b4f9

Browse files
filipnavarajkotas
andauthored
[NativeAOT] Do not use private APIs on iOS/macOS (dotnet#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 <[email protected]> --------- Co-authored-by: Jan Kotas <[email protected]>
1 parent cf46263 commit 7a0b4f9

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets

+3
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,9 @@ The .NET Foundation licenses this file to you under the MIT license.
6969
<NetCoreAppNativeLibrary Include="System.Security.Cryptography.Native.Apple" Condition="'$(_IsApplePlatform)' == 'true'" />
7070
<!-- Not compliant for iOS-like platforms -->
7171
<NetCoreAppNativeLibrary Include="System.Security.Cryptography.Native.OpenSsl" Condition="'$(StaticOpenSslLinking)' != 'true' and '$(_IsiOSLikePlatform)' != 'true'" />
72+
<NetCoreAppNativeLibrary Include="icudata" Condition="'$(_IsiOSLikePlatform)' == 'true' and '$(InvariantGlobalization)' != 'true'" />
73+
<NetCoreAppNativeLibrary Include="icui18n" Condition="'$(_IsiOSLikePlatform)' == 'true' and '$(InvariantGlobalization)' != 'true'" />
74+
<NetCoreAppNativeLibrary Include="icuuc" Condition="'$(_IsiOSLikePlatform)' == 'true' and '$(InvariantGlobalization)' != 'true'" />
7275
</ItemGroup>
7376

7477
<ItemGroup>

src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp

+32-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
#define UNW_STEP_SUCCESS 1
99
#define UNW_STEP_END 0
1010

11-
#ifdef __APPLE__
11+
#if defined(TARGET_APPLE)
1212
#include <mach-o/getsect.h>
1313
#endif
1414

@@ -883,3 +883,34 @@ bool UnwindHelpers::GetUnwindProcInfo(PCODE pc, UnwindInfoSections &uwInfoSectio
883883
uc.getInfo(procInfo);
884884
return true;
885885
}
886+
887+
#if defined(TARGET_APPLE)
888+
// Apple considers _dyld_find_unwind_sections to be private API that cannot be used
889+
// by apps submitted to App Store and TestFlight, both for iOS-like and macOS platforms.
890+
// We reimplement it using public API surface.
891+
//
892+
// Ref: https://github.com/llvm/llvm-project/blob/c37145cab12168798a603e22af6b6bf6f606b705/libunwind/src/AddressSpace.hpp#L67-L93
893+
bool _dyld_find_unwind_sections(void* addr, dyld_unwind_sections* info)
894+
{
895+
// Find mach-o image containing address.
896+
Dl_info dlinfo;
897+
if (!dladdr(addr, &dlinfo))
898+
return false;
899+
900+
const struct mach_header_64 *mh = (const struct mach_header_64 *)dlinfo.dli_fbase;
901+
902+
// Initialize the return struct
903+
info->mh = (const struct mach_header *)mh;
904+
info->dwarf_section = getsectiondata(mh, "__TEXT", "__eh_frame", &info->dwarf_section_length);
905+
info->compact_unwind_section = getsectiondata(mh, "__TEXT", "__unwind_info", &info->compact_unwind_section_length);
906+
907+
if (!info->dwarf_section) {
908+
info->dwarf_section_length = 0;
909+
}
910+
if (!info->compact_unwind_section) {
911+
info->compact_unwind_section_length = 0;
912+
}
913+
914+
return true;
915+
}
916+
#endif

0 commit comments

Comments
 (0)