libc: Add GCC fno-builtin-malloc flag to common stdlib compilation

This prevents the compiler from optimizing calloc into an
infinite recursive call.

For example a call to malloc + memset zero at GCC -O2 will be
replaced by a call to calloc. This causes infinite recursion
if the function being implemented *is* calloc.

fno-builtin-malloc forces the compiler to avoid this optimization.

Signed-off-by: Grant Ramsay <gramsay@enphaseenergy.com>
This commit is contained in:
Grant Ramsay 2023-11-11 09:35:49 +13:00 committed by Carles Cufí
parent c72b9f5048
commit 679d82c484

View File

@ -6,3 +6,6 @@ zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_ABORT source/stdlib/abort.c)
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_TIME source/time/time.c)
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_MALLOC source/stdlib/malloc.c)
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_STRNLEN source/string/strnlen.c)
# Prevent compiler from optimizing calloc into an infinite recursive call
zephyr_library_cc_option(-fno-builtin-malloc)