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