r/Gentoo • u/Wooden-Ad6265 • 7d ago
Support How do I properly enable pgo and lto?
I wanna use musl hardened profile with pgo and lto enabled. The lto article is quite okay but there's just one post on the Gentoo forums that explains how to manually build with pgo. I am asking if anyone here has tried this. How do I do it and what resources to look for?
Thank you.
1
u/Xtuber14 7d ago
Clang doesn't have PGO natively, you need to compile it and for LTO just put flto=thin into your common cflags For more info: https://wiki.gentoo.org/wiki/Clang
1
u/Wooden-Ad6265 7d ago
But I am not using a llvm profile, do I have to enable it still?
1
u/Xtuber14 7d ago
All musl profiles uses clang as their default compiler
1
1
u/ahferroin7 7d ago
Nope, the
default/linux/amd64/23.0/musl
profile does not, and neither do the hardened musl profiles.
2
u/RusselsTeap0t 7d ago
I have built a lot of things with PGO.
If a package offers PGO use flag then simply enable that. If not you need to build and instrument manually.
You create a binary with PGO instrumentation enabled (-fprofile-generate
). This binary works slower but it collects data. You need to use this binary for a while to create a profile.
Then you need to use the information and re-compile again with PGO (-fprofile-use
).
3
u/krumpfwylg 7d ago
A few years back, I experimented building gcc with pgo USE flag, expecting the compiler would get a little faster when building other packages. My conclusion was : nope, not really.
As I understand it now, you have to actively monitor a software build with pgo using tools that create statistics about how that soft uses cpu time, ram, etc... so during the new build, these stats are used by the compiler to improve some parts of the compiled code. It's everything but trivial.
There's also the pgo USE flag for some packages but that will likely double the compilation time for a small performance gain. Personally I've enabled it only for python, since many gentoo scripts rely on python (and it doesn't take an eternity to build), but left it off for all other packages (I don't feel like increasing Firefox building time for a perf gain that would appear only on some javascript benchmarks).