platformio / platform-atmelavr

Atmel AVR: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/atmelavr
Apache License 2.0
139 stars 105 forks source link

LTO causes internal compiler error #65

Closed freespace closed 6 years ago

freespace commented 7 years ago

Occasionally avr-gcc will crash when compiling:

Linking .pioenvs/uno/firmware.elf
/home/steve/.platformio/packages/framework-arduinoavr/cores/arduino/main.cpp: In function 'main':
/home/steve/.platformio/packages/framework-arduinoavr/cores/arduino/main.cpp:51:1: internal compiler error: Segmentation fault
}
^
Please submit a full bug report,
with preprocessed source if appropriate.
See <http://gcc.gnu.org/bugs.html> for instructions.
lto-wrapper: avr-g++ returned 1 exit status
/home/steve/.platformio/packages/toolchain-atmelavr/bin/../lib/gcc/avr/4.9.2/../../../../avr/bin/ld: lto-wrapper failed
collect2: error: ld returned 1 exit status
*** [.pioenvs/uno/firmware.elf] Error 1

This seems related to link time optimisation: https://github.com/sudar/Arduino-Makefile/issues/486

I can verify that adding the following to my environment resolves the issue:

build_unflags = -flto

However on code where this workaround is not required, LTO does reduces binary size.

I am not sure what the correct fix is as this seems to be an issue from the bowels of the compiler. However this ticket should help future users when googling the symptoms.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/48822812-lto-causes-internal-compiler-error?utm_campaign=plugin&utm_content=tracker%2F38207915&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F38207915&utm_medium=issues&utm_source=github).
ivankravets commented 6 years ago

Please pio update to the latest version. The toolchains were updated before.