Background
I have a project that built with GCC and links against newlib-nano (nano.specs).
Previously I was using standard library memory allocators(malloc(), etc.).
I have since switched to using heap_5 as I have external memory which spand multiple memory boundaries.
I have implemented link time wrapper to wrap all memory allocators calls and redirect them to the real memory allocator for heap_5.c
I also use some snprintf() calls and sscanf() as I have lightweight json decoding/encoding library.
I have also rewrote my linker script to remove any standard symbol so linker error out if it needs them.
Question
When should the configUSE_NEWLIB_REENTRANT be enabled given that all the memory allocators have been wrapped? I am still using snprintf() and sscanf() though.
I have read that post. The post basically says to enable configUSE_NEWLIB_REENTRANT if
newlib-nano is used. But the post does not talk indept on how standard library uses struct _reent because if it’s not used by any of my function calls then I do not need it.
If the struct _reent only has to do with memory allocation then I don’t need it because all standard library memory alloactors are wrapped (at the linker level) and point back to heap_5 implementation. Thus this leads me to believe I do not need to enable configUSE_NEWLIB_REENTRANT.
I also know that sbrk is not being linked for 2 reason
The linker symbol it require doesn’t exist because I use custom linker script that I wrote
I can validate sbrk is remove based on the .map file generated by GCC
Thus given this I should not be enabling configUSE_NEWLIB_REENTRANT but it seems that no one really know when struct _reent is really needed and that is what I want to know.
Does anyone know is struct _reent has to do with more than just memory allocators or is that all it’s needed for?
I have read that post. The post basically says to enable configUSE_NEWLIB_REENTRANT if
newlib-nano is used. But the post does not talk indept on how standard library uses struct _reent because if it’s not used by any of my function calls then I do not need it.
If the struct _reent only has to do with memory allocation then I don’t need it because all standard library memory alloactors are wrapped (at the linker level) and point back to heap_5 implementation. Thus this leads me to believe I do not need to enable configUSE_NEWLIB_REENTRANT.
I also know that sbrk is not being linked for 2 reason
The linker symbol it require doesn’t exist because I use custom linker script that I wrote
I can validate sbrk is remove based on the .map file generated by GCC
Also all my startup code from the point the reset vector is called all the way to main() has been written by me and does not call any standard library calls. Which includes setup up data and bss and setting up MSP (main stack pointer).
Thus given this I should not be enabling configUSE_NEWLIB_REENTRANT but it seems that no one really know when struct _reent is really needed and that is what I want to know.
Does anyone know is struct _reent has to do with more than just memory allocators or is that all it’s needed for?
My memory is that configUSE_NEWLIB_REENTRANT doesn’t fix the issue to make malloc/free thread safe (for that you need to define functions __malloc_lock() and __malloc_unlock(), but it provides thread local storage for a number of pieces of newlib that might need it. The biggest usage of which is for things like the file system (if you need it), and things like errno and the locale information. The structure is big, as it contains 3 FILE structures, so if you can be careful not to use the parts that need it, you can save significant memory.
You can see what is in it if you find where the compiler stores the system headers, as the structure is defined in sys/reent.h
When I was using the standard library I had implemented malloc_lock() and malloc_unlock() no longer using standard library implementation.
So I checked out the tool chain header. There alot stuff in there which relates to using floating point arithmetic such as mprec.
I have a hard floating point unit but it seems that the mprec module is used when I dig through the standard library.
I am now considering removing standard library all together and just adding my own implementations the down side is I do use some external stacks which rely on certains standard library implementation.
I don’t do any FILE io operation in my code neither does any external library.