Skip to content

Commit cae739d

Browse files
committed
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 <andyross@google.com>
1 parent dc1ea49 commit cae739d

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

zephyr/lib/alloc.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,4 +369,15 @@ static int heap_init(void)
369369
return 0;
370370
}
371371

372+
/* This is a weak stub for the Cadence libc's allocator (which is just
373+
* a newlib build). It's traditionally been provided like this in SOF
374+
* for the benefit of C++ code where the standard library needs to
375+
* link to a working malloc() even if it will never call it.
376+
*/
377+
struct _reent;
378+
__weak void *_sbrk_r(struct _reent *ptr, ptrdiff_t incr)
379+
{
380+
k_panic();
381+
}
382+
372383
SYS_INIT(heap_init, PRE_KERNEL_1, CONFIG_KERNEL_INIT_PRIORITY_OBJECTS);

0 commit comments

Comments
 (0)