toolchain.eclass: drop I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS guard
[gentoo.git] / eclass / toolchain.eclass
index 7e88900737ac84176cd875befe9ac9114c0af348..46482ad9d7535dc07782ef74a7b9a6a33e5a0dab 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2019 Gentoo Authors
+# Copyright 1999-2020 Gentoo Authors
 # Distributed under the terms of the GNU General Public License v2
 
 # Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
@@ -9,14 +9,18 @@ HOMEPAGE="https://gcc.gnu.org/"
 
 inherit eutils fixheadtails flag-o-matic gnuconfig libtool multilib pax-utils toolchain-funcs prefix
 
-if [[ ${PV} == *9999* ]] ; then
+tc_is_live() {
+       [[ ${PV} == *9999* ]]
+}
+
+if tc_is_live ; then
        EGIT_REPO_URI="git://gcc.gnu.org/git/gcc.git"
        # naming style:
        # gcc-10.1.0_pre9999 -> gcc-10-branch
        #  Note that the micro version is required or lots of stuff will break.
        #  To checkout master set gcc_LIVE_BRANCH="master" in the ebuild before
        #  inheriting this eclass.
-       EGIT_BRANCH="${PN}-${PV%.?.?_pre9999}-branch"
+       EGIT_BRANCH="releases/${PN}-${PV%.?.?_pre9999}"
        EGIT_BRANCH=${EGIT_BRANCH//./_}
        inherit git-r3
 fi
@@ -30,16 +34,6 @@ case ${EAPI:-0} in
        *) die "I don't speak EAPI ${EAPI}." ;;
 esac
 
-tc_supports_dostrip() {
-       case ${EAPI:-0} in
-               5*|6) return 1 ;;
-               7) return 0 ;;
-               *) die "Update apply_patches() for ${EAPI}." ;;
-       esac
-}
-
-tc_supports_dostrip || RESTRICT="strip" # cross-compilers need controlled stripping
-
 EXPORT_FUNCTIONS pkg_pretend pkg_setup src_unpack src_prepare src_configure \
        src_compile src_test src_install pkg_postinst pkg_postrm
 
@@ -73,32 +67,36 @@ tc_version_is_between() {
 GCC_PV=${TOOLCHAIN_GCC_PV:-${PV}}
 GCC_PVR=${GCC_PV}
 [[ ${PR} != "r0" ]] && GCC_PVR=${GCC_PVR}-${PR}
+
+# GCC_RELEASE_VER must always match 'gcc/BASE-VER' value.
+# It's an internal representation of gcc version used for:
+# - versioned paths on disk
+# - 'gcc -dumpversion' output. Must always match <digit>.<digit>.<digit>.
 GCC_RELEASE_VER=$(ver_cut 1-3 ${GCC_PV})
+
 GCC_BRANCH_VER=$(ver_cut 1-2 ${GCC_PV})
 GCCMAJOR=$(ver_cut 1 ${GCC_PV})
 GCCMINOR=$(ver_cut 2 ${GCC_PV})
 GCCMICRO=$(ver_cut 3 ${GCC_PV})
 
-# According to gcc/c-cppbuiltin.c, GCC_CONFIG_VER MUST match this regex.
-# ([^0-9]*-)?[0-9]+[.][0-9]+([.][0-9]+)?([- ].*)?
-GCC_CONFIG_VER=${GCC_CONFIG_VER:-$(ver_rs 3 '-' ${GCC_PV})}
-
-# Pre-release support
-if [[ ${GCC_PV} == *_pre* ]] ; then
-       PRERELEASE=${GCC_PV/_pre/-}
-elif [[ ${GCC_PV} == *_alpha* ]] ; then
-       SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_alpha}
-elif [[ ${GCC_PV} == *_beta* ]] ; then
-       SNAPSHOT=${GCC_BRANCH_VER}-${GCC_PV##*_beta}
+# Ideally this variable should allow for custom gentoo versioning
+# of binary and gcc-config names not directly tied to upstream
+# versioning. In practive it's hard to untangle from gcc/BASE-VER
+# (GCC_RELEASE_VER) value.
+GCC_CONFIG_VER=${GCC_RELEASE_VER}
+
+# Pre-release support. Versioning schema:
+# 1.0.0_pre9999: live ebuild
+# 1.2.3_alphaYYYYMMDD: weekly snapshots
+# 1.2.3_rcYYYYMMDD: release candidates
+if [[ ${GCC_PV} == *_alpha* ]] ; then
+       # weekly snapshots
+       SNAPSHOT=${GCCMAJOR}-${GCC_PV##*_alpha}
 elif [[ ${GCC_PV} == *_rc* ]] ; then
+       # release candidates
        SNAPSHOT=${GCC_PV%_rc*}-RC-${GCC_PV##*_rc}
 fi
 
-if [[ ${SNAPSHOT} == [56789].0-* ]] ; then
-       # The gcc-5+ releases have dropped the .0 for some reason.
-       SNAPSHOT=${SNAPSHOT/.0}
-fi
-
 PREFIX=${TOOLCHAIN_PREFIX:-${EPREFIX}/usr}
 
 if tc_version_is_at_least 3.4.0 ; then
@@ -137,15 +135,18 @@ else
        LICENSE="GPL-2+ LGPL-2.1+ FDL-1.1+"
 fi
 
-if tc_version_is_at_least 8.3; then
-       GCC_EBUILD_TEST_FLAG='test'
-else
-       # Don't force USE regression-test->test change on every
-       # gcc ebuild just yet. Let's do the change when >=gcc-8.3
-       # is commonly used as a main compiler.
-       GCC_EBUILD_TEST_FLAG='regression-test'
-fi
-IUSE="${GCC_EBUILD_TEST_FLAG} vanilla +nls"
+IUSE="test vanilla +nls"
+RESTRICT="!test? ( test )"
+
+tc_supports_dostrip() {
+       case ${EAPI:-0} in
+               5*|6) return 1 ;;
+               7) return 0 ;;
+               *) die "Update apply_patches() for ${EAPI}." ;;
+       esac
+}
+
+tc_supports_dostrip || RESTRICT+=" strip" # cross-compilers need controlled stripping
 
 TC_FEATURES=()
 
@@ -154,11 +155,13 @@ tc_has_feature() {
 }
 
 if [[ ${PN} != "kgcc64" && ${PN} != gcc-* ]] ; then
-       IUSE+=" altivec debug +cxx +fortran +nptl" TC_FEATURES+=(fortran nptl)
+       IUSE+=" altivec debug +cxx +nptl" TC_FEATURES+=(nptl)
        [[ -n ${PIE_VER} ]] && IUSE+=" nopie"
        [[ -n ${HTB_VER} ]] && IUSE+=" boundschecking"
        [[ -n ${D_VER}   ]] && IUSE+=" d"
        [[ -n ${SPECS_VER} ]] && IUSE+=" nossp"
+       # fortran support appeared in 4.1, but 4.1 needs outdated mpfr
+       tc_version_is_at_least 4.2 && IUSE+=" +fortran" TC_FEATURES+=(fortran)
        tc_version_is_at_least 3 && IUSE+=" doc hardened multilib objc"
        tc_version_is_between 3 7 && IUSE+=" awt gcj" TC_FEATURES+=(gcj)
        tc_version_is_at_least 3.3 && IUSE+=" pgo"
@@ -169,11 +172,17 @@ if [[ ${PN} != "kgcc64" && ${PN} != gcc-* ]] ; then
        tc_version_is_at_least 4.2 && IUSE+=" +openmp"
        tc_version_is_at_least 4.3 && IUSE+=" fixed-point"
        tc_version_is_at_least 4.7 && IUSE+=" go"
-       # Note: while <=gcc-4.7 also supported graphite, it required forked ppl
-       # versions which we dropped.  Since graphite was also experimental in
-       # the older versions, we don't want to bother supporting it.  #448024
-       tc_version_is_at_least 4.8 &&
-               IUSE+=" graphite +sanitize" TC_FEATURES+=(graphite)
+       # sanitizer support appeared in gcc-4.8, but <gcc-5 does not
+       # support modern glibc.
+       tc_version_is_at_least 5 && IUSE+=" +sanitize"
+       # Note:
+       #   <gcc-4.8 supported graphite, it required forked ppl
+       #     versions which we dropped.  Since graphite was also experimental in
+       #     the older versions, we don't want to bother supporting it.  #448024
+       #   <gcc-5 supported graphite, it required cloog
+       #   <gcc-6.5 supported graphite, it required old incompatible isl
+       tc_version_is_at_least 6.5 &&
+               IUSE+=" graphite" TC_FEATURES+=(graphite)
        tc_version_is_between 4.9 8 && IUSE+=" cilk"
        tc_version_is_at_least 4.9 && IUSE+=" +vtv"
        tc_version_is_at_least 5.0 && IUSE+=" jit"
