Skip to content

[NativeAOT] Migrate shared GC logging to printf#12210

Merged
jonathanpeppers merged 27 commits into
mainfrom
jonathanpeppers-native-printf-logging-next
Jul 24, 2026
Merged

[NativeAOT] Migrate shared GC logging to printf#12210
jonathanpeppers merged 27 commits into
mainfrom
jonathanpeppers-native-printf-logging-next

Conversation

@jonathanpeppers

@jonathanpeppers jonathanpeppers commented Jul 22, 2026

Copy link
Copy Markdown
Member

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 main after its stacked dependencies merged.

Part of #12139.

Scope

  • migrate temporary-peer capacity and GC cleanup summary diagnostics in bridge-processing.cc;
  • migrate debug-only missing Java method diagnostics while preserving null-safe class-name output;
  • migrate reference-log file open and invalid-path diagnostics in logger.cc;
  • return static string-segment error messages as C strings for direct %s logging;
  • remove six std::format-style logging instantiations from NativeAOT-reachable shared sources.

Behavior preservation

  • logging categories and existing debug/category gates are unchanged;
  • size_t values use %zu;
  • raw nullable class names continue through optional_string();
  • non-owning path and file-kind views use bounded %.*s output;
  • static string-segment error messages use %s without an intermediate std::string_view;
  • message text, punctuation, source locations, and control flow are unchanged;
  • warning and error diagnostics remain unconditional, while debug and info diagnostics retain helper-level category gating.

Non-goals

  • This PR does not change the logging implementation or declarations.
  • It does not migrate the nearby gref std::format strings passed to OSBridge::_monodroid_gref_log; those feed a separate file/log pipeline and require a dedicated API design.
  • It does not touch formatting outside NativeAOT-reachable shared sources.

Validation

  • dotnet-local.cmd build src\native\native-nativeaot.csproj -p:AndroidSupportedTargetJitAbis=arm64-v8a
  • dotnet-local.cmd build src\native\native-clr.csproj -p:AndroidSupportedTargetJitAbis=arm64-v8a
  • git diff --check
  • focused review of printf types, category gating, null handling, bounded string views, and control flow

simonrozsival and others added 24 commits July 17, 2026 00:56
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
Copilot AI review requested due to automatic review settings July 22, 2026 19: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.

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.cc to log_*f() with %zu for size_t and %s via optional_string() for nullable class names.
  • Converted reference-log file open and invalid-path diagnostics in logger.cc to log_*f() using bounded %.*s formatting for std::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
@jonathanpeppers

Copy link
Copy Markdown
Member Author

/review

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Android PR Reviewer completed successfully!

@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

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.ccmap_capacity, total, and alive are all size_t (lines 15, 580–581), so %zu is the correct specifier. optional_string(class_name) returns const char*, matching %s. Debug-only gating (#if ...) around the missing-method diagnostics is preserved.
  • logger.ccpath and file_kind are std::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 yields const char*, matching %s.
  • strings.hhto_string(string_segment_error) return-type change from std::string_view to const char* has exactly one caller (logger.cc:201), which is updated correctly. No other consumers depend on the old string_view return.
  • All log_*f overloads used exist in shared/log_functions.hh with __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 ⚠️ · 1 💡 (optional 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

Comment thread src/native/common/include/runtime-base/strings.hh Outdated
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
@jonathanpeppers jonathanpeppers added the drop-libcpp Work to remove the libc++ dependency from Android NativeAOT label Jul 22, 2026
Base automatically changed from dev/simonrozsival/nativeaot-runtime-printf-logging to main July 23, 2026 16:14
@jonathanpeppers jonathanpeppers added the ready-to-review This PR is ready to review/merge, I think any CI failures are just flaky (ignorable). label Jul 23, 2026
@jonathanpeppers

Copy link
Copy Markdown
Member Author

The one test failure was addressed in another PR:

image

@jonathanpeppers
jonathanpeppers merged commit 1cac38f into main Jul 24, 2026
42 of 44 checks passed
@jonathanpeppers
jonathanpeppers deleted the jonathanpeppers-native-printf-logging-next branch July 24, 2026 13:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

4 participants