make: optionally build with gcc's link time optimization#1927
make: optionally build with gcc's link time optimization#1927thomaseichinger merged 2 commits intoRIOT-OS:masterfrom
Conversation
|
IIRC lto needs at least gcc-4.7.x while gcc-4.9.x is recommended. Does this fail for lower gcc versions? Or is it just quietly ignored? |
|
@N8Fear Well, it's disabled by default. You have to manually add |
|
If it can be defined in the applications Makefile it could lead to unnecessary errors that a user may not understand correctly. Wouldn't it make sense to check for the compilerversion and drop LTO if not supported? |
|
IMHO we should add the option (LTO=yes) now for us to play with it if we want to. Took me some fiddling out the options / the syscall attributes to get a compile. As soon as we have more insight on implications / compatibility stuff etc. we can automate LTO=yes/no. No need for a perfect solution with the first commit. |
|
@Kijewski AFAIK -flto will drop anything not needed for the link. That would implicitly include --gc-sections. |
|
I did compile some applications with these options and iot-lab_M3
no options
text data bss dec hex filename
33016 168 8436 41620 a294 RIOT/examples/default/bin/iot-lab_M3/default.elf
-flto -ffat-lto-objects
text data bss dec hex filename
9904 108 784 10796 2a2c RIOT/examples/default/bin/iot-lab_M3/default.elf
--gc-sections
text data bss dec hex filename
28304 168 8432 36904 9028 RIOT/examples/default/bin/iot-lab_M3/default.elf
-flto -ffat-lto-objects --gc-sections
text data bss dec hex filename
0 0 512 512 200 RIOT/examples/default/bin/iot-lab_M3/default.elf
stm32f0discovery
no options
text data bss dec hex filename
19096 148 4804 24048 5df0 RIOT/RIOT/examples/default/bin/stm32f0discovery/default.elf
--gc-sections
text data bss dec hex filename
15244 148 4804 20196 4ee4 RIOT/examples/default/bin/stm32f0discovery/default.elf
-flto -ffat-lto-objects
text data bss dec hex filename
12880 104 2840 15824 3dd0 RIOT/examples/default/bin/stm32f0discovery/default.elf
samr21-xpro
no options
text data bss dec hex filename
24040 152 10472 34664 8768 RIOT/examples/default/bin/samr21-xpro/default.elf
--gc-sections
text data bss dec hex filename
17744 152 10472 28368 6ed0 RIOT/examples/default/bin/samr21-xpro/default.elf
-flto -ffat-lto-objects
text data bss dec hex filename
23992 152 10472 34616 8738 RIOT/examples/default/bin/samr21-xpro/default.elf |
|
@thomaseichinger I would guess the failures on iot-lab_M3 is related to the fact that the binary was completely stripped of all code when compiled with Try setting Here's a related post about similar problems when using LTO: http://www.coocox.org/forum/topic.php?id=3002 |
|
@gebart The combination of |
0198e7f to
56cc8d4
Compare
|
Rebased, added iot-lab_M3 support: With LTO: |
|
@thomaseichinger The table holding pointers to interrupt vectors needed to be marked ((used)). |
|
Is this fully funtional now? The following syntax is ok using the BFD linker, but not with GOLD: The problem is that GOLD does not understand the address specification after the section name. |
|
@gebart This is functional on native and iot-lab_M3. |
|
bump |
56cc8d4 to
aa87f61
Compare
|
rebased |
|
Sounds good to me. |
|
Is it necessary to mark all syscalls with The interrupt vector table on the other hand is only accessed by hardware IRQs which makes it necessary to tell the linker that it is used. |
|
I'm ok with adding this optionally although for me it currently bloats the binary. I didn't test with any 4.9.* gcc version though. % make clean flash BOARD=iot-lab_M3 LTO=yes
...
text data bss dec hex filename
46440 172 8444 55056 d710 RIOT/examples/default/bin/iot-lab_M3/default.elf% make clean flash BOARD=iot-lab_M3 LTO=no
...
text data bss dec hex filename
33120 168 8444 41732 a304 RIOT/examples/default/bin/iot-lab_M3/default.elf |
|
@thomaseichinger I tried it with GCC 4.9.2 and newlib master from git (2014-12-12 20:00 CET-ish): and with 4.8.3: I don't know why I get such a large file for Curiously, I can not link with LTO using GCC 4.8.3: |
|
Try some benchmarks. Synthetic messaging tests get >25% faster. |
|
So, anyone objecting this? @thomaseichinger, @gebart, do you agree to enable this for testing purposes for a while before we think about how to integrate it into mainline in a proper way? |
|
Fine for me. |
|
I am fine with even if it may break some builds this since it is an optional extra functionality. |
|
I found a bug/oversight in the lpc2387 linker script, will post a PR later today. |
|
@kaspar030 Needs rebase. |
361f195 to
9fffd99
Compare
This commit enables building using link time optimization when specifying "LTO=yes" in the application's Makefile.
Enables gcc LTO for stm32f1 based boards
|
rebased, dropped LPC2387 stuff. |
|
So, do we agree on integrating this (optionally) now and enabling it for toolchain/architecture combinations later? |
|
ACK from my side, @thomaseichinger ? I would like to revisit this at a later date when LTO support within the various toolchains is more mature and widespread, but I'm fine with the current changes for the time being since it is nothing intrusive. |
|
Fine with me. Let's see how this evolves. ACK & Go |
make: optionally build with gcc's link time optimization
This commit enables building using link time optimization when
specifying "LTO=yes" in the application's Makefile (or compile with LTO=yes make ...).
Size comparisions:
Tested only with native and msba2.
On msba2, the syscalls needed attribute(used), causing default to use 16byte more in .text when not using LTO.