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 <noreply@anthropic.com>
This commit is contained in:
Robert Allan James
2026-08-11 11:14:05 -04:00
co-authored by Claude Sonnet 5
parent 96ff2f6ae5
commit 37eec5aaa1
+10
View File
@@ -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