Mbed compile misreports RAM/Flash usage (leading to mbed_fault_handler crash when deploying on device)

Can anyone shed light on why there is a discrepancy between what ‘mbed compile’ reports and what later goes in the bin (or elf) file?

Initially, I didn’t check the size of the .bin/.elf file and took what mbed reported as correct. However, when deploying+running i kept ending up in mbed_fault_handler with a Hard Fault for no reason. After some analysis, it turns out the mbed compile reported codesize is incorrect. The .bin/.elf data is much bigger. When loading, no error was generated by the STM flash loading tools (even though all the firmware couldn’t be loaded in flash). This led to the Hard fault.

Anyway, coming back to the mbed misreporting issue:

For an example project, mbed compile reports:

Total Static RAM memory (data + bss): 2544(+2544) bytes
Total Flash memory (text + data): 24512(+24512) bytes

However, analyzing the .bin (or elf) file:

ls -l example.bin
Reports: 31312 bytes
i.e. a difference of 4256 bytes

What is this the source of this difference?
Analyzing the .elf file it can be seen that the .text section contains the difference.
(.elf .text section is 31160 bytes, even though you would have expected something like 27056 bytes (24512+2544)).

1 Like


maybe similar to Why GCC_ARM and ARMC6 show different flash and RAM usage for same program on same hardware? - Mbed CLI - Arm Mbed OS support forum

BR, Jan

1 Like

Yeah, that’s spot on the problem!

Analyzing the .map file using Amap (Amap | Sergey Sikorskiy), it’s obvious the problem is that mbed misreports the total size. Same issue as the one you referred to @JohnnyK.

Plenty of .rodata missing in the mbed compile report.

Example from one of my files:
I have large state table (2136 bytes) declared as:

static const state_table_t table[]  { ... 

This .rodata is completely missing from the mbed compile report.

Anyway, apart from my own files, the mbed-os native files are also misreported:

                      mbed compile reported (excl. text/data)       .map file reported (rodata)
mbed-os\drivers                  0                                         146
mbed-os\hal                     58                                         348
mbed-os\platform               234                                        1141
mbed-os\targets                614                                         731

Note: Using the latest CLI tools “mbed compile” or “mbed-tools compile”

1 Like