From b3073f00994fe9220ad6d2356483eb4dd748f238 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Thu, 13 Oct 2022 15:04:00 -0700 Subject: [PATCH] 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 --- CMakeLists.txt | 5 +++++ cmake/compiler/compiler_flags_template.cmake | 2 ++ cmake/compiler/gcc/compiler_flags.cmake | 2 ++ 3 files changed, 9 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5cba6ee3a8b..59d413171aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -275,6 +275,11 @@ if(NOT CONFIG_PICOLIBC) zephyr_compile_options($<$:$>) endif() +if (CONFIG_PICOLIBC AND NOT CONFIG_PICOLIBC_IO_FLOAT) + # @Intent: Set compiler specific flag to disable printf-related optimizations + zephyr_compile_options($<$:$>) +endif() + # @Intent: Set compiler specific flag for tentative definitions, no-common zephyr_compile_options($) diff --git a/cmake/compiler/compiler_flags_template.cmake b/cmake/compiler/compiler_flags_template.cmake index 543b9d6b594..9fd4bffc364 100644 --- a/cmake/compiler/compiler_flags_template.cmake +++ b/cmake/compiler/compiler_flags_template.cmake @@ -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 # diff --git a/cmake/compiler/gcc/compiler_flags.cmake b/cmake/compiler/gcc/compiler_flags.cmake index a02d5f24967..eeeed7dfdf4 100644 --- a/cmake/compiler/gcc/compiler_flags.cmake +++ b/cmake/compiler/gcc/compiler_flags.cmake @@ -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