8 years, 2 months ago.

Executable (.bin) size large difference between GCC ARM as against online compiler

For a simple blinky program, the bin size is less than 20KB. After exporting the same program with "GCC ARM Embed" for off-line compilation, the bin file size is more than 44KB.

Why such a large difference in the bin size due to compiler? Is there any way (say optimization flag) to reduce the size substantially, in using GCC?

-Hemant

3 Answers

7 years, 3 months ago.

The reason for the sizes differences are because the ARM Compiler, Linker and C/C++ runtime library are highly optimized. You can check out the GCC “.map” file to see that a simple stdio printf and other C/C++ libraries are way bigger compared to the ARM compiler (all for the non debug case). Turning on debug code adds even more.

My experience is that the ARM C/C++ Compiler (Online or Keil MDK) needs about 30-40% less Flash size and also less SRAM.

Not to forget that the GCC/GDB Compiler and Debugger is free of charge, the ARM offline compiler/debugger works only on Windows and costs about 3500 Euros (Keil MDK).

Regards Helmut

Accepted Answer
7 years, 3 months ago.

7 years, 3 months ago.

Exported projects will compile with debug symbols, which would explain the size increase. You can look into using mbed CLI - https://github.com/ARMmbed/mbed-cli - to use the export functionality offline. Exporting offline allows you to specify a build profile - https://docs.mbed.com/docs/mbed-os-handbook/en/latest/dev_tools/build_profiles/ - which would allow you to create a Makefile that will not compile the binary with debugging symbols.