@@ -184,9 +193,16 @@ if [[ ${PN} != "kgcc64" && ${PN} != gcc-* ]] ; then
                IUSE+=" systemtap" TC_FEATURES+=(systemtap)
        tc_version_is_at_least 9.0 && IUSE+=" d"
        tc_version_is_at_least 9.1 && IUSE+=" lto"
+       tc_version_is_at_least 10 && IUSE+=" zstd" TC_FEATURES+=(zstd)
 fi
 
-SLOT="${GCC_CONFIG_VER}"
+if tc_version_is_at_least 10; then
+       # Note: currently we pull in releases, snapshots and
+       # git versions into the same SLOT.
+       SLOT="${GCCMAJOR}"
+else
+       SLOT="${GCC_CONFIG_VER}"
+fi
 
 #---->> DEPEND <<----
 
@@ -213,25 +229,18 @@ if tc_has_feature objc-gc ; then
 fi
 
 if tc_has_feature graphite ; then
-       if tc_version_is_at_least 5.0 ; then
-               RDEPEND+=" graphite? ( >=dev-libs/isl-0.14:0= )"
-       elif tc_version_is_at_least 4.8 ; then
-               RDEPEND+="
-                       graphite? (
-                               >=dev-libs/cloog-0.18.0:0=
-                               >=dev-libs/isl-0.11.1:0=
-                       )"
-       fi
+       RDEPEND+=" graphite? ( >=dev-libs/isl-0.14:0= )"
 fi
 
-DEPEND="${RDEPEND}
+BDEPEND="
        >=sys-devel/bison-1.875
        >=sys-devel/flex-2.5.4
        nls? ( sys-devel/gettext )
-       ${GCC_EBUILD_TEST_FLAG}? (
+       test? (
                >=dev-util/dejagnu-1.4.4
                >=sys-devel/autogen-5.5.4
        )"
+DEPEND="${RDEPEND}"
 
 if tc_has_feature gcj ; then
        GCJ_DEPS=">=media-libs/libart_lgpl-2.1"
@@ -253,17 +262,23 @@ if tc_has_feature systemtap ; then
        DEPEND+=" systemtap? ( dev-util/systemtap )"
 fi
 
+if tc_has_feature zstd ; then
+       DEPEND+=" zstd? ( app-arch/zstd )"
+fi
+
+case ${EAPI:-0} in
+       5*|6) DEPEND+=" ${BDEPEND}" ;;
+esac
+
 PDEPEND=">=sys-devel/gcc-config-1.7"
 
 #---->> S + SRC_URI essentials <<----
 
 # Set the source directory depending on whether we're using
-# a prerelease, snapshot, or release tarball.
+# a live git tree, snapshot, or release tarball.
 S=$(
-       if [[ ${PV} == *9999* ]]; then
+       if tc_is_live ; then
                echo ${EGIT_CHECKOUT_DIR}
-       elif [[ -n ${PRERELEASE} ]] ; then
-               echo ${WORKDIR}/gcc-${PRERELEASE}
        elif [[ -n ${SNAPSHOT} ]] ; then
                echo ${WORKDIR}/gcc-${SNAPSHOT}
        else
@@ -287,6 +302,10 @@ gentoo_urls() {
 # Other than the variables normally set by portage, this function's behavior
 # can be altered by setting the following:
 #
+#      GCC_TARBALL_SRC_URI
+#                      Override link to main tarball into SRC_URI. Used by dev-lang/gnat-gpl
+#                      to provide gcc tarball snapshots. Patches are usually reused as-is.
+#
 #      SNAPSHOT
 #                      If set, this variable signals that we should be using a snapshot of
 #                      gcc. It is expected to be in the format "YYYY-MM-DD". Note that if
@@ -345,18 +364,14 @@ get_gcc_src_uri() {
        export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
 
        # Set where to download gcc itself depending on whether we're using a
-       # prerelease, snapshot, or release tarball.
-       if [[ ${PV} == *9999* ]] ; then
-               # Nothing to do w/git snapshots.
-               :
-       elif [[ -n ${PRERELEASE} ]] ; then
-               GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/prerelease-${PRERELEASE}/gcc-${PRERELEASE}.tar.bz2"
+       # live git tree, snapshot, or release tarball.
+       if tc_is_live ; then
+               # Nothing to do w/git snapshots.
+       elif [[ -n ${GCC_TARBALL_SRC_URI} ]] ; then
+               # pull gcc tarball from another location. Frequently used by gnat-gpl.
+               GCC_SRC_URI="${GCC_TARBALL_SRC_URI}"
        elif [[ -n ${SNAPSHOT} ]] ; then
-               if tc_version_is_between 5.5 6 || tc_version_is_between 6.4 7 || tc_version_is_at_least 7.2 ; then
-                       GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.xz"
-               else
-                       GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.bz2"
-               fi
+               GCC_SRC_URI="ftp://gcc.gnu.org/pub/gcc/snapshots/${SNAPSHOT}/gcc-${SNAPSHOT}.tar.xz"
        else
                if tc_version_is_between 5.5 6 || tc_version_is_between 6.4 7 || tc_version_is_at_least 7.2 ; then
                        GCC_SRC_URI="mirror://gnu/gcc/gcc-${GCC_PV}/gcc-${GCC_RELEASE_VER}.tar.xz"
@@ -412,12 +427,6 @@ SRC_URI=$(get_gcc_src_uri)
 #---->> pkg_pretend <<----
 
 toolchain_pkg_pretend() {
-       if [[ -n ${PRERELEASE}${SNAPSHOT} || ${PV} == *9999* ]] &&
-          [[ -z ${I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS} ]] ; then
-               die "Please \`export I_PROMISE_TO_SUPPLY_PATCHES_WITH_BUGS=1\` or define it" \
-                       "in your make.conf if you want to use this version."
-       fi
-
        if ! use_if_iuse cxx ; then
                use_if_iuse go && ewarn 'Go requires a C++ compiler, disabled due to USE="-cxx"'
                use_if_iuse objc++ && ewarn 'Obj-C++ requires a C++ compiler, disabled due to USE="-cxx"'
@@ -438,77 +447,11 @@ toolchain_pkg_setup() {
 #---->> src_unpack <<----
 
 toolchain_src_unpack() {
-       if [[ ${PV} == *9999* ]]; then
+       if tc_is_live ; then
                git-r3_src_unpack
-       else
-               gcc_quick_unpack
-       fi
-}
-
-gcc_quick_unpack() {
-       pushd "${WORKDIR}" > /dev/null
-       export PATCH_GCC_VER=${PATCH_GCC_VER:-${GCC_RELEASE_VER}}
-       export UCLIBC_GCC_VER=${UCLIBC_GCC_VER:-${PATCH_GCC_VER}}
-       export PIE_GCC_VER=${PIE_GCC_VER:-${GCC_RELEASE_VER}}
-       export HTB_GCC_VER=${HTB_GCC_VER:-${GCC_RELEASE_VER}}
-       export SPECS_GCC_VER=${SPECS_GCC_VER:-${GCC_RELEASE_VER}}
-
-       # Injection point for more tarballs. dev-lang/gnat-gpl uses
-       # 'GCC_A_FAKEIT' to specify it's own source and binary tarballs.
-       if [[ -n ${GCC_A_FAKEIT} ]] ; then
-               unpack ${GCC_A_FAKEIT}
-       elif [[ -n ${PRERELEASE} ]] ; then
-               unpack gcc-${PRERELEASE}.tar.bz2
-       elif [[ -n ${SNAPSHOT} ]] ; then
-               if tc_version_is_between 5.5 6 || tc_version_is_between 6.4 7 || tc_version_is_at_least 7.2 ; then
-                       unpack gcc-${SNAPSHOT}.tar.xz
-               else
-                       unpack gcc-${SNAPSHOT}.tar.bz2
-               fi
-       elif [[ ${PV} != *9999* ]] ; then
-               if tc_version_is_between 5.5 6 || tc_version_is_between 6.4 7 || tc_version_is_at_least 7.2 ; then
-                       unpack gcc-${GCC_RELEASE_VER}.tar.xz
-               else
-                       unpack gcc-${GCC_RELEASE_VER}.tar.bz2
-               fi
-       fi
-
-       if [[ -n ${D_VER} ]] && use d ; then
-               pushd "${S}"/gcc > /dev/null
-               unpack gdc-${D_VER}-src.tar.bz2
-               cd ..
-               ebegin "Adding support for the D language"
-               ./gcc/d/setup-gcc.sh >& "${T}"/dgcc.log
-               if ! eend $? ; then
-                       eerror "The D GCC package failed to apply"
-                       eerror "Please include this log file when posting a bug report:"
-                       eerror "  ${T}/dgcc.log"
-                       die "failed to include the D language"
-               fi
-               popd > /dev/null
        fi
 
-       [[ -n ${PATCH_VER} ]] && \
-               unpack gcc-${PATCH_GCC_VER}-patches-${PATCH_VER}.tar.bz2
-
-       [[ -n ${UCLIBC_VER} ]] && \
-               unpack gcc-${UCLIBC_GCC_VER}-uclibc-patches-${UCLIBC_VER}.tar.bz2
-
-       if want_pie ; then
-               if [[ -n ${PIE_CORE} ]] ; then
-                       unpack ${PIE_CORE}
-               else
-                       unpack gcc-${PIE_GCC_VER}-piepatches-v${PIE_VER}.tar.bz2
-               fi
-               [[ -n ${SPECS_VER} ]] && \
-                       unpack gcc-${SPECS_GCC_VER}-specs-${SPECS_VER}.tar.bz2
-       fi
-
-       use_if_iuse boundschecking && unpack "bounds-checking-gcc-${HTB_GCC_VER}-${HTB_VER}.patch.bz2"
-
-       [[ -n ${CYGWINPORTS_GITREV} ]] && use elibc_Cygwin && unpack "gcc-cygwinports-${CYGWINPORTS_GITREV}.tar.gz"
-
-       popd > /dev/null
+       default_src_unpack
 }
 
 #---->> src_prepare <<----
@@ -533,11 +476,27 @@ toolchain_src_prepare() {
        export BRANDING_GCC_PKGVERSION="Gentoo ${GCC_PVR}"
        cd "${S}"
 
+       if [[ -n ${D_VER} ]] && use d ; then
+               mv "${WORKDIR}"/d gcc/d || die
+               ebegin "Adding support for the D language"
+               ./gcc/d/setup-gcc.sh >& "${T}"/dgcc.log
+               if ! eend $? ; then
+                       eerror "The D GCC package failed to apply"
+                       eerror "Please include this log file when posting a bug report:"
+                       eerror "  ${T}/dgcc.log"
+                       die "failed to include the D language"
+               fi
+       fi
+
        do_gcc_gentoo_patches
        do_gcc_HTB_patches
        do_gcc_PIE_patches
        do_gcc_CYGWINPORTS_patches
 
+       if tc_is_live ; then
+               BRANDING_GCC_PKGVERSION="${BRANDING_GCC_PKGVERSION}, commit ${EGIT_VERSION}"
+       fi
+
        case ${EAPI:-0} in
                5*) epatch_user;;
                6|7) eapply_user ;;
@@ -575,13 +534,10 @@ toolchain_src_prepare() {
        gcc_version_patch
 
        if tc_version_is_at_least 4.1 ; then
-               if [[ -n ${SNAPSHOT} || -n ${PRERELEASE} ]] ; then
-                       # BASE-VER must be a three-digit version number
-                       # followed by an optional -pre string
-                       #   eg. 4.5.1, 4.6.2-pre20120213, 4.7.0-pre9999
-                       # If BASE-VER differs from ${PV/_/-} then libraries get installed in
-                       # the wrong directory.
-                       echo ${PV/_/-} > "${S}"/gcc/BASE-VER
+               local actual_version=$(< "${S}"/gcc/BASE-VER)
+               if [[ "${GCC_RELEASE_VER}" != "${actual_version}" ]] ; then
+                       eerror "'${S}/gcc/BASE-VER' contains '${actual_version}', expected '${GCC_RELEASE_VER}'"
+                       die "Please set 'TOOLCHAIN_GCC_PV' to '${actual_version}'"
                fi
        fi
 
@@ -633,7 +589,7 @@ toolchain_src_prepare() {
 
        # Prevent new texinfo from breaking old versions (see #198182, #464008)
        if tc_version_is_at_least 4.1; then
-               tc_apply_patches "Remove texinfo (bug #198182, bug ##464008)" "${FILESDIR}"/gcc-configure-texinfo.patch
+               tc_apply_patches "Remove texinfo (bug #198182, bug #464008)" "${FILESDIR}"/gcc-configure-texinfo.patch
        fi
 
        # >=gcc-4
@@ -681,7 +637,13 @@ do_gcc_CYGWINPORTS_patches() {
 
        local p d="${WORKDIR}/gcc-${CYGWINPORTS_GITREV}"
        # readarray -t is available since bash-4.4 only, #690686
-       local patches=( $(sed -e '1,/PATCH_URI="/d;/"/,$d' < "${d}"/gcc.cygport) )
+       local patches=( $(
+               for p in $(
+                       sed -e '1,/PATCH_URI="/d;/"/,$d' < "${d}"/gcc.cygport
+               ); do
+                       echo "${d}/${p}"
+               done
+       ) )
        tc_apply_patches "Applying cygwin port patches ..." ${patches[*]}
 }
 
@@ -811,7 +773,7 @@ gcc_version_patch() {
        # gcc-4.3+ has configure flags (whoo!)
        tc_version_is_at_least 4.3 && return 0
 
-       local version_string=${GCC_CONFIG_VER}
+       local version_string=${GCC_RELEASE_VER}
 
        einfo "patching gcc version: ${version_string} (${BRANDING_GCC_PKGVERSION})"
 
@@ -1209,6 +1171,15 @@ toolchain_src_configure() {
                is-flagq -mfloat-gprs=double && confgcc+=( --enable-e500-double )
                [[ ${CTARGET//_/-} == *-e500v2-* ]] && confgcc+=( --enable-e500-double )
                ;;
+       ppc64)
+               # On ppc64 big endian target gcc assumes elfv1 by default,
+               # and elfv2 on little endian
+               # but musl does not support elfv1 at all on any endian ppc64
+               # see https://git.musl-libc.org/cgit/musl/tree/INSTALL
+               # https://bugs.gentoo.org/704784
+               # https://gcc.gnu.org/PR93157
+               [[ ${CTARGET} == powerpc64-*-musl ]] && confgcc+=( --with-abi=elfv2 )
+               ;;
        riscv)
                # Add --with-abi flags to set default ABI
                confgcc+=( --with-abi=$(gcc-abi-map ${TARGET_DEFAULT_ABI}) )
@@ -1309,6 +1280,10 @@ toolchain_src_configure() {
                )
        fi
 
+       if in_iuse zstd ; then
+               confgcc+=( $(use_with zstd) )
+       fi
+
        # newer gcc's come with libquadmath, but only fortran uses
        # it, so auto punt it when we don't care
        if tc_version_is_at_least 4.6 && ! is_fortran ; then
@@ -1321,21 +1296,26 @@ toolchain_src_configure() {
                confgcc+=( --disable-lto )
        fi
 
-       # graphite was added in 4.4 but we only support it in 4.8+ due to external
-       # library issues.  #448024
-       if tc_version_is_at_least 5.0 && in_iuse graphite ; then
+       # graphite was added in 4.4 but we only support it in 6.5+ due to external
+       # library issues.  #448024, #701270
+       if tc_version_is_at_least 6.5 && in_iuse graphite ; then
                confgcc+=( $(use_with graphite isl) )
                use graphite && confgcc+=( --disable-isl-version-check )
-       elif tc_version_is_at_least 4.8 && in_iuse graphite ; then
-               confgcc+=( $(use_with graphite cloog) )
-               use graphite && confgcc+=( --disable-isl-version-check )
+       elif tc_version_is_at_least 5.0 ; then
+               confgcc+=( --without-isl )
+       elif tc_version_is_at_least 4.8 ; then
+               confgcc+=( --without-cloog )
        elif tc_version_is_at_least 4.4 ; then
                confgcc+=( --without-{cloog,ppl} )
        fi
 
-       if tc_version_is_at_least 4.8 && in_iuse sanitize ; then
-               # See Note [implicitly enabled flags]
-               confgcc+=( $(usex sanitize '' --disable-libsanitizer) )
+       if tc_version_is_at_least 4.8; then
+               if in_iuse sanitize ; then
+                       # See Note [implicitly enabled flags]
+                       confgcc+=( $(usex sanitize '' --disable-libsanitizer) )
+               else
+                       confgcc+=( --disable-libsanitizer )
+               fi
        fi
 
        if tc_version_is_at_least 6.0 && in_iuse pie ; then
@@ -1396,7 +1376,8 @@ downgrade_arch_flags() {
        local arch bver i isa myarch mytune rep ver
 
        bver=${1:-${GCC_BRANCH_VER}}
-       [[ $(gcc-version) < ${bver} ]] && return 0
+       # Don't perform downgrade if running gcc is older than ebuild's.
+       tc_version_is_at_least ${bver} $(gcc-version) || return 0
        [[ $(tc-arch) != amd64 && $(tc-arch) != x86 ]] && return 0
 
        myarch=$(get-flag march)
@@ -1404,7 +1385,7 @@ downgrade_arch_flags() {
 
        # If -march=native isn't supported we have to tease out the actual arch
        if [[ ${myarch} == native || ${mytune} == native ]] ; then
-               if [[ ${bver} < 4.2 ]] ; then
+               if ! tc_version_is_at_least 4.2 ${bver}; then
                        arch=$($(tc-getCC) -march=native -v -E -P - </dev/null 2>&1 \
                                | sed -rn "/cc1.*-march/s:.*-march=([^ ']*).*:\1:p")
                        replace-cpu-flags native ${arch}
@@ -1412,10 +1393,10 @@ downgrade_arch_flags() {
        fi
 
        # Handle special -mtune flags
-       [[ ${mytune} == intel && ${bver} < 4.9 ]] && replace-cpu-flags intel generic
-       [[ ${mytune} == generic && ${bver} < 4.2 ]] && filter-flags '-mtune=*'
+       [[ ${mytune} == intel ]] && ! tc_version_is_at_least 4.9 ${bver} && replace-cpu-flags intel generic
+       [[ ${mytune} == generic ]] && ! tc_version_is_at_least 4.2 ${bver} && filter-flags '-mtune=*'
        [[ ${mytune} == x86-64 ]] && filter-flags '-mtune=*'
-       [[ ${bver} < 3.4 ]] && filter-flags '-mtune=*'
+       tc_version_is_at_least 3.4 ${bver} || filter-flags '-mtune=*'
 
        # "added" "arch" "replacement"
        local archlist=(
@@ -1465,8 +1446,8 @@ downgrade_arch_flags() {
 
                [[ ${myarch} != ${arch} && ${mytune} != ${arch} ]] && continue
 
-               if [[ ${ver} > ${bver} ]] ; then
-                       einfo "Replacing ${myarch} (added in gcc ${ver}) with ${rep}..."
+               if ! tc_version_is_at_least ${ver} ${bver}; then
+                       einfo "Downgrading '${myarch}' (added in gcc ${ver}) with '${rep}'..."
                        [[ ${myarch} == ${arch} ]] && replace-cpu-flags ${myarch} ${rep}
                        [[ ${mytune} == ${arch} ]] && replace-cpu-flags ${mytune} ${rep}
                        continue
@@ -1514,13 +1495,17 @@ downgrade_arch_flags() {
        for ((i = 0; i < ${#isalist[@]}; i += 2)) ; do
                ver=${isalist[i]}
                isa=${isalist[i + 1]}
-               [[ ${ver} > ${bver} ]] && filter-flags ${isa} ${isa/-m/-mno-}
+               tc_version_is_at_least ${ver} ${bver} || filter-flags ${isa} ${isa/-m/-mno-}
        done
 }
 
 gcc_do_filter_flags() {
+       # Be conservative here:
+       # - don't allow -O3 and like to over-optimize libgcc # 701786
+       # - don't allow -O0 to generate potentially invalid startup code
        strip-flags
-       replace-flags -O? -O2
+       filter-flags '-O?'
+       append-flags -O2
 
        # dont want to funk ourselves
        filter-flags '-mabi*' -m31 -m32 -m64
@@ -1763,11 +1748,11 @@ gcc_do_make() {
 #---->> src_test <<----
 
 toolchain_src_test() {
-       if use ${GCC_EBUILD_TEST_FLAG} ; then
-               cd "${WORKDIR}"/build
-               # enable verbose test run and result logging
-               emake -k check RUNTESTFLAGS='-a -v'
-       fi
+       cd "${WORKDIR}"/build
+       # 'asan' wants to be preloaded first, so does 'sandbox'.
+       # To make asan tests work disable sandbox for all of test suite.
+       # 'backtrace' tests also does not like 'libsandbox.so' presence.
+       SANDBOX_ON=0 LD_PRELOAD= emake -k check
 }
 
 #---->> src_install <<----
@@ -1832,7 +1817,7 @@ toolchain_src_install() {
        cd "${D}"${BINPATH}
        # Ugh: we really need to auto-detect this list.
        #      It's constantly out of date.
-       for x in cpp gcc g++ c++ gcov g77 gcj gcjh gfortran gccgo ; do
+       for x in cpp gcc g++ c++ gcov g77 gcj gcjh gfortran gccgo gnat* ; do
                # For some reason, g77 gets made instead of ${CTARGET}-g77...
                # this should take care of that
                if [[ -f ${x} ]] ; then
@@ -1845,11 +1830,11 @@ toolchain_src_install() {
                if [[ -f ${CTARGET}-${x} ]] ; then
                        if ! is_crosscompile ; then
                                ln -sf ${CTARGET}-${x} ${x}
-                               dosym ${BINPATH#${EPREFIX}}/${CTARGET}-${x} \
+                               dosym ${BINPATH}/${CTARGET}-${x} \
                                        /usr/bin/${x}-${GCC_CONFIG_VER}
                        fi
                        # Create versioned symlinks
-                       dosym ${BINPATH#${EPREFIX}}/${CTARGET}-${x} \
+                       dosym ${BINPATH}/${CTARGET}-${x} \
                                /usr/bin/${CTARGET}-${x}-${GCC_CONFIG_VER}
                fi
 
@@ -1906,13 +1891,6 @@ toolchain_src_install() {
        # prune empty dirs left behind
        find "${ED}" -depth -type d -delete 2>/dev/null
 
-       # install testsuite results
-       if use ${GCC_EBUILD_TEST_FLAG}; then
-               docinto testsuite
-               find "${WORKDIR}"/build -type f -name "*.sum" -exec dodoc {} +
-               find "${WORKDIR}"/build -type f -path "*/testsuite/*.log" -exec dodoc {} +
-       fi
-
        # Rather install the script, else portage with changing $FILESDIR
        # between binary and source package borks things ....
        if ! is_crosscompile && [[ ${PN} != "kgcc64" ]] ; then
@@ -2246,17 +2224,6 @@ toolchain_pkg_postinst() {
                # handling of binpkgs, don't require these to be found
                cp "${ROOT%/}${DATAPATH}"/c{89,99} "${EROOT%/}"/usr/bin/ 2>/dev/null
        fi
-
-       if use ${GCC_EBUILD_TEST_FLAG} ; then
-               elog "Testsuite results have been installed into /usr/share/doc/${PF}/testsuite"
-               echo
-       fi
-
-       if [[ -n ${PRERELEASE}${SNAPSHOT} ]] ; then
-               einfo "This GCC ebuild is provided for your convenience, and the use"
-               einfo "of this compiler is not supported by the Gentoo Developers."
-               einfo "Please report bugs to upstream at http://gcc.gnu.org/bugzilla/"
-       fi
 }
 
 toolchain_pkg_postrm() {