mirror of
https://github.com/gentoo-mirror/gentoo.git
synced 2026-11-21 10:37:22 -08:00
f4e964aa2024f09da289f71768cc9b09c1ab09cf
Introduce a new eclass with utility functions for handling LTO bytecode (or internal representation, IR) inside static archives (.a files). Static libraries when built with LTO will contain LTO bytecode which is not portable across compiler versions or compiler vendors. To avoid pessimising the library and always filtering LTO, we can build it with -ffat-lto-objects instead, which builds some components twice. The installed part will then have the LTO contents stripped out, leaving the regular objects in the static archive. It's not feasible to make these work otherwise, as we'd need tracking for whether a library was built by a specific compiler and its version, and that compatibility can vary based on other factors (e.g. with gcc, sys-devel/gcc[zstd] controls if it supports zstd compression for LTO). We also discourage static libraries anyway. Provide two functions: * lto-guarantee-fat If LTO is currently enabled (as determined by `tc-is-lto`, added in2aea6c3ff2), add `-ffat-lto-objects` to CFLAGS and CXXFLAGS if supported. This guarantees that produced archives are "fat" (contain both IR and regular object files) for later pruning. * strip-lto-bytecode Process a given static archive (.a file) and remove its IR component, leaving a regular object. This approach is also taken by Fedora, openSUSE, and Debian/Ubuntu. An honourable mention to `lto-rebuild` which fulfilled the same task for many in the LTO overlay too. We did consider an alternative approach where we'd relink objects using the driver in src_install (or some hook afterwards), but this would be more brittle, as we'd need to extract the right arguments to use (see e.g. the recent Wireshark issues infad8ff8a45for how this can be subtle) and not PM-agnostic given we don't have portable hooks right now (and even if we did, suspect they wouldn't work in a way that facilitated this). It's also not clear if such an approach would've worked for Clang. The tests have been quite helpful in debugging this and making sure things work as expected. They both make sure the eclass does what it ought to, but also try to capture the expected interaction with the toolchain (which is why we have the skips depending on tooling & versions) to allow us to test workarounds and make sure we understand the interactions fully: it made it easy to test e.g. a patch to Binutils to make strip have plugin/LTO integration (PR21479). All of this wasn't worth pursuing until H. J. Lu's patches for Binutils landed, which they have now in binutils-2.44 [0], which made bfd's handling of mixed objects much more robust. [0] https://inbox.sourceware.org/binutils/20250112220244.597636-1-hjl.tools@gmail.com/ Bug: https://bugs.gentoo.org/926120 Thanks-to: Arsen Arsenović <arsen@gentoo.org> Co-authored-by: Eli Schwartz <eschwartz@gentoo.org> Signed-off-by: Sam James <sam@gentoo.org>
…
…
…
…
Description
No description provided
9.8 GiB
Languages
Shell
98%
Roff
1.4%
Emacs Lisp
0.2%
C
0.1%