Sam JamesandEli Schwartz f4e964aa20 dot-a.eclass: new eclass for handling LTO in static archives
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 in
  2aea6c3ff2), 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 in fad8ff8a45
for 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>
2025-05-06 09:45:06 +01:00
2025-05-06 10:48:45 +03:00
2025-05-03 01:20:27 +01:00
2025-05-05 14:27:39 -04:00
2025-05-01 13:35:56 +02:00
2025-05-05 10:58:33 +02:00
2025-04-27 06:49:31 -04:00
2025-05-06 07:30:50 +02:00
2025-04-25 00:33:11 +03:00
2025-05-02 06:45:09 +01:00
2025-05-04 18:37:41 +08:00
2025-05-01 18:56:27 +02:00
2025-04-29 22:41:44 +01:00
2025-05-06 10:48:45 +03:00
2025-05-04 13:35:25 -04:00
2025-05-05 21:38:06 +02:00
2025-05-06 08:50:56 +02:00
2025-05-04 20:47:16 +02:00
2025-05-04 21:01:57 -04:00
…
S
Description
No description provided
9.8 GiB
Languages
Shell 98%
Roff 1.4%
Emacs Lisp 0.2%
C 0.1%