malloc: Avoid defining calloc()

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>
This commit is contained in:
Simon Glass
2025-08-17 16:14:16 -06:00
parent 9d449d63ed
commit 22f87ef530
2 changed files with 2 additions and 1 deletions

View File

@@ -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;

View File

@@ -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