From d92d7de7c78a786d88e6b8692320f912aae631fb Mon Sep 17 00:00:00 2001 From: Stephen L Arnold Date: Sun, 29 Oct 2023 19:20:34 -0700 Subject: [PATCH] sys-config/ltobase: add simple lto cfg based on ltoize remnants Signed-off-by: Stephen L Arnold --- sys-config/ltobase/files/env/nolto.conf | 5 ++ sys-config/ltobase/files/env/plus-dl.conf | 3 + sys-config/ltobase/files/env/plus-m.conf | 3 + sys-config/ltobase/files/make.conf.lto | 8 ++ sys-config/ltobase/files/package.env/link-dl | 2 + sys-config/ltobase/files/package.env/link-m | 1 + .../ltobase/files/package.env/noltobuild | 59 +++++++++++++ .../patches/dev-libs/gmp/arm64-lto.patch | 45 ++++++++++ sys-config/ltobase/ltobase-0.1.0.ebuild | 88 +++++++++++++++++++ 9 files changed, 214 insertions(+) create mode 100644 sys-config/ltobase/files/env/nolto.conf create mode 100644 sys-config/ltobase/files/env/plus-dl.conf create mode 100644 sys-config/ltobase/files/env/plus-m.conf create mode 100644 sys-config/ltobase/files/make.conf.lto create mode 100644 sys-config/ltobase/files/package.env/link-dl create mode 100644 sys-config/ltobase/files/package.env/link-m create mode 100644 sys-config/ltobase/files/package.env/noltobuild create mode 100644 sys-config/ltobase/files/patches/dev-libs/gmp/arm64-lto.patch create mode 100644 sys-config/ltobase/ltobase-0.1.0.ebuild diff --git a/sys-config/ltobase/files/env/nolto.conf b/sys-config/ltobase/files/env/nolto.conf new file mode 100644 index 0000000..2e12fae --- /dev/null +++ b/sys-config/ltobase/files/env/nolto.conf @@ -0,0 +1,5 @@ +# Env setup to disable LTO for problem builds +CFLAGS="${CFLAGS} -fno-lto" +CXXFLAGS="${CXXFLAGS} -fno-lto" +FCFLAGS="${FCFLAGS} -fno-lto" +FFLAGS="${FFLAGS} -fno-lto" diff --git a/sys-config/ltobase/files/env/plus-dl.conf b/sys-config/ltobase/files/env/plus-dl.conf new file mode 100644 index 0000000..0946ba7 --- /dev/null +++ b/sys-config/ltobase/files/env/plus-dl.conf @@ -0,0 +1,3 @@ +LIBS="${LIBS} -ldl" +LDADD="${LDADD} -ldl" +#LDFLAGS="${LDFLAGS} -ldl" diff --git a/sys-config/ltobase/files/env/plus-m.conf b/sys-config/ltobase/files/env/plus-m.conf new file mode 100644 index 0000000..600b8f4 --- /dev/null +++ b/sys-config/ltobase/files/env/plus-m.conf @@ -0,0 +1,3 @@ +LIBS="${LIBS} -lm" +LDADD="${LDADD} -lm" +#LDFLAGS="${LDFLAGS} -lm" diff --git a/sys-config/ltobase/files/make.conf.lto b/sys-config/ltobase/files/make.conf.lto new file mode 100644 index 0000000..658e743 --- /dev/null +++ b/sys-config/ltobase/files/make.conf.lto @@ -0,0 +1,8 @@ +NPROC=$(nproc) +NUMCPUS=${NTHREADS:-$NPROC} + +LTO_FLAGS="-flto=${NUMCPUS} -fuse-linker-plugin" +VEC_FLAGS="-ftree-vectorize -fvect-cost-model=cheap" +GRAPHITE="-fgraphite-identity -floop-nest-optimize" +TUNE_FLAGS="-fdevirtualize-at-ltrans" +COMMON_FLAGS="${OPT_FLAGS} ${LTO_FLAGS} ${VEC_FLAGS} ${GRAPHITE} ${TUNE_FLAGS}" diff --git a/sys-config/ltobase/files/package.env/link-dl b/sys-config/ltobase/files/package.env/link-dl new file mode 100644 index 0000000..2991c14 --- /dev/null +++ b/sys-config/ltobase/files/package.env/link-dl @@ -0,0 +1,2 @@ +sys-libs/ncurses-compat plus-dl.conf +sys-libs/ncurses plus-dl.conf diff --git a/sys-config/ltobase/files/package.env/link-m b/sys-config/ltobase/files/package.env/link-m new file mode 100644 index 0000000..55383f1 --- /dev/null +++ b/sys-config/ltobase/files/package.env/link-m @@ -0,0 +1 @@ +sys-devel/gettext plus-m.conf diff --git a/sys-config/ltobase/files/package.env/noltobuild b/sys-config/ltobase/files/package.env/noltobuild new file mode 100644 index 0000000..f4804d4 --- /dev/null +++ b/sys-config/ltobase/files/package.env/noltobuild @@ -0,0 +1,59 @@ +sys-libs/libomp nolto.conf +sys-apps/sandbox nolto.conf +dev-libs/gmp nolto.conf +dev-libs/elfutils nolto.conf +media-libs/alsa-lib nolto.conf +media-sound/pulseaudio nolto.conf + +app-admin/keepassxc nolto.conf +app-emulation/dosemu nolto.conf +app-emulation/libguestfs nolto.conf +app-emulation/libpod nolto.conf +app-emulation/qemu nolto.conf +app-emulation/virtualbox-extpack-oracle nolto.conf +app-emulation/virtualbox nolto.conf +app-text/texlive-core nolto.conf +cross-arm-none-eabi/newlib nolto.conf + +dev-java/icedtea nolto.conf +dev-lang/erlang nolto.conf +dev-lang/lua nolto.conf +dev-lang/perl nolto.conf +dev-lang/rust nolto.conf +dev-lang/spidermonkey nolto.conf +dev-python/libvirt-python nolto.conf +dev-scheme/guile nolto.conf +dev-scheme/racket nolto.conf +dev-util/valgrind nolto.conf + +net-analyzer/wireshark nolto.conf +net-libs/nodejs nolto.conf +net-libs/webkit-gtk:3 nolto.conf +net-libs/webkit-gtk:4 nolto.conf + +sys-apps/acl nolto.conf +sys-devel/clang nolto.conf +sys-devel/gcc nolto.conf +sys-devel/gdb nolto.conf +sys-devel/llvm nolto.conf +sys-libs/glibc nolto.conf +sys-fs/fuse-common nolto.conf +sys-fs/fuse nolto.conf +sys-libs/libcxxabi nolto.conf + +app-crypt/gcr nolto.conf +dev-lang/ruby nolto.conf +dev-libs/folks nolto.conf +dev-libs/libaio nolto.conf +dev-libs/libbsd nolto.conf +dev-libs/libpcre nolto.conf +dev-libs/protobuf nolto.conf + +media-libs/mesa nolto.conf +net-misc/networkmanager nolto.conf +net-misc/openssh nolto.conf +net-proxy/privoxy nolto.conf +>=sys-apps/attr-2.4.48 nolto.conf +sys-libs/libxcrypt nolto.conf +app-misc/openrgb nolto.conf +net-mail/mailutils nolto.conf diff --git a/sys-config/ltobase/files/patches/dev-libs/gmp/arm64-lto.patch b/sys-config/ltobase/files/patches/dev-libs/gmp/arm64-lto.patch new file mode 100644 index 0000000..d1eebc1 --- /dev/null +++ b/sys-config/ltobase/files/patches/dev-libs/gmp/arm64-lto.patch @@ -0,0 +1,45 @@ +diff -r 575ff753614f mpn/arm64/bdiv_q_1.asm +--- a/mpn/arm64/bdiv_q_1.asm Fri Jan 01 14:46:22 2021 +0100 ++++ b/mpn/arm64/bdiv_q_1.asm Fri Jan 01 17:13:01 2021 +0100 +@@ -61,9 +61,15 @@ + clz cnt, x6 + lsr d, d, cnt + +- LEA_HI( x7, binvert_limb_table) ++ifdef(`PIC',` ++ adrp x7, :got:__gmp_binvert_limb_table + ubfx x6, d, 1, 7 +- LEA_LO( x7, binvert_limb_table) ++ ldr x7, [x7, #:got_lo12:__gmp_binvert_limb_table] ++',` ++ adrp x7, __gmp_binvert_limb_table ++ ubfx x6, d, 1, 7 ++ add x7, x7, :lo12:__gmp_binvert_limb_table ++') + ldrb w6, [x7, x6] + ubfiz x7, x6, 1, 8 + umull x6, w6, w6 +@@ -75,7 +81,7 @@ + mul x6, x6, x6 + msub di, x6, d, x7 + +- b GSYM_PREFIX`'mpn_pi1_bdiv_q_1 ++ b mpn_pi1_bdiv_q_1 + EPILOGUE() + + PROLOGUE(mpn_pi1_bdiv_q_1) +diff -r 575ff753614f mpn/arm64/invert_limb.asm +--- a/mpn/arm64/invert_limb.asm Fri Jan 01 14:46:22 2021 +0100 ++++ b/mpn/arm64/invert_limb.asm Fri Jan 01 17:13:01 2021 +0100 +@@ -41,9 +41,9 @@ + ASM_START() + PROLOGUE(mpn_invert_limb) + lsr x2, x0, #54 +- LEA_HI( x1, approx_tab) ++ adrp x1, approx_tab + and x2, x2, #0x1fe +- LEA_LO( x1, approx_tab) ++ add x1, x1, :lo12:approx_tab + ldrh w3, [x1,x2] + lsr x4, x0, #24 + add x4, x4, #1 diff --git a/sys-config/ltobase/ltobase-0.1.0.ebuild b/sys-config/ltobase/ltobase-0.1.0.ebuild new file mode 100644 index 0000000..bbfda6f --- /dev/null +++ b/sys-config/ltobase/ltobase-0.1.0.ebuild @@ -0,0 +1,88 @@ +# Copyright 1999-2023 Gentoo Authors +# Distributed under the terms of the GNU General Public License v2 + +EAPI=8 + +inherit toolchain-funcs + +DESCRIPTION="A base LTO override configuration for portage" +HOMEPAGE="https://github.com/VCTLabs/embedded-overlay" + +# Note: there's nothing preventing this from working on stable +KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sparc ~x86" + +SRC_URI="" + +LICENSE="GPL-2+" +SLOT="0" +IUSE="clang" + +# portage-bashrc-mv or runtitle can be installed from mv overlay +DEPEND=" + sys-apps/portage + sys-devel/binutils-config + sys-devel/gcc-config +" +RDEPEND="${DEPEND}" + +S="${WORKDIR}" +DOCS="" + +# Test binutils and gcc version +pkg_setup() { + + ACTIVE_GCC=$(gcc-fullversion) + + if ver_test "${ACTIVE_GCC}" -lt 10.2.0; then + ewarn "Warning: Active GCC version '$ACTIVE_GCC' is lower then the expected version '10.2.0', it is recommended that you use the newest GCC if you want LTO." + if [ "${I_KNOW_WHAT_I_AM_DOING}" != "y" ]; then + eerror "Aborting LTObase installation due to older GCC version '$ACTIVE_GCC' -- set I_KNOW_WHAT_I_AM_DOING=y if you want to override this behaviour." + die + else + ewarn "I_KNOW_WHAT_I_AM_DOING=y -- continuing anyway" + fi + fi + + if [ -f "${PORTAGE_CONFIGROOT%/}/etc/portage/package.env" ]; then + eerror "${PORTAGE_CONFIGROOT%/}/etc/portage/package.env is a file not a directory. Please convert package.env to a directory with the current contents of package.env being moved to a file inside it." + die + fi +} + +src_install() { + local BASE_CONFIG="env package.env patches" + local PKG_ENV="link-dl link-m noltobuild" + local ENV_CONF="nolto.conf plus-dl.conf plus-m.conf" + dodir /etc/ltobase + insinto /etc/ltobase + doins "${FILESDIR}/make.conf.lto" + for dir in $BASE_CONFIG ; do + doins -r "${FILESDIR}/$dir" + done + + dodir /etc/portage/env /etc/portage/package.env + dosym -r /etc/ltobase/make.conf.lto /etc/portage/make.conf.lto + for file in $PKG_ENV ; do + dosym -r /etc/ltobase/package.env/$file /etc/portage/package.env/$file + done + for file in $ENV_CONF ; do + dosym -r /etc/ltobase/env/$file /etc/portage/env/$file + done +} + +pkg_postinst() { + + elog "If you have not done so, you will need to modify your make.conf settings to enable LTO building on your system." + elog "A symlink has been placed in ${PORTAGE_CONFIGROOT%/}/etc/portage/make.conf.lto that can be used as a basis for these modifications." + elog "See README.rst for more details." + + elog "If you add an override for a particular package, please consider sending a pull request upstream so that other users of this repository can benefit." + ewarn "You will require a complete system rebuild in order to gain the benefits of LTO system-wide." + echo + + BINUTILS_VER=$(binutils-config ${CHOST} -c | sed -e "s/.*-//") + + if ver_test "${BINUTILS_VER}" -lt 2.34; then + ewarn "Warning: active binutils version < 2.34, it is recommended that you use the newest binutils for LTO." + fi +}