Skip to content

Commit 679d82c

Browse files
gramsay0carlescufi
authored andcommitted
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 <[email protected]>
1 parent c72b9f5 commit 679d82c

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

lib/libc/common/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_ABORT source/stdlib/abort.c)
66
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_TIME source/time/time.c)
77
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_MALLOC source/stdlib/malloc.c)
88
zephyr_library_sources_ifdef(CONFIG_COMMON_LIBC_STRNLEN source/string/strnlen.c)
9+
10+
# Prevent compiler from optimizing calloc into an infinite recursive call
11+
zephyr_library_cc_option(-fno-builtin-malloc)

0 commit comments

Comments
 (0)