Replace libc printf with eyalroz/printf and add streaming status formatting.#23694
Merged
Replace libc printf with eyalroz/printf and add streaming status formatting.#23694
Conversation
3c585a3 to
32777ac
Compare
…atting. Integrates eyalroz/printf as a vendored dependency to replace all libc snprintf/vsnprintf calls across the runtime. This gives us a consistent, portable printf implementation across all platforms (including embedded and bare-metal targets) with no platform-specific quirks. Beyond the drop-in replacement, this extends the status formatting API with streaming support: - Add iree_status_format_to: callback-based streaming formatter that avoids contiguous buffers and pre-measurement passes. The callback returns bool for flow control, enabling early termination on buffer full or allocation failure. - Add iree_string_builder_append_status: single-pass status-to-builder formatting via iree_status_format_to, resolving the status/string_builder dependency cycle that previously required a local copy in libhsa.c. - Rewrite iree_status_fprint to stream directly to FILE* with zero heap allocation (previously required a contiguous buffer). - Rewrite iree_status_to_string as single-pass using string builder instead of two-pass measure-then-format. - Fix va_copy usage in status allocation: use C99 va_copy for the two-pass measure-then-format pattern instead of calling va_start twice on the same parameter (implementation-defined behavior). - Convert Status::ToString (C++) and ApiStatusToString (Python bindings) from two-pass iree_status_format to single-pass iree_status_format_to. - Replace HIP dynamic_symbols.c allocate-format-free pattern with direct iree_string_builder_append_status (eliminates intermediate heap allocation). RISC-V toolchain fix: strip debug info from libgcc.a during CMake configure. eyalroz/printf's long double support in %Lf/%Le compiles va_arg(args, long double) which on RISC-V (128-bit quad precision) generates references to __extenddftf2/__trunctfdf2 soft-float builtins. These are resolved from libgcc.a, but the GCC 12.2.0-compiled objects in that archive contain DWARF debug info with relocation types 60/61 (in .debug_rnglists and .debug_loclists sections) that LLD cannot parse. The pre-built RISC-V toolchain lacks compiler-rt builtins as an alternative, so we strip the debug metadata from libgcc.a at configure time using llvm-objcopy --strip-debug. This preserves all code and data sections and is idempotent. The strip runs inside the RISCV_TOOLCHAIN_ROOT guard so users with their own toolchains are unaffected. Verified locally with the same toolchain used in CI (toolchain_iree_manylinux_2_28_20231012). Co-Authored-By: Claude <[email protected]>
32777ac to
abb5207
Compare
Collaborator
Author
|
mac failures are disk space, linux arm64 is unrelated and have a pending a fix. |
AaronStGeorge
pushed a commit
to ROCm/TheRock
that referenced
this pull request
Mar 16, 2026
## Summary - iree-org/iree#23694 (merged 2026-03-09) replaced all libc `snprintf`/`vsnprintf` calls in the IREE runtime with `eyalroz/printf`, making `third_party/printf` an unconditional build dependency (`printf::printf` is required by `iree::base`). - `third_party/printf` was missing from the default `--nested-submodules` list for `iree` in `fetch_sources.py`, causing it not to be fetched and the IREE build to fail. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: zjgarvey <[email protected]>
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.
Integrates eyalroz/printf as a vendored dependency to replace all libc snprintf/vsnprintf calls across the runtime. This gives us a consistent, portable printf implementation across all platforms (including embedded and bare-metal targets) with no platform-specific quirks.
Beyond the drop-in replacement, this extends the status formatting API with streaming support:
Add iree_status_format_to: callback-based streaming formatter that avoids contiguous buffers and pre-measurement passes. The callback returns bool for flow control, enabling early termination on buffer full or allocation failure.
Add iree_string_builder_append_status: single-pass status-to-builder formatting via iree_status_format_to, resolving the status/string_builder dependency cycle that previously required a local copy in libhsa.c.
Rewrite iree_status_fprint to stream directly to FILE* with zero heap allocation (previously required a contiguous buffer).
Rewrite iree_status_to_string as single-pass using string builder instead of two-pass measure-then-format.
Fix va_copy usage in status allocation: use C99 va_copy for the two-pass measure-then-format pattern instead of calling va_start twice on the same parameter (implementation-defined behavior).
Convert Status::ToString (C++) and ApiStatusToString (Python bindings) from two-pass iree_status_format to single-pass iree_status_format_to.
Replace HIP dynamic_symbols.c allocate-format-free pattern with direct iree_string_builder_append_status (eliminates intermediate heap allocation).
RISC-V toolchain fix: strip debug info from libgcc.a during CMake configure. eyalroz/printf's long double support in %Lf/%Le compiles
va_arg(args, long double)which on RISC-V (128-bit quad precision) generates references to__extenddftf2/__trunctfdf2soft-float builtins. These are resolved from libgcc.a, but the GCC 12.2.0-compiled objects in that archive contain DWARF debug info with relocation types 60/61 (in.debug_rnglistsand.debug_loclistssections) that LLD cannot parse. The pre-built RISC-V toolchain lacks compiler-rt builtins as an alternative, so we strip the debug metadata from libgcc.a at configure time usingllvm-objcopy --strip-debug. This preserves all code and data sections and is idempotent. The strip runs inside theRISCV_TOOLCHAIN_ROOTguard so users with their own toolchains are unaffected. Verified locally with the same toolchain used in CI (toolchain_iree_manylinux_2_28_20231012).ci-extra: all