Skip to content

Commit

Permalink
[NativeAOT] Do not use private APIs on iOS/macOS (#90430)
Browse files Browse the repository at this point in the history
* 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 <jkotas@microsoft.com>

---------

Co-authored-by: Jan Kotas <jkotas@microsoft.com>
  • Loading branch information
filipnavara and jkotas authored Aug 12, 2023
1 parent cf46263 commit 7a0b4f9
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ The .NET Foundation licenses this file to you under the MIT license.
<NetCoreAppNativeLibrary Include="System.Security.Cryptography.Native.Apple" Condition="'$(_IsApplePlatform)' == 'true'" />
<!-- Not compliant for iOS-like platforms -->
<NetCoreAppNativeLibrary Include="System.Security.Cryptography.Native.OpenSsl" Condition="'$(StaticOpenSslLinking)' != 'true' and '$(_IsiOSLikePlatform)' != 'true'" />
<NetCoreAppNativeLibrary Include="icudata" Condition="'$(_IsiOSLikePlatform)' == 'true' and '$(InvariantGlobalization)' != 'true'" />
<NetCoreAppNativeLibrary Include="icui18n" Condition="'$(_IsiOSLikePlatform)' == 'true' and '$(InvariantGlobalization)' != 'true'" />
<NetCoreAppNativeLibrary Include="icuuc" Condition="'$(_IsiOSLikePlatform)' == 'true' and '$(InvariantGlobalization)' != 'true'" />
</ItemGroup>

<ItemGroup>
Expand Down
33 changes: 32 additions & 1 deletion src/coreclr/nativeaot/Runtime/unix/UnwindHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define UNW_STEP_SUCCESS 1
#define UNW_STEP_END 0

#ifdef __APPLE__
#if defined(TARGET_APPLE)
#include <mach-o/getsect.h>
#endif

Expand Down Expand Up @@ -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

0 comments on commit 7a0b4f9

Please sign in to comment.