[NativeAOT] Migrate shared GC logging to printf#12210
Conversation
Introduce printf-style native logging and abort helpers while preserving the existing std::format APIs for MonoVM and CoreCLR. Migrate the NativeAOT-specific formatted call sites to the new primitives. Refs #12139 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 187b207a-083b-461e-9071-e9aab61c9d07
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Keep the printf logging PR focused on the runtime implementation instead of introducing new host-native logging test infrastructure. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Convert NativeAOT-reachable environment, file, mmap, and shared-host diagnostics to the printf helpers introduced by #12140. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Convert host environment and integer parsing diagnostics to #12140 printf helpers while preserving MonoVM formatting branches. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: 70f63eb7-6599-414c-a947-d860705aa0fa
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0f0df1cb-536b-4c53-902e-cbbb9d8e9a15
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0f0df1cb-536b-4c53-902e-cbbb9d8e9a15
Resolve the logging declaration conflicts by retaining the lightweight canonical header, and preserve the reviewed NativeAOT status string constants. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0f0df1cb-536b-4c53-902e-cbbb9d8e9a15
Include the lightweight declaration header from both implementations and the printf-only abort helper so signatures remain checked without adding the std::format surface. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 0f0df1cb-536b-4c53-902e-cbbb9d8e9a15
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cd41994d-0fbf-4ce3-be3d-50e5ad9b74fb
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cd41994d-0fbf-4ce3-be3d-50e5ad9b74fb
Use the APK description produced by the failed macOS BuildReleaseArm64 XForms CoreCLR test in Azure DevOps build 1520455. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: cd41994d-0fbf-4ce3-be3d-50e5ad9b74fb
Convert the remaining std::format-style GC bridge and logger diagnostics compiled into the NativeAOT host to the canonical printf logging helpers. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 13af6b96-9e20-422c-b3ba-8cba7f1aa5bb
There was a problem hiding this comment.
Pull request overview
This PR continues the NativeAOT printf-style logging migration by converting remaining std::format-style formatted diagnostics in NativeAOT-reachable shared sources (GC bridge paths and reference-log setup) to the log_*f() printf helpers, while preserving existing category gating and null-safe string handling.
Changes:
- Converted GC bridge diagnostics in
bridge-processing.cctolog_*f()with%zuforsize_tand%sviaoptional_string()for nullable class names. - Converted reference-log file open and invalid-path diagnostics in
logger.cctolog_*f()using bounded%.*sformatting forstd::string_view.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
src/native/clr/runtime-base/logger.cc |
Migrates reference-log file path diagnostics from {} formatting to bounded printf-style logging. |
src/native/clr/host/bridge-processing.cc |
Migrates GC bridge temporary-peer/local-capacity and GC cleanup summary diagnostics to printf-style logging. |
Return static segment error messages as C strings so printf logging can consume them directly without a string_view. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 13af6b96-9e20-422c-b3ba-8cba7f1aa5bb
|
/review |
|
✅ Android PR Reviewer completed successfully! |
There was a problem hiding this comment.
✅ LGTM
Clean, well-scoped continuation of the printf-style native logging migration. I verified the changes independently against the full source before reading the description.
Verification highlights:
bridge-processing.cc—map_capacity,total, andaliveare allsize_t(lines 15, 580–581), so%zuis the correct specifier.optional_string(class_name)returnsconst char*, matching%s. Debug-only gating (#if ...) around the missing-method diagnostics is preserved.logger.cc—pathandfile_kindarestd::string_view; the%.*s+static_cast<int>(len)+.data()pattern is the correct way to print a non-null-terminated view.to_string(file_name.error())now yieldsconst char*, matching%s.strings.hh—to_string(string_segment_error)return-type change fromstd::string_viewtoconst char*has exactly one caller (logger.cc:201), which is updated correctly. No other consumers depend on the oldstring_viewreturn.- All
log_*foverloads used exist inshared/log_functions.hhwith__attribute__((format(printf,...))), so the compiler validates the format strings — mismatches would fail the build. - Message text, categories, punctuation, and control flow are unchanged, as claimed.
CI: dotnet-android completed neutral (not a failure); license/cla passed. No PR-caused failures.
Counts: 0 ❌ · 0 constexpr on to_string). Nice, mechanically-faithful migration.
Generated by Android PR Reviewer for #12210 · 65.9 AIC · ⌖ 12.8 AIC · ⊞ 6.8K
Comment /review to run again
Express the static string-segment error mapping as a compile-time function now that it returns string literals. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: 13af6b96-9e20-422c-b3ba-8cba7f1aa5bb

Summary
Continue the printf-style native logging migration by converting the remaining formatted diagnostics in the shared GC bridge and logger setup paths compiled into the NativeAOT host.
This PR follows the runtime utility migration merged in #12148 and reuses the canonical shared printf declarations established by #12155. It now targets
mainafter its stacked dependencies merged.Part of #12139.
Scope
bridge-processing.cc;logger.cc;%slogging;std::format-style logging instantiations from NativeAOT-reachable shared sources.Behavior preservation
size_tvalues use%zu;optional_string();%.*soutput;%swithout an intermediatestd::string_view;Non-goals
std::formatstrings passed toOSBridge::_monodroid_gref_log; those feed a separate file/log pipeline and require a dedicated API design.Validation
dotnet-local.cmd build src\native\native-nativeaot.csproj -p:AndroidSupportedTargetJitAbis=arm64-v8adotnet-local.cmd build src\native\native-clr.csproj -p:AndroidSupportedTargetJitAbis=arm64-v8agit diff --check