Skip to content

Commit

Permalink
[libc] Include (v)s(n)printf in baremetal configs
Browse files Browse the repository at this point in the history
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
  • Loading branch information
petrhosek committed Sep 4, 2023
1 parent 7dc199d commit 89fc7e5
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 2 deletions.
6 changes: 6 additions & 0 deletions libc/config/baremetal/arm/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.inttypes.imaxdiv
libc.src.inttypes.strtoimax
libc.src.inttypes.strtoumax

# stdio.h entrypoints
libc.src.stdio.sprintf
libc.src.stdio.snprintf
libc.src.stdio.vsprintf
libc.src.stdio.vsnprintf

# stdlib.h entrypoints
libc.src.stdlib.abs
Expand Down
1 change: 1 addition & 0 deletions libc/config/baremetal/arm/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.errno
libc.include.inttypes
libc.include.math
libc.include.stdio
libc.include.stdlib
libc.include.string
libc.include.strings
Expand Down
6 changes: 6 additions & 0 deletions libc/config/baremetal/riscv32/entrypoints.txt
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ set(TARGET_LIBC_ENTRYPOINTS
libc.src.inttypes.strtoimax
libc.src.inttypes.strtoumax

# stdio.h entrypoints
libc.src.stdio.sprintf
libc.src.stdio.snprintf
libc.src.stdio.vsprintf
libc.src.stdio.vsnprintf

# stdlib.h entrypoints
libc.src.stdlib.abs
libc.src.stdlib.atoi
Expand Down
1 change: 1 addition & 0 deletions libc/config/baremetal/riscv32/headers.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ set(TARGET_PUBLIC_HEADERS
libc.include.errno
libc.include.inttypes
libc.include.math
libc.include.stdio
libc.include.stdlib
libc.include.string
libc.include.strings
Expand Down
12 changes: 10 additions & 2 deletions libc/src/stdio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ if(NOT LIBC_TARGET_ARCHITECTURE_IS_GPU)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/generic)
endif()

if(${LIBC_TARGET_OS} STREQUAL "baremetal")
list(APPEND printf_copts
"-DLIBC_COPT_PRINTF_DISABLE_FLOAT"
"-DLIBC_COPT_PRINTF_DISABLE_INDEX_MODE"
"-DLIBC_COPT_PRINTF_DISABLE_WRITE_INT"
)
endif()

add_subdirectory(printf_core)
add_subdirectory(scanf_core)

Expand Down Expand Up @@ -419,13 +427,13 @@ list(APPEND printf_deps
libc.src.stdio.printf_core.vfprintf_internal
)
if(LLVM_LIBC_FULL_BUILD)
list(APPEND printf_deps
list(APPEND printf_deps
libc.src.__support.File.file
libc.src.__support.File.platform_file
libc.src.__support.File.platform_stdout
)
else()
set(printf_copts "-DLIBC_COPT_PRINTF_USE_SYSTEM_FILE")
list(APPEND printf_copts "-DLIBC_COPT_PRINTF_USE_SYSTEM_FILE")
endif()

add_entrypoint_object(
Expand Down
1 change: 1 addition & 0 deletions libc/src/stdio/printf_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ add_object_library(
libc.src.__support.float_to_string
COMPILE_OPTIONS
-DLIBC_COPT_FLOAT_TO_STR_USE_MEGA_LONG_DOUBLE_TABLE
${printf_copts}
)


Expand Down

0 comments on commit 89fc7e5

Please sign in to comment.