[Concept,04/15] malloc: Avoid defining calloc()
Commit Message
From: Simon Glass <sjg@chromium.org>
The C runtime calls malloc() before starting main(), e.g. to get some
memory to use for dynamic linking.
If CONFIG_TPL_SYS_MALLOC_SIMPLE is enabled, the calloc() symbol is
defined within U-Boot. The C runtime may call that too.
Use the same #define technique as for malloc_simple(), to fix a crash
on my machine when running:
/tmp/b/sandbox_vpl/tpl/u-boot-tpl -D
This does not happen in CI, perhaps because the C runtime uses malloc()
instead of calloc().
Signed-off-by: Simon Glass <sjg@chromium.org>
---
common/malloc_simple.c | 2 +-
include/malloc.h | 1 +
2 files changed, 2 insertions(+), 1 deletion(-)
@@ -65,7 +65,7 @@ void *memalign_simple(size_t align, size_t bytes)
}
#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
-void *calloc(size_t nmemb, size_t elem_size)
+void *calloc_simple(size_t nmemb, size_t elem_size)
{
size_t size = nmemb * elem_size;
void *ptr;
@@ -882,6 +882,7 @@ void malloc_disable_testing(void);
#if CONFIG_IS_ENABLED(SYS_MALLOC_SIMPLE)
#define malloc malloc_simple
#define realloc realloc_simple
+#define calloc calloc_simple
#define memalign memalign_simple
#if IS_ENABLED(CONFIG_VALGRIND)
#define free free_simple