Skip to content

Commit

Permalink
sys-config/ltoize: Add overrides for flag-o-matic
Browse files Browse the repository at this point in the history
Add an experimental USE flag to override strip-flags and replace-flags
in flag-o-matic.

Address #57

Signed-off-by: Shane Peelar <[email protected]>
  • Loading branch information
InBetweenNames committed Oct 27, 2018
1 parent 368af73 commit 7e8739f
Show file tree
Hide file tree
Showing 6 changed files with 128 additions and 2 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ The actual `/etc/portage` modifications are in `sys-config/ltoize/files`. This
Not all packages build cleanly. Environment overrides are used to allow packages to build that have trouble with O3, Graphite, and LTO. These can be found in `package.cflags/ltoworkarounds.conf`. I have tried to categorize the overrides based on the kind of failure were being exhibited, but in some cases this was difficult.
Graphite and -O3 overrides are included in that file as well, but they won't affect you if you are not using those compiler flags.

### Flag-O-Matic flag manipulation

In addition to the above, a number of packages call `strip-flags`, `replace-flags`, and `filter-flags` to manipulate the `*FLAGS` variables.
LTOize has an experimental `USE` flag `override-flagomatic` to override `strip-flags` and `replace-flags` globally to turn these functions into no-ops.
`filter-flags` is left alone as in the cases I've looked at, the uses of it are legitimate. `override-flagomatic` is disabled by default. Users who use this
functionality should report breakages as issues, so they can be manually resolved in a configuration file (probably in `package.cflags` to start).

The relevant issue for this work is [#57](https://github.com/InBetweenNames/gentooLTO/issues/57). Any ideas/suggestions, please post!

### LTO patches

This overlay also contains patches to help certain packages build under LTO that have not been accepted upstream yet. A script, `41-lto-patch.sh`, is symlinked to your portage `bashrc.d` directory
Expand Down
5 changes: 4 additions & 1 deletion metadata/pkg_desc_index
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
sys-config/ltoize 0.2: A configuration for portage to make building with LTO easy.
dev-lang/python 2.7.15-r1 3.4.8-r2 3.5.5-r2 3.6.6-r1 3.7.0-r1: An interpreted, interactive, object-oriented programming language
media-libs/x264 0.0.20170701-r1: A free library for encoding X264/AVC streams
media-video/x264-encoder 0.0.20170701-r1: A free commandline encoder for X264/AVC streams
sys-config/ltoize 0.8.1 0.8.2 0.9.0: A configuration for portage to make building with LTO easy.
2 changes: 1 addition & 1 deletion sys-config/ltoize/files/bashrc.d/41-lto-patch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ LTOPatch() {

${prev_shopt}

[[ -n ${applied} ]] && ewarn "LTO patches applied."
[[ -n ${applied} ]] && ewarn "lto-overlay: LTO patches applied."

}

Expand Down
16 changes: 16 additions & 0 deletions sys-config/ltoize/files/bashrc.d/42-lto-flag-o-matic.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
LTOOverrideFlagOMatic()
{
strip-flags()
{
ewarn "lto-overlay: strip-flags OVERRIDDEN"
}

replace-flags()
{
ewarn "lto-overlay: replace-flags OVERRIDDEN"
}
}

BashrcdPhase prepare LTOOverrideFlagOMatic
BashrcdPhase configure LTOOverrideFlagOMatic
BashrcdPhase compile LTOOverrideFlagOMatic
97 changes: 97 additions & 0 deletions sys-config/ltoize/ltoize-0.9.0.ebuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Copyright 1999-2018 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2

EAPI=7

inherit toolchain-funcs

DESCRIPTION="A configuration for portage to make building with LTO easy."
HOMEPAGE="https://github.com/InBetweenNames/gentooLTO"
KEYWORDS="~amd64 ~x86"

SRC_URI=""

LICENSE="GPL-2+"
SLOT="0"
IUSE="override-flagomatic"

#portage-bashrc-mv can be obtained from mv overlay
DEPEND=">=sys-devel/gcc-4.9.4:* >=sys-devel/binutils-2.28.1:* app-portage/portage-bashrc-mv[cflags] >=sys-devel/gcc-config-1.9.1"
#DEPEND="graphite ? ( gcc[graphite] )"

RDEPEND="${DEPEND}"

#Test binutils and gcc version

pkg_setup() {

ACTIVE_GCC=$(gcc-fullversion)

if ver_test "${ACTIVE_GCC}" -lt 8.2.0; then
ewarn "Warning: Active GCC version < 7.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 LTOize installation due to older 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.cflags" ]; then
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."
die
fi

}

pkg_preinst() {

GENTOOLTO_PORTDIR=$(portageq get_repo_path ${PORTAGE_CONFIGROOT} lto-overlay)
LTO_PORTAGE_DIR="${GENTOOLTO_PORTDIR}/${CATEGORY}/${PN}/files"

ACTIVE_GCC=$(gcc-fullversion)

#Insert make.conf sample...

elog "Installing make.conf.lto sample for make.conf modifications"
dosym "${LTO_PORTAGE_DIR}/make.conf.lto" "${PORTAGE_CONFIGROOT%/}/etc/portage/make.conf.lto"

elog "Installing ltoworkarounds.conf package.cflags overrides"
dosym "${LTO_PORTAGE_DIR}/package.cflags/ltoworkarounds.conf" "${PORTAGE_CONFIGROOT%/}/etc/portage/package.cflags/ltoworkarounds.conf"

#elog "Installing patches to help certain software build with this configuration (installed as symlinks)"
#for i in $(ls ${LTO_PORTAGE_DIR}/patches); do
# dosym "${LTO_PORTAGE_DIR}/patches/$i" "${PORTAGE_CONFIGROOT%/}/etc/portage/patches/$i"
#done

elog "Installing bashrc.d hook symlink to apply LTO patches directly from lto-overlay"
dosym "${LTO_PORTAGE_DIR}/bashrc.d/41-lto-patch.sh" "${PORTAGE_CONFIGROOT%/}/etc/portage/bashrc.d/41-lto-patch.sh"

if use override-flagomatic; then
ewarn "Installing bashrc.d hook to override strip-flags and replace-flags functions in flag-o-matic. This is an experimental feature!"
dosym "${LTO_PORTAGE_DIR}/bashrc.d/42-lto-flag-o-matic.sh" "${PORTAGE_CONFIGROOT%/}/etc/portage/bashrc.d/42-lto-flag-o-matic.sh"
fi

}

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 "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."
elog "One of the aims of this project is also to improve the performance of linux distributions through these mechanisms as well."
elog "Occasionally, you will experience breakage due to LTO problems. These are documented in the README.md of this repository."
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
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."
echo
ewarn "This is an experimental project and should not be used on a stable system in its current state."

BINUTILS_VER=$(binutils-config ${CHOST} -c | sed -e "s/.*-//")

if ver_test "${BINUTILS_VER}" -lt 2.31.1; then
ewarn "Warning: active binutils version < 2.31.1, it is recommended that you use the newest binutils for LTO."
fi

}
1 change: 1 addition & 0 deletions sys-config/ltoize/metadata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@
<longdescription lang="en">
LTOize is a set of configuration files and overrides to make building your system Link Time Optimization easy. This is part of a bigger initiative to find errors in C and C++ programs that are caused by undefined behaviour. Users are strongly encouraged to contribute their configuration changes upstream. For more information, see the gentooLTO project on GitHub.
</longdescription>
<use><flag name="override-flagomatic">Override strip-flags and replace-flags in flag-o-matic.eclass (EXPERIMENTAL)</flag></use>
</pkgmetadata>

0 comments on commit 7e8739f

Please sign in to comment.