Skip to content

Commit

Permalink
gcc/picolibc: Disable -fprintf-return-value when printf is not complete
Browse files Browse the repository at this point in the history
GCC will compute expected sprintf (et al) return values internally and use
them in place of the actual return value. When the printf implementation
has reduced functionality, gcc may compute a different value.

For picolibc, this means disabling the optimization unless floating point
output is enabled.

Signed-off-by: Keith Packard <keithp@keithp.com>
  • Loading branch information
keith-packard authored and stephanosio committed Oct 31, 2022
1 parent cb5c440 commit b3073f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ if(NOT CONFIG_PICOLIBC)
zephyr_compile_options($<$<COMPILE_LANGUAGE:ASM>:$<TARGET_PROPERTY:compiler,freestanding>>)
endif()

if (CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_IO_FLOAT)
# @Intent: Set compiler specific flag to disable printf-related optimizations
zephyr_compile_options($<$<COMPILE_LANGUAGE:C>:$<TARGET_PROPERTY:compiler,no_printf_return_value>>)
endif()

# @Intent: Set compiler specific flag for tentative definitions, no-common
zephyr_compile_options($<TARGET_PROPERTY:compiler,no_common>)

Expand Down
2 changes: 2 additions & 0 deletions cmake/compiler/compiler_flags_template.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ set_property(TARGET compiler-cpp PROPERTY no_exceptions)
# Flag for disabling rtti in C++
set_property(TARGET compiler-cpp PROPERTY no_rtti)

# Flag for disabling optimizations around printf return value
set_compiler_property(PROPERTY no_printf_return_value)

###################################################
# This section covers all remaining C / C++ flags #
Expand Down
2 changes: 2 additions & 0 deletions cmake/compiler/gcc/compiler_flags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ if (NOT CONFIG_NEWLIB_LIBC AND
set_compiler_property(APPEND PROPERTY nostdinc_include ${NOSTDINC})
endif()

set_compiler_property(PROPERTY no_printf_return_value -fno-printf-return-value)

set_compiler_property(TARGET compiler-cpp PROPERTY nostdincxx "-nostdinc++")

# Required C++ flags when using gcc
Expand Down

0 comments on commit b3073f0

Please sign in to comment.