Using arm-none-eabi-gcc for Cortex-M4 (baremetal application), the code for malloc
is also emitted even though I never use malloc
in my code.
S
In an environment with limited memory such as the Cortex M4, another option is to use newlib-nano. It provides a __register_exitproc()
that is weakly linked. Therefore it is easy to override with your own empty function that avoids calling malloc()
. This will have the additional benefit of removing __call_exitprocs()
from your binary as well.
--specs=nano.specs
to your compiler and linker options.void __register_exitproc(void) { }
Note that this will prevent destructors being called for static instances of classes. This seems appropriate in your example.
See the comments in the newlib source for more details.