Skip to content

Commit 0b1a17c

Browse files
authored
Revert "[libc] Migrate from baremetal stdio.h to generic stdio.h" (#156371)
Reverts #152748
1 parent dafffe2 commit 0b1a17c

File tree

18 files changed

+357
-280
lines changed

18 files changed

+357
-280
lines changed

libc/config/baremetal/aarch64/entrypoints.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ set(TARGET_LIBC_ENTRYPOINTS
124124

125125
# stdio.h entrypoints
126126
libc.src.stdio.asprintf
127-
libc.src.stdio.fopencookie
128-
libc.src.stdio.fprintf
129127
libc.src.stdio.getchar
130128
libc.src.stdio.printf
131129
libc.src.stdio.putchar

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ set(TARGET_LIBC_ENTRYPOINTS
124124

125125
# stdio.h entrypoints
126126
libc.src.stdio.asprintf
127-
libc.src.stdio.fopencookie
128-
libc.src.stdio.fprintf
129127
libc.src.stdio.getchar
130128
libc.src.stdio.printf
131129
libc.src.stdio.putchar

libc/config/baremetal/riscv/entrypoints.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,6 @@ set(TARGET_LIBC_ENTRYPOINTS
124124

125125
# stdio.h entrypoints
126126
libc.src.stdio.asprintf
127-
libc.src.stdio.fopencookie
128-
libc.src.stdio.fprintf
129127
libc.src.stdio.getchar
130128
libc.src.stdio.printf
131129
libc.src.stdio.putchar

libc/src/__support/File/CMakeLists.txt

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,6 @@ add_object_library(
2222
libc.src.__support.error_or
2323
)
2424

25-
add_header_library(
26-
cookie_file
27-
HDRS
28-
cookie_file.h
29-
DEPENDS
30-
.file
31-
libc.hdr.errno_macros
32-
libc.hdr.types.cookie_io_functions_t
33-
libc.hdr.types.off_t
34-
libc.src.__support.CPP.new
35-
)
36-
3725
add_object_library(
3826
dir
3927
SRCS
@@ -53,11 +41,7 @@ endif()
5341

5442
add_subdirectory(${LIBC_TARGET_OS})
5543

56-
if(LIBC_TARGET_OS_IS_BAREMETAL)
57-
set(target_file libc.src.__support.File.cookie_file)
58-
else()
59-
set(target_file libc.src.__support.File.${LIBC_TARGET_OS}.file)
60-
endif()
44+
set(target_file libc.src.__support.File.${LIBC_TARGET_OS}.file)
6145
set(target_stdout libc.src.__support.File.${LIBC_TARGET_OS}.stdout)
6246
set(target_stderr libc.src.__support.File.${LIBC_TARGET_OS}.stderr)
6347
set(target_stdin libc.src.__support.File.${LIBC_TARGET_OS}.stdin)

libc/src/__support/File/baremetal/CMakeLists.txt

Lines changed: 0 additions & 32 deletions
This file was deleted.

libc/src/__support/File/baremetal/stderr.cpp

Lines changed: 0 additions & 34 deletions
This file was deleted.

libc/src/__support/File/baremetal/stdin.cpp

Lines changed: 0 additions & 34 deletions
This file was deleted.

libc/src/__support/File/baremetal/stdout.cpp

Lines changed: 0 additions & 34 deletions
This file was deleted.

libc/src/__support/File/cookie_file.h

Lines changed: 0 additions & 80 deletions
This file was deleted.

libc/src/__support/OSUtil/baremetal/io.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,45 @@
1313

1414
namespace LIBC_NAMESPACE_DECL {
1515

16+
// These are intended to be provided by the vendor.
17+
//
18+
// The signature of these types and functions intentionally match `fopencookie`
19+
// which allows the following:
20+
//
21+
// ```
22+
// struct __llvm_libc_stdio_cookie { ... };
23+
// ...
24+
// struct __llvm_libc_stdio_cookie __llvm_libc_stdin_cookie;
25+
// cookie_io_functions_t stdin_func = { .read = __llvm_libc_stdio_read };
26+
// FILE *stdin = fopencookie(&__llvm_libc_stdin_cookie, "r", stdin_func);
27+
// ...
28+
// struct __llvm_libc_stdio_cookie __llvm_libc_stdout_cookie;
29+
// cookie_io_functions_t stdout_func = { .write = __llvm_libc_stdio_write };
30+
// FILE *stdout = fopencookie(&__llvm_libc_stdout_cookie, "w", stdout_func);
31+
// ...
32+
// struct __llvm_libc_stdio_cookie __llvm_libc_stderr_cookie;
33+
// cookie_io_functions_t stderr_func = { .write = __llvm_libc_stdio_write };
34+
// FILE *stderr = fopencookie(&__llvm_libc_stderr_cookie, "w", stderr_func);
35+
// ```
36+
//
37+
// At the same time, implementation of functions like `printf` and `scanf` can
38+
// use `__llvm_libc_stdio_read` and `__llvm_libc_stdio_write` directly to avoid
39+
// the extra indirection.
40+
//
41+
// All three symbols `__llvm_libc_stdin_cookie`, `__llvm_libc_stdout_cookie`,
42+
// and `__llvm_libc_stderr_cookie` must be provided, even if they don't point
43+
// at anything.
44+
45+
struct __llvm_libc_stdio_cookie;
46+
47+
extern "C" struct __llvm_libc_stdio_cookie __llvm_libc_stdin_cookie;
48+
extern "C" struct __llvm_libc_stdio_cookie __llvm_libc_stdout_cookie;
49+
extern "C" struct __llvm_libc_stdio_cookie __llvm_libc_stderr_cookie;
50+
51+
extern "C" ssize_t __llvm_libc_stdio_read(void *cookie, char *buf, size_t size);
52+
extern "C" ssize_t __llvm_libc_stdio_write(void *cookie, const char *buf,
53+
size_t size);
54+
1655
ssize_t read_from_stdin(char *buf, size_t size) {
1756
return __llvm_libc_stdio_read(static_cast<void *>(&__llvm_libc_stdin_cookie),
1857
buf, size);

0 commit comments

Comments
 (0)