Skip to content

Commit

Permalink
sys-config/ltobase: add simple lto cfg based on ltoize remnants
Browse files Browse the repository at this point in the history
Signed-off-by: Stephen L Arnold <[email protected]>
  • Loading branch information
sarnold committed Oct 30, 2023
1 parent 39bcf1b commit d92d7de
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 0 deletions.
5 changes: 5 additions & 0 deletions sys-config/ltobase/files/env/nolto.conf
Original file line number Diff line number Diff line change
@@ -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"
3 changes: 3 additions & 0 deletions sys-config/ltobase/files/env/plus-dl.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LIBS="${LIBS} -ldl"
LDADD="${LDADD} -ldl"
#LDFLAGS="${LDFLAGS} -ldl"
3 changes: 3 additions & 0 deletions sys-config/ltobase/files/env/plus-m.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
LIBS="${LIBS} -lm"
LDADD="${LDADD} -lm"
#LDFLAGS="${LDFLAGS} -lm"
8 changes: 8 additions & 0 deletions sys-config/ltobase/files/make.conf.lto
Original file line number Diff line number Diff line change
@@ -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}"
2 changes: 2 additions & 0 deletions sys-config/ltobase/files/package.env/link-dl
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
sys-libs/ncurses-compat plus-dl.conf
sys-libs/ncurses plus-dl.conf
1 change: 1 addition & 0 deletions sys-config/ltobase/files/package.env/link-m
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sys-devel/gettext plus-m.conf
59 changes: 59 additions & 0 deletions sys-config/ltobase/files/package.env/noltobuild
Original file line number Diff line number Diff line change
@@ -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
45 changes: 45 additions & 0 deletions sys-config/ltobase/files/patches/dev-libs/gmp/arm64-lto.patch
Original file line number Diff line number Diff line change
@@ -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
88 changes: 88 additions & 0 deletions sys-config/ltobase/ltobase-0.1.0.ebuild
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit d92d7de

Please sign in to comment.