From 37eec5aaa1eeff3fa7995585229c03bf668c7ec4 Mon Sep 17 00:00:00 2001 From: Robert Allan James Date: Tue, 11 Aug 2026 11:14:05 -0400 Subject: [PATCH] starkernel: shim.c -- backfill freestanding putc()/getc() FABRIC.md item 4.5d: GCC's -O2 folds putchar(c)/fputc(c,stdout) call sites into putc(c,stdout), and getchar() into getc(stdin) -- neither symbol was ever needed at -O0 because that fold pass is inactive there. Both are thin wrappers reusing the existing putchar()/getchar() implementations exactly (putc -> console_putc via putchar; getc -> the existing "no stdin in kernel" -1/EOF stub via getchar), not new behavior. Harmless at the current -O0 build (nothing calls these symbols directly at -O0); this is prep for enabling optimization, verified against a clean amd64 boot at unchanged -O0. Co-Authored-By: Claude Sonnet 5 --- src/starkernel/vm/host/shim.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/starkernel/vm/host/shim.c b/src/starkernel/vm/host/shim.c index 14e0fb2..2d26879 100644 --- a/src/starkernel/vm/host/shim.c +++ b/src/starkernel/vm/host/shim.c @@ -1098,6 +1098,11 @@ int vfprintf(FILE *stream, const char *fmt, va_list args) { int puts(const char *s) { console_println(s ? s : ""); return 0; } /** @brief Kernel @c putchar(): emit one character to the console; returns @p c. */ int putchar(int c) { console_putc((char)c); return c; } +/** @brief Kernel @c putc(): ignores stream, same as @c putchar(). GCC's -O2 + * folds @c putchar(c) / @c fputc(c, stdout) call sites into @c putc(c, stdout) + * (FABRIC.md item 4.5d) -- this symbol was never needed at -O0 because that + * fold pass is inactive there. */ +int putc(int c, FILE *stream) { (void)stream; return putchar(c); } /** @brief Kernel @c fflush(): no-op (console writes are synchronous); returns 0. */ int fflush(FILE *stream) { (void)stream; return 0; } /** @brief Kernel @c fputs(): ignores stream, prints @p s + newline to console. */ @@ -1204,6 +1209,11 @@ const unsigned short ** __ctype_b_loc(void) { /** @brief Kernel @c getchar(): always returns -1 (EOF) — no stdin in kernel. */ int getchar(void) { return -1; } +/** @brief Kernel @c getc(): ignores stream, same as @c getchar(). GCC's -O2 + * folds @c getchar() call sites into @c getc(stdin) (FABRIC.md item 4.5d) -- + * this symbol was never needed at -O0 because that fold pass is inactive + * there. */ +int getc(FILE *stream) { (void)stream; return getchar(); } /* ----------------------------------------------------------------------------- * Misc platform stubs