buildsystem: enable LTO by default#22338
Conversation
|
Is it ethical to approve this with "LGTM" |
|
Looks like LLM slop. Just merge yolo |
Murdock will have the last word on that |
Murdock results❌ FAILED 0aa9603 fixup! treewide: mark functions as used to avoid LTO linker problems Build failures (1)
Test failures (6)
Artifacts |
|
Reddit says, that the Adding Edit: I just checked and The LDFLAG addition of course has to be guarded to only be added when using LLVM. |
|
Now it seems we are mostly down to this ESP32 (gcc) issue: /opt/esp/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/bin/ld: /opt/esp/xtensa-esp-elf/bin/../lib/gcc/xtensa-esp-elf/14.2.0/../../../../xtensa-esp-elf/lib/esp32/libg_nano.a(libc_a-__call_atexit.o):/builds/idf/crosstool-NG/.build/xtensa-esp-elf/src/newlib/newlib/libc/stdlib/__call_atexit.c:17:(.data+0x0): undefined reference to `__lock___atexit_recursive_mutex'
collect2: error: ld returned 1 exit statusand some spurious ones (non-exhaustive list): /opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc_nano.a(lib_a-signal.o): in function `_raise_r':
signal.c:(.text._raise_r+0x2e): undefined reference to `_kill_r'
collect2: error: ld returned 1 exit statusBuilding application "lwip_ipv4" for "nrf52840dk" with CPU "nrf52".
(...)
/opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib/thumb/v7e-m+fp/hard/libc_nano.a(lib_a-signal.o): in function `_raise_r':
signal.c:(.text._raise_r+0x20): undefined reference to `_getpid_r'
/opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: signal.c:(.text._raise_r+0x2e): undefined reference to `_kill_r'
collect2: error: ld returned 1 exit statusBuilding application "tests_nanocoap_cli" for "atmega256rfr2-xpro" with CPU "atmega256rfr2".
(...)
/tmp/ccm2IZTu.ltrans0.ltrans.o: In function `_cmd_put':
<artificial>:(.text._cmd_put+0xf6): undefined reference to `__wrap_strerror'
/tmp/ccm2IZTu.ltrans11.ltrans.o: In function `_nanocoap_put_handler':
<artificial>:(.text._nanocoap_put_handler+0x102): undefined reference to `__wrap_strerror'
/tmp/ccm2IZTu.ltrans11.ltrans.o: In function `_nanocoap_get_handler':
<artificial>:(.text._nanocoap_get_handler+0xa2): undefined reference to `__wrap_strerror'
<artificial>:(.text._nanocoap_get_handler+0x250): undefined reference to `__wrap_strerror'
collect2: error: ld returned 1 exit statusBuilding application "tests_ssp" for "nrf52840dk" with CPU "nrf52".
(...)
/opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: /tmp/tests_ssp.elf.bo40wB.ltrans0.ltrans.o: in function `uart_write.constprop.0':
<artificial>:(.text.uart_write.constprop.0+0x36): undefined reference to `__stack_chk_fail'
/opt/gcc-arm-none-eabi-10.3-2021.10/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/bin/ld: <artificial>:(.text.uart_write.constprop.0+0x9c): undefined reference to `__stack_chk_guard'
collect2: error: ld returned 1 exit status |
|
I was so sneaky as to add a commit that adds some I've also double-checked that the functions actually do not end up in the binary when they are not actually used, and it appears they do not: The Let's see what else Murdock comes up with. |
|
I think the AVR GCC in riotdocker is a bit too vintage for LTO |
But it might also be just an issue with that particular example, given that all the other binaries build just fine also for AVR. |
|
Regarding the failing $ make -C tests/sys/ssp all -j test
(...)
main(): This is RIOT! (Version: 2026.07-devel-300-g0aa960-use_lto)
calling stack corruption function
make[1]: *** [/home/mikolai/TUD/Code/RIOT-build/Makefile.include:877: cleanterm] Segmentation fault
Unexpected end of file in expect script at "child.expect('.*stack smashing detected.*')" (tests/sys/ssp/tests/01-run.py:15)
Process already stopped
make: *** [/home/mikolai/TUD/Code/RIOT-build/makefiles/tests/tests.inc.mk:32: test] Error 1
make: Leaving directory '/home/mikolai/TUD/Code/RIOT-build/tests/sys/ssp'It seems from looking at the binary, that the stack protection is not added to the function by GCC when LTO is enabled, although the buffer is still allocated on the stack and written over its bounds (hence the segmentation fault). This contradicts the GCC doc on -fstack-protect and looks like a bug in GCC. I've found two possible workarounds to get GCC to still add stack protection to the function with LTO enabled:
Any opinions on which approach we should take? Btw, found #13175 on the way which might be good giving another spin as well. |
Contribution description
Let's see where we are at this now.
Testing procedure
Issues/PRs references
Replaces #14795.
Declaration of AI-Tools / LLMs usage:
AI-Tools / LLMs that were used are: