Skip to content

Use gcc-ar and gcc-ranlib #702

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Use gcc-ar and gcc-ranlib #702

wants to merge 1 commit into from

Conversation

krzmaz
Copy link

@krzmaz krzmaz commented Jan 10, 2022

In order to use link time optimizations (lto) ar and ranlib need to have the lto plugin supplied. This is achieved easiest by using the gcc-* equivalents. More info:
https://embeddedartistry.com/blog/2020/04/13/prefer-gcc-ar-to-ar-in-your-buildsystems/
This won't affect most builds at all, because lto is disabled in the framework package. As far as I've found this setting comes from espressif/esp-idf#3989 and is more of a hotfix for Mac builds than a needed change.

I've successfully enabled lto in my project without any functional differences, achieving ~5% flash usage reduction.

@Jason2866
Copy link
Contributor

@TheRealMazur Great find! Just tried and compiled on Apple M1 and the flash size reduced from 1.427.984 bytes to 1.276.720 bytes. 147k less flash used.

@krzmaz
Copy link
Author

krzmaz commented Jan 14, 2022

@Jason2866 just to be sure - you tried applying my changes and enabling lto, right? This PR should not have any effects without enabling lto AFAIK 😅

@Jason2866
Copy link
Contributor

Jason2866 commented Jan 14, 2022

Yes, since I forked this github, and espressif Arduino32 for our needs already it was a easy change to use the option lto for compile and linking

@krzmaz
Copy link
Author

krzmaz commented Jan 14, 2022

Just keep in mind that this can mess up backtrace symbols. I needed to add -ggdb linker flag to have the full debug info, which surprisingly increased the flash usage (the end result was still better than without lto, but I was sure any debug symbols will be stripped before flashing - I'm planning to investigate that further).

@Jason2866
Copy link
Contributor

For me using -flto for C3 does not work. Ends in bootloop.
S2 and ESP32 does work without any problems.

@krzmaz
Copy link
Author

krzmaz commented Jan 20, 2022

It's possible that some specific linker flags or scripts would need to be modified to work with C3. That shouldn't block this PR, as it merely allows for opting in to use lto.

Unfortunately I'm not able to help you with with debugging C3, as I don't own one.

@Jason2866
Copy link
Contributor

yes, this PR should be merged!

@stale
Copy link

stale bot commented Jul 30, 2022

This issue has been automatically marked as stale because it has not had recent activity. Please provide more details or it will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 30, 2022
@krzmaz
Copy link
Author

krzmaz commented Jul 30, 2022

@valeros @ivankravets Sorry for the direct pings but I'm not sure how to get some progress on this PR. Could you help move it forward?

@stale stale bot removed the stale label Jul 30, 2022
@Jason2866
Copy link
Contributor

We use in our fork for Tasmota. lto works great, excluding the c3 (known gcc compiler bug, solved in actual gcc version).

@Jason2866
Copy link
Contributor

Bump

@ivankravets ivankravets requested a review from valeros March 7, 2023 19:34
@ivankravets
Copy link
Member

ivankravets commented Mar 7, 2023

This is an official dev-platform and we try to keep it in accordance with official Espressif build workflows. Nevertheless, you can customize the toolchain for your project by leveraging PRE scripting:

platformio.ini

[env]
extra_scripts = pre:custom_toolchain.py

custom_toolchain.py

Import("env")

env.Replace(
    AR="xtensa-esp32-elf-gcc-ar",
    RANLIB="xtensa-esp32-elf-gcc-ranlib"
)

Could you try the snippet above?

@Jason2866
Copy link
Contributor

Good reason. @me-no-dev can we switch to this versions?

@me-no-dev
Copy link

@Jason2866 feel free to PR to the 5.1-libs branch. We can have it as part of 3.0.0

@softhack007
Copy link

+1 👍 for merging this into development.

@krzmaz krzmaz closed this by deleting the head repository Nov 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants