Listing Code and Data Size for all Files with the GNU size Utility in a Post-Build Action

The GNU size utility which is part of the GNU build tools shows code and data size for archive or object files. It is usually used as a post-build step in Eclipse CDT to show text, data and bss at the end of the build:

Detailed size information for each file

Detailed size information for each file

Usually the ‘size’ utility is used to show information about the binary in an Eclipse CDT post-build action:

post build step in MCUXpresso IDE

post build step in NXP MCUXpresso IDE

The Eclipse based NXP MCUXpresso IDE has the ‘Image Info’ plugin which gives detailed information about what is used by the linked ELF/Dwarf file:

Image Info Plugin in MCUXpresso IDE

Image Info Plugin in MCUXpresso IDE

The above view and information is what is used in the linked application. Still it can be very useful to get size information for all the linked object files.

:info: Keep in mind that the linker will ‘strip’ any unused function, variable or constant for the final image, so the size information for each object file is the worst case.

To list the size information in a post-build, I could list the desired object files as argument to the post-build action. A very useful trick is to use the $(OBJS) macro which holds all the object files. That Macro is defined in the make files:

OBJS Macro in Make File

OBJS Macro in Make File

So I can use that macro in the post-build action for the ‘size’ command, shown below for the case of the MCUXpresso IDE:

arm-none-eabi-size $(OBJI) in the post-build action

arm-none-eabi-size $(OBJI) in the post-build action

That way I get the details for each object file too:

Detailed size information for each file

Detailed size information for each file

And there is yet another useful trick if you need a listing of the application: add the following as post-build command (thanks for commenting on this, Konstantin!):

arm-none-eabi-objdump -S “${BuildArtifactFileName}” > “${BuildArtifactFileBaseName}.lst”

Happy Sizing 🙂

Links

5 thoughts on “Listing Code and Data Size for all Files with the GNU size Utility in a Post-Build Action

  1. Hello !
    I’ll add a little from myself.
    Sometimes it is useful to get a listing of the program.
    Can add Post-build steps
    arm-none-eabi-objdump -S “${BuildArtifactFileName}” > “${BuildArtifactFileBaseName}.lst”

    Like

  2. Handy hints thank you gentlemen!
    I also add this:
    touch “${ProjDirPath}/../Sources/lib/version.c”
    This forces version.c to rebuild next time, because it contains
    char const gCompileTime[] = __DATE__ ” ” __TIME__;
    which is handy for tracking the actual build time. This is the minimum work the build process has to do each time.
    And
    time
    so I know when the build has finished, to save me accidentally rebuilding and wasting time (when I forget if I have built or not).

    Like

Leave a Reply to Erich Styger Cancel reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.