0
votes

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!

1
Please also show the compilation flags passed to gcc/g++.Erlkoenig
I vote close - I understand your issue - but for a sort of question like this you provide too little information. To start: where can documention of the relevant systems be found (so everyone does not have to look this up themselves) ? compile flags are missing, what else did you do ? which options did you already try (yes, Im expecting this) ?darune
added gcc flags (skipped c++, as this seems not c++ related anymore). @darune I thought this is more of a general question, and I think it is a simple question, so I tried keeping it short. I tried many combinations of compile flags, none of which made a difference.bananenbär
"in order to show the compiler that most translation units are not even needed, to find out which modules are most expensive." - That is a flawed method. The linker map file will provide that information directly.Clifford

1 Answers

5
votes

You need to pass the flags -ffunction-sections -fdata-sections to the compiler (gcc/g++) such that --gc-sections in the linker works, and -flto to the compiler such that -flto in the linker can do its work.