Skip to main content
Senior
December 20, 2025
Solved

Post-build step to size object files

  • December 20, 2025
  • 5 replies
  • 551 views

I'm using STM32CubeIDE Version 2.0.0 and would like to get the size of all the object files in my build. I know I can do this in Project Settings->C/C++ Build->Settings->Build Steps->Post-build steps->commands using arm-non-eabi-size, but what is the variable that expands to the names of the object files, and how do I use it?

Best answer by TDK

> it seems the .o files are not being retained

They're retained on my system. Default project settings.

TDK_0-1766261246894.png

> I need to know the current working directory for the post-build step and where the files are so I can size them.

The cwd is the build directory. Same directory as the ELF file. The *.o files are in subdirectories in the same structure as the *.c files in the project.

Should be very doable to find all *.o files in a script and do arm-none-eabi-size on them.

5 replies

TDK
Super User
December 20, 2025

> I'm using STM32CubeIDE Version 2.0.0 and would like to get the size of all the object files in my build.

This is available with the default build settings.

After building, go to the Build Analyzer, refresh, then go to the Memory Details tab and you can see the size of each object.

TDK_0-1766252541689.png

 

"If you feel a post has answered your question, please click ""Accept as Solution""."
Senior
December 20, 2025

Well, the information is there, but not as useful as I'd like. For my NXP projects, I get a listing, by object file, similar to the summary shown in the Console pane  for the .elf file, which I see the text, data, and bss usage.

TDK
Super User
December 20, 2025

I don't think it's broken down by compilation unit (*.o file) anywhere. Objects get removed by the linker so what's in the compilation units is not the same as what's in the final binary. Two object files can contain the same data so you can't just sum them up.

Perhaps you can show a screenshot of what you're looking for.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Senior
December 20, 2025

No, it's not. What I want to do is run arm-none-eabi-size on each of the compiled object files. Looking at the build directory, it seems the .o files are not being retained, so I need them to remain so I can get their individual sizes. I'm fluent in shell scripting; I need to know the current working directory for the post-build step and where the files are so I can size them.

AScha.3
Super User
December 20, 2025

Ah, the files are in -> debug/.../src , see all "src" for core, drivers, middleware, third party, etc.

AScha3_0-1766261437352.png

But afaik not very useful, as there is all of the libs etc., but the optimizer+linker takes only , whats used in target program. So this is more like a useless info about possible size.

What i showed , in "memory details" , is whats really used then.

"If you feel a post has answered your question, please click ""Accept as Solution""."
TDK
TDKBest answer
Super User
December 20, 2025

> it seems the .o files are not being retained

They're retained on my system. Default project settings.

TDK_0-1766261246894.png

> I need to know the current working directory for the post-build step and where the files are so I can size them.

The cwd is the build directory. Same directory as the ELF file. The *.o files are in subdirectories in the same structure as the *.c files in the project.

Should be very doable to find all *.o files in a script and do arm-none-eabi-size on them.

"If you feel a post has answered your question, please click ""Accept as Solution""."
Senior
December 20, 2025

Arrrgh!! The IDE is to blame. File Explorer shows all the files, but the IDE takes a condescending attitude, showing only what it thinks I need.

Senior
December 20, 2025

I finally got what I wanted:

sh -c "arm-none-eabi-size Core/src/*.o"
 text	 data	 bss	 dec	 hex	filename
 763	 12	 2056	 2831	 b0f	Core/src/FreeRTOS_CLI.o
 124	 0	 0	 124	 7c	Core/src/MCP9808.o
 6763	 11	 2177	 8951	 22f7	Core/src/cli_app.o
 878	 0	 24	 902	 386	Core/src/commsModule.o
 0	 0	 0	 0	 0	Core/src/freertos.o
 3222	 1	 1581	 4804	 12c4	Core/src/main.o
 846	 0	 24	 870	 366	Core/src/modemModule.o
 862	 4	 0	 866	 362	Core/src/reports.o
 2741	 34	 17489	 20264	 4f28	Core/src/sensors.o
 764	 0	 0	 764	 2fc	Core/src/stm32f4xx_hal_msp.o
 200	 0	 72	 272	 110	Core/src/stm32f4xx_hal_timebase_tim.o
 180	 0	 0	 180	 b4	Core/src/stm32f4xx_it.o
 220	 4	 4	 228	 e4	Core/src/syscalls.o
 64	 0	 4	 68	 44	Core/src/sysmem.o
 152	 4	 0	 156	 9c	Core/src/system_stm32f4xx.o
 19	 8	 0	 27	 1b	Core/src/version.o