From 31f73bf142af1be3a61d3475e7bc4f132c336185 Mon Sep 17 00:00:00 2001 From: Andy Ross Date: Thu, 2 Mar 2023 11:25:59 -0800 Subject: [PATCH] zephyr/alloc: Add newlib-style allocator stub for C++ builds This is a weak stub for the Cadence libc's allocator (which is just a newlib build). It's traditionally been provided like this in SOF for the benefit of C++ code where the standard library needs to link to a working malloc() even if it will never call it. Longer term this should be integrated as a working allocator, either unified with the one here or in the Zephyr libc layer. Zephyr already provides a newlib-compatible _sbrk_r(), we just have to tell it to use it when linking against Cadence libc. Signed-off-by: Andy Ross --- zephyr/lib/alloc.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/zephyr/lib/alloc.c b/zephyr/lib/alloc.c index f20e125e9246..2bfafc60d312 100644 --- a/zephyr/lib/alloc.c +++ b/zephyr/lib/alloc.c @@ -367,4 +367,15 @@ static int heap_init(void) return 0; } +/* This is a weak stub for the Cadence libc's allocator (which is just + * a newlib build). It's traditionally been provided like this in SOF + * for the benefit of C++ code where the standard library needs to + * link to a working malloc() even if it will never call it. + */ +struct _reent; +__weak void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr) +{ + k_panic(); +} + SYS_INIT(heap_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS);