From c1ba4d6f827a2128bc3cd0aa98f5b91d704b68b7 Mon Sep 17 00:00:00 2001 From: William Huynh Date: Mon, 1 Sep 2025 15:02:06 +0100 Subject: [PATCH] [libc] Add support for std::cout on embedded Fixes an bug with external linkage in stdout/stderr. Adds the required entrypoints for std::cout. --- libc/config/baremetal/aarch64/entrypoints.txt | 8 ++++++++ libc/config/baremetal/arm/entrypoints.txt | 8 ++++++++ libc/config/baremetal/riscv/entrypoints.txt | 8 ++++++++ libc/src/__support/File/baremetal/stderr.cpp | 8 ++++---- libc/src/__support/File/baremetal/stdin.cpp | 8 ++++---- 5 files changed, 32 insertions(+), 8 deletions(-) diff --git a/libc/config/baremetal/aarch64/entrypoints.txt b/libc/config/baremetal/aarch64/entrypoints.txt index 90d0a7a9adc6a..31449e0c8b831 100644 --- a/libc/config/baremetal/aarch64/entrypoints.txt +++ b/libc/config/baremetal/aarch64/entrypoints.txt @@ -124,8 +124,11 @@ set(TARGET_LIBC_ENTRYPOINTS # stdio.h entrypoints libc.src.stdio.asprintf + libc.src.stdio.fflush libc.src.stdio.fopencookie libc.src.stdio.fprintf + libc.src.stdio.fwrite + libc.src.stdio.getc libc.src.stdio.getchar libc.src.stdio.printf libc.src.stdio.putchar @@ -135,7 +138,12 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.stdio.snprintf libc.src.stdio.sprintf libc.src.stdio.sscanf + libc.src.stdio.stderr + libc.src.stdio.stdin + libc.src.stdio.stdout + libc.src.stdio.ungetc libc.src.stdio.vasprintf + libc.src.stdio.vfprintf libc.src.stdio.vprintf libc.src.stdio.vscanf libc.src.stdio.vsnprintf diff --git a/libc/config/baremetal/arm/entrypoints.txt b/libc/config/baremetal/arm/entrypoints.txt index d838a485b6c89..d61ca2c7faa7a 100644 --- a/libc/config/baremetal/arm/entrypoints.txt +++ b/libc/config/baremetal/arm/entrypoints.txt @@ -124,8 +124,11 @@ set(TARGET_LIBC_ENTRYPOINTS # stdio.h entrypoints libc.src.stdio.asprintf + libc.src.stdio.fflush libc.src.stdio.fopencookie libc.src.stdio.fprintf + libc.src.stdio.fwrite + libc.src.stdio.getc libc.src.stdio.getchar libc.src.stdio.printf libc.src.stdio.putchar @@ -135,7 +138,12 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.stdio.snprintf libc.src.stdio.sprintf libc.src.stdio.sscanf + libc.src.stdio.stderr + libc.src.stdio.stdin + libc.src.stdio.stdout + libc.src.stdio.ungetc libc.src.stdio.vasprintf + libc.src.stdio.vfprintf libc.src.stdio.vprintf libc.src.stdio.vscanf libc.src.stdio.vsnprintf diff --git a/libc/config/baremetal/riscv/entrypoints.txt b/libc/config/baremetal/riscv/entrypoints.txt index db65d6115cdbb..53cb61faf50d3 100644 --- a/libc/config/baremetal/riscv/entrypoints.txt +++ b/libc/config/baremetal/riscv/entrypoints.txt @@ -124,8 +124,11 @@ set(TARGET_LIBC_ENTRYPOINTS # stdio.h entrypoints libc.src.stdio.asprintf + libc.src.stdio.fflush libc.src.stdio.fopencookie libc.src.stdio.fprintf + libc.src.stdio.fwrite + libc.src.stdio.getc libc.src.stdio.getchar libc.src.stdio.printf libc.src.stdio.putchar @@ -135,7 +138,12 @@ set(TARGET_LIBC_ENTRYPOINTS libc.src.stdio.snprintf libc.src.stdio.sprintf libc.src.stdio.sscanf + libc.src.stdio.stderr + libc.src.stdio.stdin + libc.src.stdio.stdout + libc.src.stdio.ungetc libc.src.stdio.vasprintf + libc.src.stdio.vfprintf libc.src.stdio.vprintf libc.src.stdio.vscanf libc.src.stdio.vsnprintf diff --git a/libc/src/__support/File/baremetal/stderr.cpp b/libc/src/__support/File/baremetal/stderr.cpp index 0a67771f034aa..bca866a73120b 100644 --- a/libc/src/__support/File/baremetal/stderr.cpp +++ b/libc/src/__support/File/baremetal/stderr.cpp @@ -14,10 +14,10 @@ namespace LIBC_NAMESPACE_DECL { -cookie_io_functions_t io_func = {.read = nullptr, - .write = __llvm_libc_stdio_write, - .seek = nullptr, - .close = nullptr}; +static cookie_io_functions_t io_func = {.read = nullptr, + .write = __llvm_libc_stdio_write, + .seek = nullptr, + .close = nullptr}; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wglobal-constructors" // Buffering is implementation defined. Therefore to save RAM, we use no diff --git a/libc/src/__support/File/baremetal/stdin.cpp b/libc/src/__support/File/baremetal/stdin.cpp index 569d924749eec..e0bc0ec6a6378 100644 --- a/libc/src/__support/File/baremetal/stdin.cpp +++ b/libc/src/__support/File/baremetal/stdin.cpp @@ -14,10 +14,10 @@ namespace LIBC_NAMESPACE_DECL { -cookie_io_functions_t io_func = {.read = __llvm_libc_stdio_read, - .write = nullptr, - .seek = nullptr, - .close = nullptr}; +static cookie_io_functions_t io_func = {.read = __llvm_libc_stdio_read, + .write = nullptr, + .seek = nullptr, + .close = nullptr}; #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wglobal-constructors" // Buffering is implementation defined. Therefore to save RAM, we use no