Compiler Flags For Reducing Binary Size

Hello All,

So I’ve finally hit the wall of running out of APP_FLASH. I was looking into custom compiler flags to reduce the app binary size(e.g. Just wondering if anyone has any experience in doing this for particle.

I’ve read a view form posts about this and I do know that I need to build this locally.

With Device OS 2.0.0 you’ll need to modify the Workbench Makefile to add the COMPILE_LTO=y option to the options for building the user firmware binary. For example, for the compile and flash target:

# Compile and flash the user part
flash-user: dfu preprocess
	$(call print_stage,FLASHING APPLICATION)
	cd "$(value DEVICE_OS_PATH)/main" && make all program-dfu COMPILE_LTO=y
	$(call print_success,FLASHED SUCCESSFULLY)

This only works with 2.0.0-rc and later. Make sure you Clean application after changing the value. This will also increase the time spent in the link phase, but it will make the binary smaller.

1 Like

@rickkas7 thanks for the reply.

Good to know there is an option. I see that v2.0.0-rc.4 just got release today. I’ll try this out.

Do we have an approximate/tentative ETA on when v2.0.0+ will move out of the RC phase?

Sorry for the lame question. I cannot find how to edit the Workbench Makefile to add this COMPILE_LTO=y flag. Can I ask for a tip here please?

I think this will be in the particle tool chain folder. OS 2.0.0 just released a few days ago so I was thinking of giving this a shot sometime next week.

Tool chain folder in windows is probably in the path:


Make sure you download the OS 2.0.0 toolchain and it should appear in that folder

@rickkas7 correct me if I am wrong. I “THINK” this is what we should do. Note I am not too sure which “exact” folder it is as well.

It seems that location is correct. I implemented the changes suggested. However, the binary size of my app didn’t changed after all. On the other hand the size of the binary reduced a couple of kB after I migrated from 1.5.2 to 2.0.0.



@rickkas7 did mention that the device’s OS will have to be 2.0.0 so I guess this will explain the size only changing upon upgrading.

Glad to see you got some results!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.