Skip to content

[native] Stop linking libc++ into the CoreCLR and NativeAOT runtimes - #12572

Merged
simonrozsival merged 4 commits into
mainfrom
dev/simonrozsival/clr-stop-linking-libcpp
Sep 8, 2026
Merged

simonrozsival merged 4 commits into
mainfrom
dev/simonrozsival/clr-stop-linking-libcpp

Conversation

@simonrozsival

@simonrozsival simonrozsival commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

PR relationship: Stacked on #12571; #12523 is already merged. Rebased onto 79bc01fd8c from dev/simonrozsival/clr-assembly-store-strings, including the updated .apkdesc baselines.

Stop linking libc++ and libunwind into the CoreCLR and NativeAOT hosts now that their C++ runtime dependencies have been removed. This is the payoff PR for the CoreCLR half of #12533.

Changes

  • Make no-STL linking the shared default. CoreCLR and NativeAOT inherit default-common, which sets ANDROID_STL=none. mono-default-common overrides this to c++_static for MonoVM. Existing entry-point preset names are unchanged, and libc++ headers remain available for header-only facilities.
  • Disable Clang's implicit unwinder. Add --unwindlib=none when ANDROID_STL=none; disabling libc++ alone still lets Clang add libunwind.a implicitly.
  • Build the Xamarin unwinder only for MonoVM. Only Mono tracing consumes xa::unwind. Remove the unused CoreCLR/NativeAOT unwinder include references as well.
  • Remove obsolete runtime-pack archives. Stop shipping libc++_static.a, libc++abi.a, and libunwind.a, and stop including Xamarin unwinder archives in the CoreCLR pack. Clean obsolete copies from existing CoreCLR/NativeAOT pack directories and prevent stale build outputs from being copied back. MonoVM retains its existing dependencies.
  • Keep compiler support separate. Remove the C++/unwind archives from NativeRuntimeComponents and rename the remaining clang built-ins set to CompilerRuntime (compiler-rt).
  • Respect preset-only changes. Track generated CMakePresets.json in the runtime, archive-stub, and test-JNI configuration inputs. Remove the nonexistent clr/startup/CMakeLists.txt input that forced CoreCLR to reconfigure on every build.

Removing the libraries from the link command makes accidental reintroduction of a C++ runtime dependency a link error, rather than silently pulling libc++ back into the host.

Coverage and validation

Local Release SDK build and native builds completed:

  • CoreCLR and NativeAOT: Debug and Release hosts for ARM, ARM64, and x64. Generated linker commands, Clang's expanded commands, and host artifacts were inspected for libc++/libunwind dependencies.
  • MonoVM: Debug and Release builds for all four ABIs, retaining its existing libc++ and unwinder behavior.
  • CoreCLR prebuilt-runtime app smoke tests and NativeAOT app-link tests for all three supported ABIs. NativeAOT assertions require the host archive in the linker response and reject libc++/unwind archives.
  • Runtime-pack contents and stale-archive cleanup tests for both runtimes, plus NativeAOT workload/NDK linker tests.
  • All four CoreCLR APK-size cases pass with the rebased baselines. Existing NativeAOT size cases remain skipped by the test suite.
  • Preset invalidation checked for every native flavor: no-op configuration skips, touching the generated presets triggers reconfiguration, and the following no-op skips again.

Unified static CoreCLR linking

This PR does not enable _AndroidEnableNativeRuntimeLinking. An explicit attempt reached LinkNativeRuntime but failed: the current dotnet/runtime pack supplies libcoreclr.so, not the required libcoreclr_static.a, and the dormant path has additional unresolved dependencies. Consequently, CoreCLR app coverage is explicitly a smoke test using the prebuilt runtime, not a claim that unified static CoreCLR linking works.

