Skip to content

[NativeAOT] Migrate runtime utility logging to printf#12148

Open
simonrozsival wants to merge 3 commits into
dev/simonrozsival/nativeaot-printf-loggingfrom
dev/simonrozsival/nativeaot-runtime-printf-logging
Open

[NativeAOT] Migrate runtime utility logging to printf#12148
simonrozsival wants to merge 3 commits into
dev/simonrozsival/nativeaot-printf-loggingfrom
dev/simonrozsival/nativeaot-runtime-printf-logging

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Summary

Continue the printf-style native logging migration started by #12140.

This stacked PR converts formatted logging in NativeAOT-reachable shared runtime utilities to the log_*f() and Helpers::abort_applicationf() APIs introduced by #12140, avoiding additional std::format instantiations in those paths.

Base/dependency: #12140 must merge first. This PR targets dev/simonrozsival/nativeaot-printf-logging rather than main so its diff contains only this second-stage migration.

Part of #12139.

Scope

The change is deliberately limited to four files that are compiled into the Android NativeAOT host:

  • src/native/clr/include/runtime-base/util.hh
  • src/native/clr/runtime-base/util.cc
  • src/native/clr/runtime-base/android-system-shared.cc
  • src/native/clr/host/host-shared.cc

These files do not overlap the currently open sibling work:

Changes

Runtime and environment utilities

  • migrate file-stat, directory-creation, fopen, chmod, and fchmod diagnostics to printf-style logging;
  • migrate environment-variable set/create diagnostics while preserving bounded std::string_view output through %.*s;
  • preserve null-safe output for raw C-string inputs through optional_string().

Memory-mapped APK diagnostics

  • replace the std::format allocation in the fatal mmap() error path with Helpers::abort_applicationf();
  • migrate the detailed mmap range/length diagnostic to %p, %zu, %d, and %.*s formatting;
  • migrate the debug-only non-ELF diagnostic without assuming that its std::string_view is NUL-terminated.

Android system properties

  • migrate the property-buffer size warning using the correct size_t format;
  • migrate invalid debug.mono.max_grefc values while preserving the compile-time property-name length;
  • migrate the effective maximum-gref count using the correct long format.

Shared host diagnostics

  • migrate Java-class-name lookup failures, including pointer output, to printf-style logging.

Formatting and behavior preservation

  • raw pointers use %p and are explicitly passed as void*;
  • size_t uses %zu, long uses %ld, and descriptors use %d;
  • non-owning strings use %.*s with an explicit length;
  • debug/info category gating remains inside the [Native] Add printf-style native logging #12140 helpers;
  • warning/error/fatal messages remain unconditional, matching the existing logging behavior;
  • no logging category, error path, JNI behavior, or control flow is changed.

Non-goals

Validation

The higher-level native project builds were also attempted, but the local Gradle 9.4.1 distribution failed while starting the unrelated manifestmerger build, before native compilation. The direct checks above use the repository-generated production NDK compile commands and generated headers.

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

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 libc++ reduction work by migrating remaining formatted logging in NativeAOT-reachable shared runtime utilities away from std::format/{}-style logging and onto the printf-checked log_*f() and Helpers::abort_applicationf() APIs introduced in the stacked dependency PR #12140.

Changes:

  • Convert runtime utility and environment diagnostics to log_*f() with bounded %.*s for std::string_view and null-safe optional_string() for const char*.
  • Replace a fatal mmap() failure path’s std::format allocation with Helpers::abort_applicationf() and migrate detailed mmap diagnostics to printf formatting.
  • Migrate Android system-property and shared host (JNI class-name lookup) diagnostics to log_*f() with correct format specifiers.
Show a summary per file
File Description
src/native/clr/runtime-base/util.cc Migrates directory creation, fopen, and chmod/fchmod error logging to log_*f().
src/native/clr/runtime-base/android-system-shared.cc Migrates system property warnings and max-gref override diagnostics to log_warnf() with correct size_t/long formats.
src/native/clr/include/runtime-base/util.hh Migrates env-var and mmap-related diagnostics to log_*f() / abort_applicationf(), using bounded %.*s formatting.
src/native/clr/host/host-shared.cc Migrates Java class-name lookup failures to log_errorf() (including %p).

Copilot's findings

  • Files reviewed: 4/4 changed files
  • Comments generated: 0

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
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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants