Skip to content

Commit a24c46a

Browse files
authored
Fix sys-config/ltoize to install symlinks at proper location in Prefix. (#862)
dosym seems to silently adds $EPREFIX to some parts of its arguments, see https://bugs.gentoo.org/615594. This is a hackish way of having Prefix install the symlinks at the expected location. I updated the documentation to reflect that Prefix cannot use the make.conf.lto symlink, at it sources an absolute path that is not present in Prefix.
1 parent 9e7b681 commit a24c46a

1 file changed

Lines changed: 127 additions & 0 deletions

File tree

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
# Copyright 1999-2021 Gentoo Authors
2+
# Distributed under the terms of the GNU General Public License v2
3+
4+
EAPI=7
5+
6+
inherit toolchain-funcs
7+
8+
DESCRIPTION="A configuration for portage to make building with LTO easy"
9+
HOMEPAGE="https://github.com/InBetweenNames/gentooLTO"
10+
11+
#Note: there's nothing preventing this from working on stable, but the dependencies of ltoize aren't keyworded for
12+
#stable, so we only can do testing
13+
KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~s390 ~sparc ~x86"
14+
15+
SRC_URI=""
16+
17+
LICENSE="GPL-2+"
18+
SLOT="0"
19+
IUSE="clang keep-nocommon override-flagomatic"
20+
21+
#portage-bashrc-mv can be obtained from mv overlay
22+
DEPEND="
23+
app-portage/portage-bashrc-mv[cflags]
24+
sys-apps/portage
25+
sys-devel/gcc-config
26+
"
27+
RDEPEND="${DEPEND}"
28+
29+
#Test binutils and gcc version
30+
pkg_setup() {
31+
32+
ACTIVE_GCC=$(gcc-fullversion)
33+
34+
if ver_test "${ACTIVE_GCC}" -lt 10.2.0; then
35+
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."
36+
if [ "${I_KNOW_WHAT_I_AM_DOING}" != "y" ]; then
37+
eerror "Aborting LTOize installation due to older GCC version '$ACTIVE_GCC' -- set I_KNOW_WHAT_I_AM_DOING=y if you want to override this behaviour."
38+
die
39+
else
40+
ewarn "I_KNOW_WHAT_I_AM_DOING=y -- continuing anyway"
41+
fi
42+
fi
43+
44+
if [ -f "${PORTAGE_CONFIGROOT%/}/etc/portage/package.cflags" ]; then
45+
eerror "${PORTAGE_CONFIGROOT%/}/etc/portage/package.cflags is a file not a directory. Please convert package.cflags to a directory with the current contents of package.cflags being moved to a file inside it."
46+
die
47+
fi
48+
49+
}
50+
51+
pkg_preinst() {
52+
ACTIVE_GCC=$(gcc-fullversion)
53+
GENTOOLTO_PORTDIR=$(portageq get_repo_path ${PORTAGE_CONFIGROOT} lto-overlay)
54+
LTO_PORTAGE_DIR="${GENTOOLTO_PORTDIR}/${CATEGORY}/${PN}/files"
55+
56+
COMMON_WORKAROUNDS=(
57+
cmake-makefile.conf
58+
devirtualize-at-ltrans.conf
59+
graphite.conf
60+
ipa-pta.conf
61+
lto.conf
62+
no-common-libtool.conf
63+
no-plt.conf
64+
no-semantic-interposition.conf
65+
optimizations.conf
66+
portage-bashrc-mv.conf
67+
tls-dialect.conf
68+
use-ld.conf
69+
)
70+
71+
#Install make.conf settings
72+
elog "Installing make.conf.lto.defines definitions for optimizations used in this overlay"
73+
dosym "${LTO_PORTAGE_DIR}/make.conf.lto.defines" "${PORTAGE_CONFIGROOT#${EPREFIX}}/etc/portage/make.conf.lto.defines"
74+
75+
elog "Installing make.conf.lto default full optimization config for make.conf"
76+
dosym "${LTO_PORTAGE_DIR}/make.conf.lto" "${PORTAGE_CONFIGROOT#${EPREFIX}}/etc/portage/make.conf.lto"
77+
78+
#Install main workarounds files
79+
for i in "${COMMON_WORKAROUNDS[@]}"; do
80+
elog "Installing package.cflags ${i} override"
81+
dosym "${LTO_PORTAGE_DIR}/package.cflags/${i}" "${PORTAGE_CONFIGROOT#${EPREFIX}}/etc/portage/package.cflags/${i}"
82+
done
83+
84+
#Install -fno-common workarounds file
85+
use keep-nocommon && dosym "${LTO_PORTAGE_DIR}/package.cflags/no-common.conf" \
86+
"${PORTAGE_CONFIGROOT#${EPREFIX}%/}/etc/portage/package.cflags/no-common.conf"
87+
88+
# Install Clang LTO workarounds
89+
use clang && dosym "${LTO_PORTAGE_DIR}/package.cflags/clang.conf" \
90+
"${PORTAGE_CONFIGROOT#${EPREFIX}%/}/etc/portage/package.cflags/clang.conf"
91+
92+
#Install patch framework
93+
elog "Installing bashrc.d hook symlink to apply LTO patches directly from lto-overlay"
94+
dosym "${LTO_PORTAGE_DIR}/bashrc.d/41-lto-patch.sh" "${PORTAGE_CONFIGROOT#${EPREFIX}}/etc/portage/bashrc.d/41-lto-patch.sh"
95+
96+
#Optional: install flag-o-matic overrides
97+
if use override-flagomatic; then
98+
ewarn "Installing bashrc.d hook to override strip-flags and replace-flags functions in flag-o-matic. This is an experimental feature!"
99+
dosym "${LTO_PORTAGE_DIR}/bashrc.d/42-lto-flag-o-matic.sh" "${PORTAGE_CONFIGROOT#${EPREFIX}}/etc/portage/bashrc.d/42-lto-flag-o-matic.sh"
100+
dosym "${LTO_PORTAGE_DIR}/package.cflags/flag-o-matic.conf" "${PORTAGE_CONFIGROOT#${EPREFIX}}/etc/portage/package.cflags/flag-o-matic.conf"
101+
fi
102+
103+
elog "Installing bashrc.d hook symlink to override package libtool lt_cv_sys_global_symbol_pipe and lt_cv_sys_global_symbol_to_cdecl"
104+
dosym "${LTO_PORTAGE_DIR}/bashrc.d/43-lto-no-common.sh" "${PORTAGE_CONFIGROOT#${EPREFIX}}/etc/portage/bashrc.d/43-lto-no-common.sh"
105+
}
106+
107+
pkg_postinst()
108+
{
109+
elog "If you have not done so, you will need to modify your make.conf settings to enable LTO building on your system."
110+
elog "A symlink has been placed in ${PORTAGE_CONFIGROOT%/}/etc/portage/make.conf.lto that can be used as a basis for these modifications."
111+
elog "See README.md for more details."
112+
elog "lto-overlay and ltoize are part of a project to help find undefined behaviour in C and C++ programs through the use of aggressive compiler optimizations."
113+
elog "One of the aims of this project is also to improve the performance of linux distributions through these mechanisms as well."
114+
elog "Occasionally, you will experience breakage due to LTO problems. These are documented in the README.md of this repository."
115+
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."
116+
ewarn "You will require a complete system rebuild in order to gain the benefits of LTO system-wide."
117+
echo
118+
elog "Please consider reading the README.md at the root of this repository before attempting to rebuild your system to familiarize yourself with the goals of this project and potential pitfalls you could run into."
119+
echo
120+
ewarn "This is an experimental project and should not be used on a stable system in its current state."
121+
122+
BINUTILS_VER=$(binutils-config ${CHOST} -c | sed -e "s/.*-//")
123+
124+
if ver_test "${BINUTILS_VER}" -lt 2.34; then
125+
ewarn "Warning: active binutils version < 2.34, it is recommended that you use the newest binutils for LTO."
126+
fi
127+
}

0 commit comments

Comments
 (0)