@simonrozsival simonrozsival added the drop-libcpp Work to remove the libc++ dependency from Android NativeAOT label Aug 28, 2026
@simonrozsival
simonrozsival marked this pull request as ready for review August 28, 2026 14:00
Copilot AI lite review requested due to automatic review settings August 28, 2026 14:00
@simonrozsival
simonrozsival changed the base branch from dev/simonrozsival/clr-assembly-store-strings to dev/simonrozsival/fix-jstring-array-wrapper August 28, 2026 14:01
@simonrozsival simonrozsival reopened this Aug 28, 2026
@simonrozsival
simonrozsival changed the base branch from dev/simonrozsival/fix-jstring-array-wrapper to dev/simonrozsival/clr-assembly-store-strings August 28, 2026 14:05

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Review tier: Lite
Findings: 1 Low severity

New issues introduced by this change (1)
Severity Finding
Low severity src/​native/​CMakePresets.json.in — 💡 Maintainability — coreclr-default-common duplicates ANDROID_CPP_FEATURES from…
What changed in this PR

Removes the C++ standard library (libc++/libc++abi) and libunwind from the CoreCLR native host build and runtime packs now that the host no longer references the C++ standard library, while keeping compiler built-ins available for linking.

Changes:

  • Stop shipping/linking libc++/libc++abi/libunwind for CoreCLR by pruning NDK redistributables and runtime pack asset lists.
  • Introduce a CoreCLR-specific CMake preset baseline (ANDROID_STL=none) and adjust CoreCLR presets to inherit from it.
  • Narrow libunwind build to MonoVM-only and rename the native archive set from CplusPlusRuntime to CompilerRuntime (clang builtins).
File Description
src/​Xamarin.Android.Build.Tasks/​Utilities/​NativeRuntimeComponents.cs Renames the “c++” archive set to “compiler-rt” and removes libc++/libc++abi/libunwind archives from the known archive list.
src/​Xamarin.Android.Build.Tasks/​Tasks/​LinkNativeRuntime.cs Updates the set used for the “compiler support” archive group when ordering link inputs.
src/​native/​native.targets Stops copying NDK “CplusPlus” redistributable archives into CoreCLR runtime packs.
src/​native/​CMakePresets.json.in Adds coreclr-default-common preset with ANDROID_STL=none and updates CoreCLR presets to inherit from it.
src/​native/​CMakeLists.txt Builds common/libunwind only for MonoVM (where it is actually linked).
build-tools/​scripts/​Ndk.targets Removes libc++/libc++abi/libunwind from the NDK redistributable item list.
build-tools/​scripts/​Ndk.projitems Removes now-unused UnwindArchDir metadata.
build-tools/​create-packs/​Microsoft.Android.Runtime.proj Stops including NDK “CplusPlus” redistributables in the CoreCLR runtime pack assets.

Comment thread src/native/CMakePresets.json.in Resolved
@simonrozsival simonrozsival changed the title [native] Stop linking libc++ into the CoreCLR host [native] Stop linking libc++ into the CoreCLR and NativeAOT runtimes Aug 28, 2026
@simonrozsival
simonrozsival marked this pull request as draft September 3, 2026 06:13
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/clr-stop-linking-libcpp branch from 5f2f049 to 30ed2fc Compare September 8, 2026 12:23
@simonrozsival
simonrozsival marked this pull request as ready for review September 8, 2026 13:35
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12572

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No actionable code issues found. I reviewed the native preset split, explicit unwinder suppression, runtime-pack composition/cleanup, compiler-runtime link ordering, and the added CoreCLR/NativeAOT coverage. The latest Azure DevOps run is still in progress, so this review does not treat CI as green yet.

Generated by Android PR Reviewer for #12572 · gpt56 · 232.3 AIC · ⌖ 20.7 AIC · ⊞ 27.7K
Comment /review to run again

@simonrozsival simonrozsival added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Sep 8, 2026
stacked auto-merge was automatically disabled September 8, 2026 16:15

Pull Request is not mergeable

stacked auto-merge was automatically disabled September 8, 2026 16:17

Pull Request is not mergeable

stacked auto-merge was automatically disabled September 8, 2026 16:27

