gcc/picolibc: Disable -fprintf-return-value when printf is not complete

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>
This commit is contained in:
Keith Packard 2022-10-13 15:04:00 -07:00 committed by Stephanos Ioannidis
commit b3073f0099
3 changed files with 9 additions and 0 deletions

View file

@ -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>)

View file

@ -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 #

View file

@ -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