[WIP] Drop libc++ from Android NativeAOT linking#11311
Draft
simonrozsival wants to merge 7 commits into
Draft
Conversation
MAUI net11.0 currently generates net11.0-android36.1, but dotnet/android now produces Android 37 packs only. Copy a checked-in Directory.Build.Override.props into the MAUI checkout so the integration leg packs net11.0-android37.0 until dotnet/maui updates net11.0. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
MAUI's Cake script deletes Directory.Build.Override.props when no platform switch is passed, so copying an override file does not survive until dotnet-pack. Apply a checked-in patch directly to the MAUI checkout instead. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Remove the explicit NativeAOT final-link dependency on libc++/libc++abi and keep the Android NativeAOT link guarded with -nostdlib++. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Member
Author
Emulator validation updateI tested the signed NativeAOT + trimmable typemap sample APK on an arm64 emulator after rebuilding/overlaying the local validation packs. What works:
Important caveats:
|
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…iveaot-drop-libcpp # Conflicts: # external/Java.Interop # src/Mono.Android/Mono.Android.csproj # src/Xamarin.Android.Build.Tasks/Microsoft.Android.Sdk/targets/Microsoft.Android.Sdk.NativeAOT.targets
The merge of origin/main brought in PR #11256, which switched native linking from an inline `clang` Exec invocation to the LinkNativeAotSharedLibrary task driving `ld.lld` directly. Taking origin/main's version of Microsoft.Android.Sdk.NativeAOT.targets re-introduced the explicit `libc++_static.a` and `libc++abi.a` includes in @(_NdkLibs), reversing the branch's purpose. Drop those includes. With ld.lld invoked directly, no C++ stdlib is linked unless we list it explicitly, so `-nostdlib++` (a clang driver flag) is not needed. cxx-shims.cc continues to provide the minimal C++ runtime shims required by NativeAOT. Also update the now-stale `LinkStandardCPlusPlusLibrary>false` and `libstdc++compat.a` removal comments. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
NativeAOT roots array typemap dictionaries from the root typemap assembly, which references the per-assembly __ArrayMapRank* anchor types. Keep those anchors public so the generated metadata is valid across assembly boundaries. Add test coverage for the emitted visibility. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This draft explores removing the Android NativeAOT link-time dependency on libc++.
The branch now:
libc++_static.aandlibc++abi.alink inputs;ld.lld/NativeLinkerpath frommain;__ArrayMapRank*typemap anchors public, because the root typemap assembly references them across assembly boundaries.Context
This is related to #9926 and the NDK r29 NativeAOT linking work.
The relevant background is that the NativeAOT Android runtime should avoid depending on libc++ instead of working around duplicate
libunwindsymbols or switching to shared libc++. Related references:libunwindsymbol failure and discusses removing the libc++ dependency from Android NativeAOT.Size impact
Earlier measurements on this branch used
samples/NativeAOT/NativeAOT.csprojbuilt in Release with_AndroidTypeMapImplementation=trimmable.libNativeAOT.solibNativeAOT.solibNativeAOT.sois the per-ABI native shared library packaged in the APK, for examplelib/arm64-v8a/libNativeAOT.so. It is not the whole Android app package; the APK also contains manifest, resources, Java stubs/classes, signatures, and packaging assets.Validation
Validated locally during the latest iteration:
dotnet test tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests/Microsoft.Android.Sdk.TrimmableTypeMap.Tests.csproj --no-restore— 457 passed.Previous branch validation:
src/Xamarin.Android.Build.Tasks/Xamarin.Android.Build.Tasks.csproj;android-arm64andandroid-x64;samples/NativeAOT/NativeAOT.csprojwith_AndroidTypeMapImplementation=trimmableforandroid-arm64andandroid-x64;libc++/libc++abiinputs;llvm-nm -ureports no undefined C++ runtime-looking symbols in the finallibNativeAOT.sooutputs;libNativeAOT.soloaded without libc++,MainApplicationandMainActivitynative callbacks ran,MainActivity.OnCreate()logged, and the process remained alive.Current status
The PR is still draft/WIP. A CI follow-up fixed the NativeAOT trimmable typemap build failures caused by private
__ArrayMapRank*anchors producing invalid NativeAOT metadata and unresolved link symbols.The x64 APK builds and packages without libc++, but local x64 runtime validation still needs an x64 emulator host because Android emulator x86_64 system images are not accepted on Apple Silicon/aarch64 hosts.