For the GNU ARM tools it is easy to print out the code and date size information, see
- GNU Additional Tools: Create Flash Image, Print Size and Extended Listing Options
- Code Size Information with gcc for ARM/Kinetis
- text, data and bss: Code and Data Size Explained
But this is all for ARM cores. What if I use other architectures like S08 or ColdFire in Eclipse?
GNU Size Tool
The solution is to use the ‘size’ tool which is part of the GNU tool chain. If you are using CodeWarrior for MCU, then it gets installed as part of the ARM toolchain. If you are using a different GNU toolchain, then very likely you have this tool already installed. The ‘size’ tool reports the size of the objects and section sizes in a (ELF/Dwarf) file.
Post-Build Step
To have the size printed at the end of each build, I’m adding it as ‘post-build-step’ to the build settings. For this I go into the project properties (select the project, menu Project > Properties). Then go into C/C++ Build > Settings and select the ‘Build Steps’ tab. There I call the ‘size’ command for the output file of the linker:
I’m using this command:
"${ARM_GNU_TOOLS_HOME}/bin/arm-none-eabi-size" --format=berkeley ${BuildArtifactFileName}
In my Eclipse, the variable ‘ARM_GNU_TOOLS_HOME’ points to where I have the GNU tools installed. Inside the bin folder, I call the ‘size’ program (or size.exe): the name depends on GNU tool chain installed, or you can point to the generic ‘size’ command.
The –format option specifies the output format for the size information. The last option is the output file of my linker, and here I’m using again a variable.
Console Output
With this, it reports at the end of the build process the code/data size, such as:
C:/Freescale/CW MCU v10.6/gnu/bin/mingw32-make --no-print-directory post-build "C:\Freescale\CW MCU v10.6\eclipse\../Cross_Tools/arm-none-eabi-gcc-4_7_3/bin/arm-none-eabi-size" --format=berkeley SRB_Master.abs text data bss dec hex filename 17153 0 2664 19817 4d69 SRB_Master.abs
Happy Sizing 🙂
Hi Erich!
Do you know how I can separate the .abs or .elf file in many .o files and print their sizes?
LikeLike
You cannot create .o files from the .elf file, but if you are using the extended options of objdump (https://sourceware.org/binutils/docs/binutils/objdump.html)
LikeLike
Erich,
Back in the old Classic CodeWarrior, the left most panel listed all the files in a project, and how much ROM and RAM memory they used up. This was very handy, especially when using the smaller 9S08 or ColdFire 1 MCUs.
Screenshot:
Is it possible to get that info out of the newer Eclipse based CodeWarrior?
-Bill
LikeLike
Hi Bill,
this is the best I can come up with: https://mcuoneclipse.com/2014/07/13/listing-code-and-data-size-for-each-source-file-with-gnu-and-eclipse/
LikeLike
Thanks Erich!
LikeLike
Pingback: Listing Code and Data Size for each Source File with GNU and Eclipse | MCU on Eclipse
Pingback: Tutorial: How to Erase the FLASH with the GNU debugger | MCU on Eclipse
Pingback: Code Coverage for Embedded Target with Eclipse, gcc and gcov | MCU on Eclipse
Hi,
Is it possible to print size of all object files located in the pointed folder and subfolders recursively using a short command?
LikeLike
Hi Jan,
not that I’m aware of. The closest what I know about is this: https://mcuoneclipse.com/2014/07/13/listing-code-and-data-size-for-each-source-file-with-gnu-and-eclipse/
LikeLike
Hi Erich,
Today I found a better way, by copying the last macros on “Invoking: Cross ARM C++ Linker” in makefile file.
You only have to put “$(OBJS) $(USER_OBJS) $(LIBS)” without(“) on “Other flags” field, and done: you don’t need to write every file or every folder.
LikeLike
Thank you very much Erich! Worked perfectly!
LikeLike
Erich,
Is the sum of ‘text’ and ‘data’ sections the total space needed to fit in the Flash?
Bill
LikeLike
Hi Bill,
yes, see https://mcuoneclipse.com/2013/04/14/text-data-and-bss-code-and-data-size-explained/
Erich
LikeLike