platformio / platform-espressif32

Espressif 32: development platform for PlatformIO
https://registry.platformio.org/platforms/platformio/espressif32
Apache License 2.0
901 stars 609 forks source link

Use GCC wrapped ar & ranlib to enable LTO #1329

Closed deece closed 6 months ago

deece commented 6 months ago

As per https://github.com/platformio/platform-ststm32/issues/386

Link Time Optimisation shifts compilation to the final link, allowing for more aggressive optimisations.

AR & RANLIB need to use their gcc equivalents to enable this, and will otherwise behave identically if LTO data is not in the objects.

(This should probably be done for all platforms)

deece commented 6 months ago

Note: This appears to a rehash of https://github.com/platformio/platform-espressif32/pull/702

Jason2866 commented 6 months ago

Using LTO since over a year with project Tasmota and it is working. Knowing from maintainer of project EspEasy he is using too and it works well here too.

valeros commented 6 months ago

The espressif32 dev-platform is more popular than ststm32, so all steps regarding build system should be carefully considered. LTO in embedded builds is a controversial topic, so I'm a bit reluctant to enable it by default, mainly because of the aggressive optimizations as you mentioned. We try to differ as little as possible from the original tools used in frameworks, so if you still interested in enabling LTO for ESP32 targets, please file a feature request in the Espressif repositories in the first place.

Jason2866 commented 6 months ago

@valeros espressif Arduino is already using elf-gcc-ar https://github.com/espressif/arduino-esp32/pull/8013

valeros commented 6 months ago

@Jason2866 thanks for the info. I didn't notice this change in 2.0.14, so I believe it's currently only available in the core dev branch for v3.x?

Jason2866 commented 6 months ago

@valeros Yes, it is added in dev branch v3.x and will be there in release v3.0.0 I added in my fork for core 2.0.14 and it is working there too.

deece commented 6 months ago

@valeros this change in itself doesn't enable LTO, it just removes things that get in the way of enabling it.

It should be completely transparent to non-LTO builds.

Jason2866 commented 6 months ago

Exactly, without explicit enabling LTO there will be no change in compiled code by merging the PR. Yes, imho LTO should always disabled by default in an standard setup. This is the case here. The build scripts have explicitly set -fno-lto. So this changes is full backwards compatible. https://github.com/espressif/arduino-esp32/blob/75b7f4b646599426e92ebec913a4dce14ef528cd/tools/platformio-build-esp32.py#L84

valeros commented 6 months ago

Thanks for the PR, merged!