Pull Request is not mergeable

Base automatically changed from dev/simonrozsival/clr-assembly-store-strings to main September 8, 2026 16:32
simonrozsival and others added 4 commits September 8, 2026 18:32
Now that the CoreCLR host has zero references to the C++ standard
library, we can stop linking it in entirely.

* Add a `coreclr-default-common` CMake preset that sets
  `ANDROID_STL=none` (mirroring `nativeaot-default-common`, but
  without the STL).  This drops `-static-libstdc++` from the link
  line and replaces it with `-nostdlib++`.  Every CMake target
  already adds `${SYSROOT_CXX_INCLUDE_DIR}` explicitly, so the
  libc++ *headers* remain available.

* Stop building `common/libunwind` for CoreCLR.  Only `mono/tracing`
  links `xa::unwind`; the CoreCLR host built it and never used it.

* Stop shipping `libc++_static.a`, `libc++abi.a` and `libunwind.a`
  in the CoreCLR runtime pack, and drop them from the archive list
  used by `LinkNativeRuntime`.  `KnownSets.CplusPlusRuntime` now only
  holds the clang built-ins archive, so it is renamed to
  `KnownSets.CompilerRuntime`.

Verified on `android-arm64` Release: the host builds and links
cleanly with `ANDROID_STL=none`, `libnet-android.release.so` is
unchanged at 203,776 bytes, has zero undefined libc++/libunwind
symbols, and its `DT_NEEDED` list is unchanged.  MonoVM and NativeAOT
are unaffected.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0a35a0db-502d-48c0-8468-e73b5dd0ab2e
NativeAOT already had zero references to the C++ standard library
after #12523, so switching `nativeaot-default-common` to
`ANDROID_STL=none` costs nothing and turns any future libc++ use into
a link error instead of silently pulling the archive back in.

Verified on `android-arm64` Release with a clean configure: all three
NativeAOT artifacts -- `libnaot-android.release.so`,
`libnaot-android.release-static-release.a` and
`libxa-java-interop-release.a` -- are byte-for-byte identical to the
`c++_static` build.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 0a35a0db-502d-48c0-8468-e73b5dd0ab2e
…rchives

Suppress Clang's implicit libunwind dependency when ANDROID_STL is none. Preserve obsolete-archive cleanup for CoreCLR and NativeAOT packs, exclude stale Xamarin unwind archives, and verify app linking without C++ archives on all supported ABIs.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Separate CoreCLR prebuilt-runtime smoke coverage from NativeAOT archive-link checks, simplify runtime-pack assertions, and share no-STL defaults while isolating Mono's libc++ settings. Track generated presets in native configuration inputs, remove the nonexistent startup input, and drop unused unwinder include paths.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@simonrozsival
simonrozsival force-pushed the dev/simonrozsival/clr-stop-linking-libcpp branch from 30ed2fc to 1eb5203 Compare September 8, 2026 16:32
@simonrozsival

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Sep 8, 2026 •

Copy link
Copy Markdown
Contributor

✅ Android PR Reviewer completed successfully!

Generated by Android PR Reviewer for #12572

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ LGTM

The runtime split is coherent: CoreCLR and NativeAOT now use no-STL/no-unwinder linking, Mono retains libc++ and the Xamarin unwinder, compiler-rt remains available to static linking, and stale pack artifacts are explicitly removed. The PR narrative matches the implementation, and CI is green.

Findings: 0 errors · 0 warnings · 1 suggestion (test hardening)

Generated by Android PR Reviewer for #12572 · gpt56 · 142.4 AIC · ⌖ 8.86 AIC · ⊞ 25.7K
Comment /review to run again

@simonrozsival
simonrozsival merged commit 5a5b38a into main Sep 8, 2026
44 checks passed
@simonrozsival
simonrozsival deleted the dev/simonrozsival/clr-stop-linking-libcpp branch September 8, 2026 20:51
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 9, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

drop-libcpp Work to remove the libc++ dependency from Android NativeAOT ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants