[NativeAOT] Reduce owning C++ standard library state#12142
Open
simonrozsival wants to merge 5 commits into
Open
[NativeAOT] Reduce owning C++ standard library state#12142simonrozsival wants to merge 5 commits into
simonrozsival wants to merge 5 commits into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 187b207a-083b-461e-9071-e9aab61c9d07
Contributor
There was a problem hiding this comment.
Pull request overview
Reduces owning C++ standard-library state reachable from the Android NativeAOT host to help shrink binaries and remove libc++-related symbol roots (part of #12139).
Changes:
- Replaces GC-bridge temporary peer storage from
std::unordered_maptotsl::robin_map, and tightens lifetime cleanup. - Removes/avoids owning
std::stringstorage in logging paths and source-location function-name parsing (moves to boundedstd::string_viewparsing). - Introduces NativeAOT-specific bounded storage for Android override/native-library paths (while keeping CoreCLR behavior).
Show a summary per file
| File | Description |
|---|---|
| src/native/common/include/shared/cpp-util.hh | Reworks function-name extraction to bounded std::string_view parsing and updates formatted error messages to avoid owning strings. |
| src/native/CMakeLists.txt | Makes robin-map include path available to CLR/NativeAOT targets and unconditionally defines ROBIN_MAP_DIR. |
| src/native/clr/runtime-base/logger.cc | Switches gref/lref path storage away from owning std::string to explicit malloc/free management and uses bounded path building. |
| src/native/clr/include/runtime-base/android-system.hh | Adds NativeAOT-specific bounded path storage/return types for override/native-library directories. |
| src/native/clr/include/host/bridge-processing-shared.hh | Swaps temporary peer map to tsl::robin_map and adds guarded include/diagnostic handling. |
| src/native/clr/host/bridge-processing.cc | Updates temporary-peer insertion/iteration for robin-map and ensures local refs are deleted before clearing the map. |
Copilot's findings
- Files reviewed: 6/6 changed files
- Comments generated: 1
Use the negative-index TemporaryPeerMap approach from #11311 so CoreCLR and NativeAOT no longer need robin-map for GC bridge processing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Move the TemporaryPeerMap changes to #12145 so this branch only contains the remaining owning-state cleanup. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Member
Author
CI failure analysisThe public The sole failure was The final link reports duplicate symbols such as
This is the same pre-existing collision independently reproduced by #12140 build #1513800. It is unrelated to this PR's container/string cleanup and provides further evidence for #12139. |
This was referenced Jul 17, 2026
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
This was referenced Jul 17, 2026
Preserve the NativeAOT fixed-buffer state while keeping the new CoreCLR application code-cache directory state behind the non-NativeAOT path. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 3f8e6959-6647-4d07-ab74-492a1e60d3ec
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
Reduce owning C++ standard-library state reachable from the Android NativeAOT host.
This PR is intentionally limited to three areas:
The GC bridge temporary-peer cleanup was split into #12145. The two PRs are independent and can merge in either order.
Part of #12139, which tracks removing the Android NativeAOT app's libc++ dependency.
Motivation
The NativeAOT host shares a significant amount of code with CoreCLR. Several shared helpers still introduced owning C++ standard-library objects or template instantiations into the NativeAOT build even though the NativeAOT path only needs bounded, process-lifetime data:
std::stringinstances;std::vector<std::string>plus an owning result string.These are small individually, but each can root additional constructors, destructors, allocation helpers, exception machinery, or ranges/container implementation code in the final NativeAOT binary.
Changes
1. Reference logging paths
File:
src/native/clr/runtime-base/logger.ccstd::stringinstances forgref_fileandlref_filewith nullable C-string pointers;set_log_file()to perform overflow-checked allocation, copy the selected path, NUL-terminate it, and release the previous value;gref=/lref=values asstd::string_viewinstead of returning a pointer into the parser without a length;FILE*;<override>/grefs.txtin boundeddynamic_local_string<SENSIBLE_PATH_MAX>storage instead of an owningstd::string.The observable logging behavior is unchanged: configured paths are tried first, fallback files remain under the override directory, and file-open failures continue to be logged by existing helpers.
2. NativeAOT Android path storage
File:
src/native/clr/include/runtime-base/android-system.hhUnder
XA_HOST_NATIVEAOT:primary_override_dirandnative_libraries_dirin fixed process-lifetime buffers sized byConstants::SENSIBLE_PATH_MAX;std::string, array, span, update-directory, and debug-property behavior unchanged.This is a compile-time host specialization, not a runtime behavior switch.
3. Source-location function-name parsing
File:
src/native/common/include/shared/cpp-util.hhget_function_name();std::string_view;%.*s, avoiding construction of a temporary result string.Malformed or empty signatures continue to fall back safely rather than being dereferenced blindly.
Scope and non-goals
Expected impact
basic_stringstorage and destructor roots from the NativeAOT logging/path code changed here;Exact archive/shared-library measurements will be refreshed after CI validates the final split revision.
Validation
The remaining three-file change was included in the earlier combined revision that passed:
git diff --check;src/native/native-nativeaot.csproj;src/native/native-clr.csproj;static_assertcoverage for ordinary functions, scoped methods, templates and GCC substitution suffixes, lambdas, free and scoped operators, malformed signatures, null, and empty input;CI is validating head
4412ea395.