Talk:LTO

From Gentoo Wiki
Jump to:navigation Jump to:search
Note
Before creating a discussion or leaving a comment, please read about using talk pages. In particular, sign comments using ~~~~ and add new discussions at the bottom of the page. Don't forget to make your discussion visible using {{Talk|date = 2024-05-14}}.
== Discussion title ==

{{Talk|date = 2024-05-13}}

A comment [[User:Larry the Cow|Larry the Cow]] 13:52, 13 May 2024 (UTC)
: A reply [[User:Sally the Spider|Sally the Spider]] 11:29, 14 May 2024 (UTC)
:: Another reply [[User:Larry the Cow|Larry the Cow]] 05:30, 14 May 2024 (UTC)
:: Your reply ~~~~

Navigate to first:

Idea: -Werror

Talk status
This discussion is done.

Based on the work going on with the Gentoo tinderbox, and confirmed anecdotally, the adding -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing can help replace subtle runtime failures with obvious compile failures. Making incompatible packages more obvious. The downside is that users may never trigger the runtime behaviour that would lead to the crash, and will definitely see the compile failure. — The preceding unsigned comment was added by Anthonyryan1 (talkcontribs) 2023-05-20T02:01:32‎

I tried to keep this pretty simple for users when writing so left this idea as being highlighted in Project:Toolchain/LTO in the See also section for those that like to enjoy troubleshoot more. If you have a better way to do this though then please add.
Immolo (talk) 11:37, 21 May 2023 (UTC)
Closing discussion while user decides if they wish to add their idea to improve.
Immolo (talk) 10:13, 25 May 2023 (UTC)

Common misconception: -fuse-linker-plugin

Talk status
This discussion is done.

-flto in CFLAGS, CXXFLAGS, etc. implies -fuse-linker-plugin Citation: https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-fuse-linker-plugin — The preceding unsigned comment was added by Anthonyryan1 (talkcontribs) 2023-05-20T02:01:32‎

If you think it is needed then please add.
Immolo (talk) 11:42, 21 May 2023 (UTC)
Please don't delete comments as the talk pages are only to discuss changes, if you wish to add this change then please add it to the main article.
Immolo (talk) 12:18, 22 May 2023 (UTC)
This particular section of the discussion was meant Q&A style rather than a discussion. I added it because there's been a lot of historical confusion about how to enable LTO on the Gentoo forums, reddit's /r/gentoo etc and various blogs. I felt it was worth noting in the discussion page. The citation linked above authoritatively states it is not necessary. I just wanted the note preserved here for future editors who may be coming to this page with imperfect information, as I was.
Anthonyryan1 (talk) 11:42, 21 May 2023 (UTC)

Common misconception: LDFLAGS

Talk status
This discussion is still ongoing.

Is it necessary to specify -flto in LDFLAGS? Should it be specified as -Wl,-flto or -flto Citation needed. — The preceding unsigned comment was added by Anthonyryan1 (talkcontribs) 2023-05-20T02:01:32‎

AFAIK it is not required anymore. Their are old forums posts that do say it's needed and I can see the GentooLTO overlay hasn't enabled it. If there is a better citation available then it would be great to have added but currently I can't find one I'm happy to add.
Immolo (talk) 11:46, 21 May 2023 (UTC)


Update for -flto=

Talk status
This discussion is still ongoing.

GCC now throws warnings when -flto is passed with no arguments or as -flto=1. -flto=jobserver attempts to detect jobs from the makefile jobserver but not all makefiles/ebuilds set this up correctly and gcc will fallback to -flto=auto. -flto=auto is basically just -flto={nproc}. Doing this has a pretty decent change of overloading user machines since we all pass --jobs x in our makeopts and some have --jobs x in our EMERGE_DEFAULT_OPTS. So someone already maxing out their cores with their job paralleling options is adding a square of more processes to it by using jobserver (in a non-trivial amount of cases) or auto. I propose adding a note to make your -flto argument the same as your makeopts jobs argument to avoid the generation of these warnings while not potentially overloading your system by use of the auto option/fallback.

See this thread from GCC patch mailing list for more info: https://inbox.sourceware.org/gcc-patches/CAFiYyc0CXeDVazbSebSb+RtP8nruSXa=CTRNBxZ4G4MRHKfgmA@mail.gmail.com/T/

Obiwanjacobi (talk) 03:30, 29 November 2023 (UTC)

-fno-lto does not always work

Talk status
This discussion is still ongoing.

I noticed that media-video/ffmpeg does not work with the -fno-lto -Wno-error-... overrides, something about the way it calls the linker.

I propose changing nolto.conf to the base flags instead of the overrides.

Crocodillian (talk) 13:58, 10 January 2024 (UTC)

Use -flto for gcc but -flto=thin for clang

Talk status
This discussion is done.

On a default gcc system some packages still compile with clang, for example chromium and firefox. With CFLAGS="... -flto ..." linking with clang takes hours and uses tens of gigabytes of memory. Is there an easy option to use -flto=thin for clang compilation instead?

Khumarahn (talk) 18:48, 21 April 2024 (UTC)

You can override per-package CFLAGS using /etc/portage/package.env. I don't think there's a special environment variable for Clang. — Waldo Lemmer 02:38, 22 April 2024 (UTC)
Yes, but then I need to keep track of which packages use clang, and this changes with time. Also what if a package uses both gcc and clang? (I don't know if this happens.) — Khumarahn (talk) 07:27, 22 April 2024 (UTC)
Unfortunately, I don't have a solution for you. I can't find a way to get gcc to ignore =thin, nor a way to pass arguments to clang only. Might I suggest asking at #gentoo (webchat)?
Talk pages are really just for discussions about article additions and corrections, so you probably won't get an answer here. However, once you do find a solution, feel free to add it to LTO. You can create a discussion here if you need help with that.
Waldo Lemmer 08:21, 22 April 2024 (UTC)
Thanks :-) This is such an obvious question, I was hoping that people who wrote the LTO page would just know an answer — Khumarahn (talk) 08:46, 22 April 2024 (UTC)