From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 378641584AD for ; Sat, 03 May 2025 04:28:46 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 213173432E9 for ; Sat, 03 May 2025 04:28:46 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 3F4E51103DE; Sat, 03 May 2025 04:28:02 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 767AB110287 for ; Sat, 03 May 2025 04:28:01 +0000 (UTC) Received: from [192.168.0.1] (c144-156.icpnet.pl [85.221.144.156]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (prime256v1) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: mgorny) by smtp.gentoo.org (Postfix) with ESMTPSA id 311B2343272; Sat, 03 May 2025 04:28:00 +0000 (UTC) Message-ID: <38c45beb8d7b4efc559323bbd30b519119a15297.camel@gentoo.org> Subject: Re: [gentoo-dev] [PATCH 1/5] dot-a.eclass: new eclass for handling LTO in static archives From: =?UTF-8?Q?Micha=C5=82_G=C3=B3rny?= To: gentoo-dev@lists.gentoo.org Cc: Sam James , Eli Schwartz Date: Sat, 03 May 2025 06:27:55 +0200 In-Reply-To: <810439f1ff34594dcc88c05c08a24d3d0450de22.1746216822.git.sam@gentoo.org> References: <810439f1ff34594dcc88c05c08a24d3d0450de22.1746216822.git.sam@gentoo.org> Organization: Gentoo Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-L273UIsX9orH8OCAYDvU" User-Agent: Evolution 3.54.3 Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 X-Archives-Salt: 26f4cbb8-8c1d-4a69-83b7-c0f0d32899f7 X-Archives-Hash: a3b10136803608df47510783cac18046 --=-L273UIsX9orH8OCAYDvU Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hi, Sorry for not looking earlier. On Fri, 2025-05-02 at 21:13 +0100, Sam James wrote: > diff --git a/eclass/dot-a.eclass b/eclass/dot-a.eclass > new file mode 100644 > index 0000000000000..20a0fa1dfc206 > --- /dev/null > +++ b/eclass/dot-a.eclass > @@ -0,0 +1,124 @@ > +# Copyright 2025 Gentoo Authors > +# Distributed under the terms of the GNU General Public License v2 > + > +# @ECLASS: dot-a.eclass > +# @MAINTAINER: > +# Toolchain > +# Toolchain Ninjas You've got "toolchain" twice. > +# @AUTHOR: > +# Sam James > +# Eli Schwartz > +# @SUPPORTED_EAPIS: 8 > +# @BLURB: Functions to handle stripping LTO bytecode out of static archi= ves. > +# @DESCRIPTION: > +# This eclass provides functions to strip LTO bytecode out of static arc= hives > +# (.a files). > +# > +# Static libraries when built with LTO will contain LTO bytecode which i= s > +# not portable across compiler versions or compiler vendors. To avoid pe= ssimising > +# the library and always filtering LTO, we can build it with -ffat-lto-o= bjects > +# instead, which builds some components twice. The installed part will t= hen > +# have the LTO contents stripped out, leaving the regular objects in the > +# static archive. > +# > +# Use should be passing calling lto-guarantee-fat before configure-time > +# and calling strip-lto-bytecode after installation. Do I understand correctly that this is to be always used when you're installing static libraries? Or are there more specific criteria?=20 Perhaps that'd be worth including in the doc. > +# > +# @EXAMPLE: > +# @CODE > +# > +# inherit dot-a > +# > +# src_configure() { > +# lto-guarantee-fat > +# econf > +# } > +# > +# src_install() { > +# default > +# strip-lto-bytecode > +# } > +case ${EAPI} in > + 8) ;; > + *) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;; > +esac > + > +if [[ -z ${_DOT_A_ECLASS} ]] ; then > +_DOT_A_ECLASS=3D1 > + > +inherit flag-o-matic toolchain-funcs > + > +# TODO: QA check > + > +# @FUNCTION: lto-guarantee-fat > +# @DESCRIPTION: > +# If LTO is enabled, appends -ffat-lto-objects or any other flags needed > +# to provide fat LTO objects. > +lto-guarantee-fat() { > + tc-is-lto || return > + > + # We add this for all languages as LTO obviously can't be done > + # if different compilers are used for e.g. C vs C++ anyway. > + append-flags $(test-flags-CC -ffat-lto-objects) > +} > + > +# @FUNCTION: strip-lto-bytecode > +# @USAGE: [library|directory] [...] > +# @DESCRIPTION: > +# Strips LTO bytecode from libraries (static archives) passed as argumen= ts. > +# Defaults to operating on ${ED} as a whole if no arguments are passed. > +# > +# As an optimisation, if USE=3Dstatic-libs exists for a package and is d= isabled, > +# the default-searching behaviour with no arguments is suppressed. > +strip-lto-bytecode() { > + tc-is-lto || return > + > + local files=3D() > + > + if [[ ${#} -eq 0 ]]; then > + if ! in_iuse static-libs || use static-libs ; then > + # maybe we are USE=3Dstatic-libs. Alternatively, maybe the ebuild doe= sn't > + # offer such a choice. In both cases, the user specified the function= , > + # so we expect to be called on *something*, but nothing was explicitl= y > + # passed. Try scanning ${ED} automatically. > + set -- "${ED}" > + fi > + fi > + > + # Check if any of our arguments are directories to be recursed > + # into. > + local arg > + for arg in "$@" ; do > + if [[ -d ${arg} ]] ; then > + mapfile -t -d '' -O "${#files[@]}" files < <(find "${arg}" -type f -i= name '*.a' -print0) > + else > + files+=3D( "${arg}" ) > + fi > + done Why not just pass all arguments to find(1)? If you pass a file path to it, it will just return that file, i.e.: mapfile -t -d '' files < <(find -H "${@}" -type f -iname '*.a' -print0) ('-H' to follow symbolic links if passed directly in "$@") > + > + toolchain_type=3D > + tc-is-gcc && toolchain_type=3Dgnu > + tc-is-clang && toolchain_type=3Dllvm > + > + local file > + for file in "${files[@]}" ; do > + case ${toolchain_type} in > + gnu) > + $(tc-getSTRIP) \ > + -R .gnu.lto_* \ > + -R .gnu.debuglto_* \ > + -N __gnu_lto_v1 \ > + "${file}" || die "Stripping bytecode in ${file} failed" > + ;; Technically, strip accepts multiple files, but I can guess there's no point in optimizing the GNU branch here. > + llvm) > + llvm-bitcode-strip \ > + -r "${file}" \ > + -o "${file}" || die "Stripping bytecode in ${file} failed" > + ;; > + *) > + ;; > + esac > + done > +} > + > +fi --=20 Best regards, Micha=C5=82 G=C3=B3rny --=-L273UIsX9orH8OCAYDvU Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part -----BEGIN PGP SIGNATURE----- iQFGBAABCgAwFiEEx2qEUJQJjSjMiybFY5ra4jKeJA4FAmgVm0sSHG1nb3JueUBn ZW50b28ub3JnAAoJEGOa2uIyniQO+k4IAIeeUpQOReUIFYrjP5t2u8hdDAZ8NTU1 yx5iOH/Tu+D6rpoUCbUqQkNk7rY03RGM1v9tbbApkYJ1r4lUCr+ZMIwmr3NAVMeK ipjqhr7z3SL+2eatr/dVuJ00QJ0jBjpJV2F92UuBrN/6asc+4BTBZj2ivA02eMTH bdzRAdQu3kC1isz3tR/Lz2nQitVS5786Tn8VDM5VB1JYA9LGD0+eF1kl/TuGpXBv +M6IQDA2ThmJX3dCOPU5hpuJoP9Cvq6KlEyjloMuFnvpOHKdyrcB1HTLEy77tI1r mGzoTeJ/WLpEWkpIcAvv0mvGghAnQhWC71GzvJLmqfnGvh1zf2cID9s= =80bZ -----END PGP SIGNATURE----- --=-L273UIsX9orH8OCAYDvU--