I have used the ‘classic’ CodeWarrior IDE for years, before I moved over to Eclipse some years ago. And as with any IDE or tool switch, things are different in the ‘new world’. In summary, I don’t want to go back anyway, and Eclipse is my development tool of choice now. But from time to time I get challenged about something like “hey, this was possible in the previous tool, so how can I do the same in Eclipse?”. As a fan of Eclipse, this then gets my attention as I feel that Eclipse can do it, and it can do it better. 😉
So what about this one: In CodeWarrior the project view lists code and data size for each source file:
CodeWarrior can easily do this, as it maintains an internal data base of the code and details of each compilation unit/file. To me, that feature is nice, but had not much relevance for me, as this does not tell me what will be the code and data size in the application (.elf) file. Because the linker will be smart enough to strip unused functions and data.
Anyway, how to do this in Eclipse and GNU tools? Actually, I have not found a way to show it in a nice view :-(. But I know from my post “Printing Code Size Information in Eclipse” that the ‘size’ utility prints code and data size. But by default only for the application after linking. Which is what I need anyway. But what about listing code and date size for the source files?
My solution is to list the object files as ‘other flags’ the ‘print size’ settings in the project:
💡 With the GNU GCC ARM Embedded (launchpad) 4.8.x it is possible to use wildcards like Sources\*.o. This is not supported in the GNU tools in KDS, as they are using older or different tools, but you can swap the tools chain, see “Switching ARM GNU Tool Chain and Libraries in Kinetis Design Studio“.
💡 see the comments section: you can try using Generated_Code\\*.o Sources\\*.o (double slashes) to have the wildcards working.
I can use relative paths, as at least with the GNU ARM Eclipse plugins the GNU tools have the ‘output’ folder as current directory:
This then lists the size information at the end of the link phase:
'Invoking: Cross ARM GNU Print Size' arm-none-eabi-size --format=berkeley Sources\Events.o Sources\main.o Generated_Code\Cpu.o Generated_Code\WAIT1.o Generated_Code\IO1.o Generated_Code\CsIO1.o "K64_PEx_Printf.elf" text data bss dec hex filename 12 0 0 12 c Sources\Events.o 140 0 0 140 8c Sources\main.o 108 0 0 108 6c Generated_Code\Cpu.o 188 0 0 188 bc Generated_Code\WAIT1.o 824 0 24 848 350 Generated_Code\IO1.o 276 0 0 276 114 Generated_Code\CsIO1.o 10572 712 8496 19780 4d44 K64_PEx_Printf.elf 'Finished building: K64_PEx_Printf.siz'
In the NXP MCUXpresso IDE this can be added to the Post-Build Steps e.g. like this:
and it gives:
Another way is to use the $(OBJS) macro which lists all objects plus the final binary (ELF) file. The ‘Show totals’ will use the ‘–totals’ option: be careful as this sums up the size of the object files, so it is a kind of worst-case as the linker will remove unused functions and data.
For another way to get this kind of information see “Listing Code and Data Size with GNU nm in Eclipse“.
It is possible to list the code and data size for each source (well, object) file in Eclipse. I admit it is not in the project view or in a graphical view, and I need to list the object files individually. So I do not say that Eclipse can do the *same*, but I think it is very close 😉
Happy Sizing 🙂