Trying to build newlib with -DMALLOC_PROVIDED

Stephan Mühlstrasser
Wed Apr 19 18:15:00 GMT 2017


I'm making my first attempt to build newlib for an ARM bare-metal 
environment from the current master branch. malloc(), free() etc. come 
from the bare-metal library, therefore I'm trying to build newlib with 
-DMALLOC_PROVIDED, using other configurations in newlib/ 
as a blueprint.

I made this modification in newlib/ for my target:

     newlib_cflags="${newlib_cflags} -DMALLOC_PROVIDED"

I can successfully build newlib, and when I try to link a test 
application that just calls printf() I get the following unresolved symbols:

In function `_vfprintf_r':
vfprintf.c:(.text+0x1fcc): undefined reference to `_free_r'
vfprintf.c:(.text+0x215c): undefined reference to `_free_r'
In function `__swsetup_r':
wsetup.c:(.text+0xcc): undefined reference to `_free_r'
In function `__sflush_r':
fflush.c:(.text+0x24c): undefined reference to `_free_r'
In function `__sfmoreglue':
findfp.c:(.text+0x130): undefined reference to `_malloc_r'

and also

In function `_sbrk':
syscalls.c:(.text+0x984): undefined reference to `end'

I read various tutorials about porting newlib, and they suggest that it 
should be possible to build without the reentrant versions of the memory 
management functions. But I don't understand how that is supposed to 
work in the source. For example in malloc.h:

extern _PTR malloc _PARAMS ((size_t));
#ifdef __CYGWIN__
#undef _malloc_r
#define _malloc_r(r, s) malloc (s)
extern _PTR _malloc_r _PARAMS ((struct _reent *, size_t));

This looks like that only for __CYGWIN__ the reentrant variants are 
defined away.

How can I build newlib for an environment that provides the memory 
management functions that are already thread-safe?

Thanks in advance for any suggestions!

Best regards

More information about the Newlib mailing list