Skip to content

Commit 89fc7e5

Browse files
committed
[libc] Include (v)s(n)printf in baremetal configs
These are commonly used on baremetal targets. We disable float support and other features to reduce the binary size. This would ideally eventually be handled using the proposed config mechanism: https://discourse.llvm.org/t/rfc-systematic-way-to-introduce-and-use-libc-config-options/72943 but for now we use a CMake conditional. Differential Revision: https://reviews.llvm.org/D159067
1 parent 7dc199d commit 89fc7e5

File tree

6 files changed

+25
-2
lines changed

6 files changed

+25
-2
lines changed

libc/config/baremetal/arm/entrypoints.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ set(TARGET_LIBC_ENTRYPOINTS
6363
libc.src.inttypes.imaxdiv
6464
libc.src.inttypes.strtoimax
6565
libc.src.inttypes.strtoumax
66+
67+
# stdio.h entrypoints
68+
libc.src.stdio.sprintf
69+
libc.src.stdio.snprintf
70+
libc.src.stdio.vsprintf
71+
libc.src.stdio.vsnprintf
6672

6773
# stdlib.h entrypoints
6874
libc.src.stdlib.abs

libc/config/baremetal/arm/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(TARGET_PUBLIC_HEADERS
44
libc.include.errno
55
libc.include.inttypes
66
libc.include.math
7+
libc.include.stdio
78
libc.include.stdlib
89
libc.include.string
910
libc.include.strings

libc/config/baremetal/riscv32/entrypoints.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ set(TARGET_LIBC_ENTRYPOINTS
6464
libc.src.inttypes.strtoimax
6565
libc.src.inttypes.strtoumax
6666

67+
# stdio.h entrypoints
68+
libc.src.stdio.sprintf
69+
libc.src.stdio.snprintf
70+
libc.src.stdio.vsprintf
71+
libc.src.stdio.vsnprintf
72+
6773
# stdlib.h entrypoints
6874
libc.src.stdlib.abs
6975
libc.src.stdlib.atoi

libc/config/baremetal/riscv32/headers.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ set(TARGET_PUBLIC_HEADERS
44
libc.include.errno
55
libc.include.inttypes
66
libc.include.math
7+
libc.include.stdio
78
libc.include.stdlib
89
libc.include.string
910
libc.include.strings

libc/src/stdio/CMakeLists.txt

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,14 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
2626
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generic)
2727
endif()
2828

29+
if(${LIBC_TARGET_OS} STREQUAL "baremetal")
30+
list(APPEND printf_copts
31+
"-DLIBC_COPT_PRINTF_DISABLE_FLOAT"
32+
"-DLIBC_COPT_PRINTF_DISABLE_INDEX_MODE"
33+
"-DLIBC_COPT_PRINTF_DISABLE_WRITE_INT"
34+
)
35+
endif()
36+
2937
add_subdirectory(printf_core)
3038
add_subdirectory(scanf_core)
3139

@@ -419,13 +427,13 @@ list(APPEND printf_deps
419427
libc.src.stdio.printf_core.vfprintf_internal
420428
)
421429
if(LLVM_LIBC_FULL_BUILD)
422-
list(APPEND printf_deps
430+
list(APPEND printf_deps
423431
libc.src.__support.File.file
424432
libc.src.__support.File.platform_file
425433
libc.src.__support.File.platform_stdout
426434
)
427435
else()
428-
set(printf_copts "-DLIBC_COPT_PRINTF_USE_SYSTEM_FILE")
436+
list(APPEND printf_copts "-DLIBC_COPT_PRINTF_USE_SYSTEM_FILE")
429437
endif()
430438

431439
add_entrypoint_object(

libc/src/stdio/printf_core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ add_object_library(
9393
libc.src.__support.float_to_string
9494
COMPILE_OPTIONS
9595
-DLIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE
96+
${printf_copts}
9697
)
9798

9899

0 commit comments

Comments
 (0)