Skip to content

Fix custom printf/malloc#783

Open
ZERICO2005 wants to merge 4 commits intomasterfrom
fix_custom_printf_malloc
Open

Fix custom printf/malloc#783
ZERICO2005 wants to merge 4 commits intomasterfrom
fix_custom_printf_malloc

Conversation

@ZERICO2005
Copy link
Copy Markdown
Contributor

@ZERICO2005 ZERICO2005 commented Apr 13, 2026

The test for std::terminate was added to make sure that sprintf (used by std::terminate) is linked even if no functions from libnanoprintf.a are directly referenced by lto.s.

#include <ti/screen.h>
#include <ti/getcsc.h>
#include <exception>

int main(void) {
    os_ClrHome();
    os_PutStrFull("before std::terminate");
    while (!os_GetCSC());

    std::terminate();
}

To define a custom malloc/free/realloc, the user must set ALLOCATOR = CUSTOM in the makefile, then they just have to define malloc in one of two ways:

// it is recommended but not strictly necessary to #include <stdlib.h>
#include <stdlib.h>
void *malloc(size_t size) {
    /* code */
}
	.global	_malloc
	.type	_malloc, @function
_malloc:
	; code
	ret

This does remove support for _custom_malloc/_custom_free/_custom_realloc, but the user can fix it by doing:

	.global	_malloc
	.type	_malloc, @function
_malloc:
	jp _custom_malloc
	.extern _custom_malloc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

cedev-obj only searches lto.s

1 participant