We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
My project uses ARM Cortex M0+, with C++ and ArmClang 6.10.1. My ultimate goal is to set "Heap_Size EQU 0x0" in the startup.s file. My code builds fine, but when I run it in Keil simulator it crashes. Stepping through assembly instructions, it appears that the "_init_alloc" function exits with SIGRTMEM signal after comparing the 0x0 heap size to a "#0x10" immediate. To confirm, I set "Heap_Size EQU 0x10" and my program builds/runs as expected.
I've ensured that malloc+new are not used in my code (UNUSED according to the generated static call graph); I left free+delete alone since they are used in more places, but I don't think this matters since I'm not using malloc+new. After digging through the ARM info center, I used "IMPORT __ARM_use_no_argv" and an overridden "__aeabi_atexit" function to achieve this.
As a possibly related side-note, I can't use "IMPORT __use_no_heap_region" because the linker still finds references to malloc+free, resulting in "Error: L6915E: Library reports error: __use_no_heap was requested, but malloc was referenced". I'm not sure why entirely, but maybe because the linker can't remove them explicitly from the library (they still appear in the map file).
Conclusion: Is there some typical minimum heap size, and/or how is the aforementioned "#0x10" immediate determined? Is it specific to C++ or ArmClang? In another project that uses ArmCC with RTX and C only, the "Heap_Size EQU 0x0" works as expected. Thanks for any help!
Oh okay, thanks for clarifying how the 2 issues are tied together. I understand that I need to enforce "__use_no_heap" to get the heap size to 0x0. So moving on with that goal...
I'm going to dig through the map and static call graph to hunt down any less-than-explicit references. I can already see "__cxa_allocate_exception" is called by std::array::at() somewhere... I'll update my results after I finish or get stuck.
Throwing exceptions does make use of malloc.
arm_exceptions_alloc.o(.text) refers to h1_alloc_mt.o(.text) for malloc
I removed all exception-related handling (and added -fno-exceptions flag). This removed all deeper malloc calls and allowed heap size of 0x0! Thank you for your guidance.
However, the linker still reports: "__use_no_heap was requested, but free was referenced". The only references to free/delete are in generated default class destructors, such as "MyClass::~MyClass__deallocating". I'm not using new/malloc for these classes, so free/delete isn't needed. This may be getting outside the scope of this question and/or embedded environment and more into C++ realm, but is there a way to prevent this automatic delete? I'm so close to enabling "__use_no_heap_region".
Just to update for completeness, I finished resolving my issue by overloading the delete operator to prevent referencing free. Now I can enforce the "__use_no_heap_region" flag.