I have a tree-shaped process/task architecture in my FreeRTOS construct. The main() simply creates a RootTask (after initializing the HAL), which creates another two tasks, and so on.
I'm currently fighting with flash size (code + constants, basically?), and therefore disabling tasks (=commenting them) in order to show the compiler that most translation units are not even needed, to find out which modules are most expensive.
However, I've "commented my way up" to main() and took out EVERYTHING except the while(1) loop. It still doesn't fit in 128k Flash. Tried removing all C++ translation units, using even gcc for linking; but still ~100k ".text" section (I would be fine with 10k at this point, considering the application doesn't do anything).
I'm using arm-none-eabi-gcc/g++ 5.4.1. The linker script was generated by ST-CubeMX.
gcc flags:
-mcpu=cortex-m0 -mthumb -Os -s -Wall -Wa -a -ad -alms=build/$(notdir $(<:.c=.lst))
Linker flags:
-mcpu=cortex-m0 -specs=nosys.specs -T$(LDSCRIPT) [some-libraries] -Wl,-Map=$(BUILD_DIR)/$(TARGET).map,--cref -Wl,--gc-sections,--undefined=uxTopUsedPriority,-flto
(also generated by CubeMX, except -flto)
Can someone explain why the Compiler/Linker are not removing unused code from the final binary? Are there tools to investigate further?
Please let me know if more information is needed.
Thank you!