Split text and data sections if possible#723
Split text and data sections if possible#723Kijewski wants to merge 3 commits intoRIOT-OS:masterfrom Kijewski:fdata-sections
Conversation
In #664 I added a test that determines if the supplied compiler understands the `-fno-delete-null-pointer-checks` flag. The problem is that the `$(CC)` supplied on command line or in the application's Makefile is used, but not the one the `$(BOARD)`'s Makefile sets. That problem was overlooked as all the boards use GCC, and GCC happens to know the flag. But if some future board does not use GCC, then the wrong order of the checks could pose a problem.
This patch adds `-ffunction-sections` and `-fdata-sections` to the
`CFLAGS` if the compiler understands these flags (at least clang and GCC
do).
These flags cause every function and every static variable to go into
a section of its own in the object file. The static linker is then able
to drop functions/variables if they are not used.
The results are quite impressive ("default", BOARD=native, CFLAGS=-Os):
```
With patch:
text data bss dec hex filename
36686 552 108520 145758 2395e …/default.elf
Without patch:
text data bss dec hex filename
43944 580 109544 154068 259d4 …/default.elf
```
|
The PR is based on #722. |
|
I'm not sure if this is gonna work on ARM7. With patch: Without: |
|
|
|
Maybe https://github.com/Kijewski/RIOT/pull/2 helps but I'm not so sure if this is enough. |
|
Hm, the linker scripts need to be fixed to enabled gc-sections. The problem is only not only that the entry point needs to be specified, but also that the entry code has to be proper. I think I have fixed the startup code for msba2, but I cannot test it. The scraped functions look about right. |
|
I cannot find |
|
|
|
I think this is a very good idea, but the linkerflags should be set inside the boards Makefile instead of the global Makefile.include - because for this optimization to work the linker/startupscripts for each platform needs to be adjusted... |
|
I will test this on a per module board basis. |
This patch adds
-ffunction-sectionsand-fdata-sectionsto theCFLAGSif the compiler understands these flags (at least clang and GCCdo).
These flags cause every function and every static variable to go into
a section of its own in the object file. The static linker is then able
to drop functions/variables if they are not used.
The results are quite impressive ("default", BOARD=native, CFLAGS=-Os):