summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
authorRyan Hill <dirtyepic@gentoo.org>2014-02-02 23:43:49 +0000
committerRyan Hill <dirtyepic@gentoo.org>2014-02-02 23:43:49 +0000
commitc197eb06141497aa1246b021244067ea3b692f7b (patch)
treec42f74f41e560694cd22fafa98661999151c1f22 /eclass
parentVersion bump. Drop old version. (diff)
downloadgentoo-2-c197eb06141497aa1246b021244067ea3b692f7b.tar.gz
gentoo-2-c197eb06141497aa1246b021244067ea3b692f7b.tar.bz2
gentoo-2-c197eb06141497aa1246b021244067ea3b692f7b.zip
Add downgrade_arch_flags() to automatically replace/strip unsupported -march
and instruction set flags. Add testsuite.
Diffstat (limited to 'eclass')
-rw-r--r--eclass/ChangeLog7
-rwxr-xr-xeclass/tests/toolchain.sh81
-rw-r--r--eclass/toolchain.eclass139
3 files changed, 212 insertions, 15 deletions
diff --git a/eclass/ChangeLog b/eclass/ChangeLog
index b89739086b97..a4a96edb256e 100644
--- a/eclass/ChangeLog
+++ b/eclass/ChangeLog
@@ -1,6 +1,11 @@
# ChangeLog for eclass directory
# Copyright 1999-2014 Gentoo Foundation; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1135 2014/02/02 12:15:05 hasufell Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/ChangeLog,v 1.1136 2014/02/02 23:43:48 dirtyepic Exp $
+
+ 02 Feb 2014; Ryan Hill <dirtyepic@gentoo.org> +tests/toolchain.sh,
+ toolchain.eclass:
+ Add downgrade_arch_flags() to automatically replace/strip unsupported -march
+ and instruction set flags. Add testsuite.
02 Feb 2014; Julian Ospald <hasufell@gentoo.org> games.eclass:
respect ECONF_SOURCE wrt #494210
diff --git a/eclass/tests/toolchain.sh b/eclass/tests/toolchain.sh
new file mode 100755
index 000000000000..7040707310a9
--- /dev/null
+++ b/eclass/tests/toolchain.sh
@@ -0,0 +1,81 @@
+#!/bin/bash
+
+source tests-common.sh
+
+inherit toolchain
+
+test_downgrade_arch_flags() {
+ local exp msg ret=0 ver
+
+ ver=${1}
+ exp=${2}
+ shift 2
+ CFLAGS=${@}
+
+ tbegin "${ver} ${CFLAGS} => ${exp}"
+
+ downgrade_arch_flags ${ver}
+
+ if [[ ${CFLAGS} != ${exp} ]]; then
+ msg="Failure - Expected: \"${exp}\" Got: \"${CFLAGS}\""
+ ret=1
+ fi
+ tend ${ret} ${msg}
+}
+
+# ver expected given
+test_downgrade_arch_flags 4.9 "-march=haswell" "-march=haswell"
+test_downgrade_arch_flags 4.8 "-march=core-avx2" "-march=haswell"
+test_downgrade_arch_flags 4.7 "-march=core-avx2" "-march=haswell"
+test_downgrade_arch_flags 4.6 "-march=core-avx-i" "-march=haswell"
+test_downgrade_arch_flags 4.5 "-march=core2" "-march=haswell"
+test_downgrade_arch_flags 4.4 "-march=core2" "-march=haswell"
+test_downgrade_arch_flags 4.3 "-march=core2" "-march=haswell"
+test_downgrade_arch_flags 4.2 "-march=nocona" "-march=haswell"
+test_downgrade_arch_flags 4.1 "-march=nocona" "-march=haswell"
+test_downgrade_arch_flags 4.0 "-march=nocona" "-march=haswell"
+test_downgrade_arch_flags 3.4 "-march=nocona" "-march=haswell"
+test_downgrade_arch_flags 3.3 "-march=nocona" "-march=haswell"
+
+test_downgrade_arch_flags 4.9 "-march=bdver4" "-march=bdver4"
+test_downgrade_arch_flags 4.8 "-march=bdver3" "-march=bdver4"
+test_downgrade_arch_flags 4.7 "-march=bdver2" "-march=bdver4"
+test_downgrade_arch_flags 4.6 "-march=bdver1" "-march=bdver4"
+test_downgrade_arch_flags 4.5 "-march=amdfam10" "-march=bdver4"
+test_downgrade_arch_flags 4.4 "-march=amdfam10" "-march=bdver4"
+test_downgrade_arch_flags 4.3 "-march=amdfam10" "-march=bdver4"
+test_downgrade_arch_flags 4.2 "-march=k8" "-march=bdver4"
+test_downgrade_arch_flags 4.1 "-march=k8" "-march=bdver4"
+test_downgrade_arch_flags 4.0 "-march=k8" "-march=bdver4"
+test_downgrade_arch_flags 3.4 "-march=k8" "-march=bdver4"
+test_downgrade_arch_flags 3.3 "-march=x86-64" "-march=bdver4"
+
+test_downgrade_arch_flags 3.4 "-march=c3-2" "-march=c3-2"
+test_downgrade_arch_flags 3.3 "-march=c3" "-march=c3-2"
+
+test_downgrade_arch_flags 4.5 "-march=garbage" "-march=garbage"
+
+test_downgrade_arch_flags 4.9 "-mtune=intel" "-mtune=intel"
+test_downgrade_arch_flags 4.8 "-mtune=generic" "-mtune=intel"
+test_downgrade_arch_flags 3.4 "" "-mtune=generic"
+test_downgrade_arch_flags 3.4 "" "-mtune=x86-64"
+test_downgrade_arch_flags 3.3 "-mtune=nocona" "-mtune=haswell"
+
+test_downgrade_arch_flags 4.5 "-march=amdfam10 -mtune=generic" "-march=btver2 -mtune=generic"
+test_downgrade_arch_flags 3.3 "-march=k6-2" "-march=geode -mtune=barcelona"
+test_downgrade_arch_flags 3.4 "-march=k8" "-march=btver2 -mtune=generic"
+
+test_downgrade_arch_flags 4.2 "-march=native" "-march=native"
+test_downgrade_arch_flags 4.1 "-march=nocona" "-march=native"
+
+test_downgrade_arch_flags 4.9 "-march=foo -msha -mrtm -mavx2 -mbmi -mno-xop -maes -mno-sse4" "-march=foo -msha -mrtm -mavx2 -mbmi -mno-xop -maes -mno-sse4"
+test_downgrade_arch_flags 4.8 "-march=foo -mrtm -mavx2 -mbmi -mno-xop -maes -mno-sse4" "-march=foo -msha -mrtm -mavx2 -mbmi -mno-xop -maes -mno-sse4"
+test_downgrade_arch_flags 4.7 "-march=foo -mavx2 -mbmi -mno-xop -maes -mno-sse4" "-march=foo -msha -mrtm -mavx2 -mbmi -mno-xop -maes -mno-sse4"
+test_downgrade_arch_flags 4.6 "-march=foo -mbmi -mno-xop -maes -mno-sse4" "-march=foo -msha -mrtm -mavx2 -mbmi -mno-xop -maes -mno-sse4"
+test_downgrade_arch_flags 4.5 "-march=foo -mno-xop -maes -mno-sse4" "-march=foo -msha -mrtm -mavx2 -mbmi -mno-xop -maes -mno-sse4"
+test_downgrade_arch_flags 4.4 "-march=foo -maes -mno-sse4" "-march=foo -msha -mrtm -mavx2 -mbmi -mno-xop -maes -mno-sse4"
+test_downgrade_arch_flags 4.3 "-march=foo -mno-sse4" "-march=foo -msha -mrtm -mavx2 -mbmi -mno-xop -maes -mno-sse4"
+test_downgrade_arch_flags 4.2 "-march=foo" "-march=foo -msha -mrtm -mavx2 -mbmi -mno-xop -maes -mno-sse4"
+
+test_downgrade_arch_flags 4.4 "-O2 -march=core2 -ffoo -fblah" "-O2 -march=atom -msha -ffoo -mrtm -mavx2 -fblah"
+texit
diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass
index c2213f914bbc..540e8377e167 100644
--- a/eclass/toolchain.eclass
+++ b/eclass/toolchain.eclass
@@ -1,6 +1,6 @@
# Copyright 1999-2014 Gentoo Foundation
# Distributed under the terms of the GNU General Public License v2
-# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain.eclass,v 1.621 2014/01/24 04:13:58 dirtyepic Exp $
+# $Header: /var/cvsroot/gentoo-x86/eclass/toolchain.eclass,v 1.622 2014/02/02 23:43:48 dirtyepic Exp $
# Maintainer: Toolchain Ninjas <toolchain@gentoo.org>
@@ -770,6 +770,7 @@ do_gcc_rename_java_bins() {
#---->> src_configure <<----
toolchain_src_configure() {
+ downgrade_arch_flags
gcc_do_filter_flags
einfo "CFLAGS=\"${CFLAGS}\""
@@ -1206,6 +1207,129 @@ toolchain_src_configure() {
popd > /dev/null
}
+# Replace -m flags unsupported by the version being built with the best
+# available equivalent
+downgrade_arch_flags() {
+ local arch bver i isa myarch mytune rep ver
+
+ bver=${1:-${GCC_BRANCH_VER}}
+ [[ $(gcc-version) < ${bver} ]] && return 0
+
+ myarch=$(get-flag march)
+ mytune=$(get-flag mtune)
+
+ # 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
+ arch=$(echo "" | $(tc-getCC) -march=native -v -E - 2>&1 \
+ | grep cc1 | sed -e 's:.*-march=\([^ ]*\).*:\1:')
+ replace-cpu-flags native ${arch}
+ fi
+ fi
+
+ # Handle special -mtune flags
+ [[ ${mytune} == intel && ${bver} < "4.9" ]] && replace-cpu-flags intel generic
+ [[ ${mytune} == generic && ${bver} < "4.2" ]] && filter-flags '-mtune=*'
+ [[ ${mytune} == x86-64 ]] && filter-flags '-mtune=*'
+
+ declare -a archlist
+ # "arch" "added" "replacement"
+ archlist=("bdver4 4.9 bdver3")
+ archlist+=("bonnell 4.9 atom")
+ archlist+=("broadwell 4.9 core-avx2")
+ archlist+=("haswell 4.9 core-avx2")
+ archlist+=("ivybridge 4.9 core-avx-i")
+ archlist+=("nehalem 4.9 corei7")
+ archlist+=("sandybridge 4.9 corei7-avx")
+ archlist+=("silvermont 4.9 corei7")
+ archlist+=("westmere 4.9 corei7")
+ archlist+=("bdver3 4.8 bdver2")
+ archlist+=("btver2 4.8 btver1")
+ archlist+=("bdver2 4.7 bdver1")
+ archlist+=("core-avx2 4.7 core-avx-i")
+ archlist+=("bdver1 4.6 amdfam10")
+ archlist+=("btver1 4.6 amdfam10")
+ archlist+=("core-avx-i 4.6 core2")
+ archlist+=("corei7 4.6 core2")
+ archlist+=("corei7-avx 4.6 core2")
+ archlist+=("atom 4.5 core2")
+ archlist+=("amdfam10 4.3 k8")
+ archlist+=("athlon64-sse3 4.3 k8")
+ archlist+=("barcelona 4.3 k8")
+ archlist+=("core2 4.3 nocona")
+ archlist+=("geode 4.3 k6-2") # gcc.gnu.org/PR41989#c22
+ archlist+=("k8-sse3 4.3 k8")
+ archlist+=("opteron-sse3 4.3 k8")
+ archlist+=("athlon-fx 3.4 x86-64")
+ archlist+=("athlon64 3.4 x86-64")
+ archlist+=("c3-2 3.4 c3")
+ archlist+=("k8 3.4 x86-64")
+ archlist+=("opteron 3.4 x86-64")
+ archlist+=("pentium-m 3.4 pentium3")
+ archlist+=("pentium3m 3.4 pentium3")
+ archlist+=("pentium4m 3.4 pentium4")
+
+ myarch=$(get-flag march)
+ mytune=$(get-flag mtune)
+
+ for ((i=0; i < ${#archlist[@]}; i++)) ; do
+ arch=${archlist[i]%% *}
+ ver=${archlist[i]#* } ver=${ver% *}
+ rep=${archlist[i]##* }
+
+ [[ ${myarch} != ${arch} ]] && [[ ${mytune} != ${arch} ]] && continue
+
+ if [[ ${ver} > ${bver} ]] ; then
+ einfo "Replacing ${myarch} (added in ${ver}) with ${rep}..."
+ [[ ${myarch} == ${arch} ]] && replace-cpu-flags ${myarch} ${rep}
+ [[ ${mytune} == ${arch} ]] && replace-cpu-flags ${mytune} ${rep}
+ downgrade_arch_flags ${1:-${GCC_BRANCH_VER}}
+ break
+ else
+ break
+ fi
+ done
+
+ declare -a isalist
+ isalist=("-msha 4.9")
+ isalist+=("-mavx512pf 4.9")
+ isalist+=("-mavx512f 4.9")
+ isalist+=("-mavx512er 4.9")
+ isalist+=("-mavx512cd 4.9")
+ isalist+=("-mxsaveopt 4.8")
+ isalist+=("-mxsave 4.8")
+ isalist+=("-mrtm 4.8")
+ isalist+=("-mfxsr 4.8")
+ isalist+=("-mlzcnt 4.7")
+ isalist+=("-mbmi2 4.7")
+ isalist+=("-mavx2 4.7")
+ isalist+=("-mtbm 4.6")
+ isalist+=("-mrdrnd 4.6")
+ isalist+=("-mfsgsbase 4.6")
+ isalist+=("-mf16c 4.6")
+ isalist+=("-mbmi 4.6")
+ isalist+=("-mxop 4.5")
+ isalist+=("-mlwp 4.5")
+ isalist+=("-mfma4 4.5")
+ isalist+=("-mpclmul 4.4")
+ isalist+=("-mfma 4.4")
+ isalist+=("-mavx 4.4")
+ isalist+=("-maes 4.4")
+ isalist+=("-mssse3 4.3")
+ isalist+=("-msse4a 4.3")
+ isalist+=("-msse4 4.3")
+ isalist+=("-msse4.2 4.3")
+ isalist+=("-msse4.1 4.3")
+ isalist+=("-mpopcnt 4.3")
+ isalist+=("-mabm 4.3")
+
+ for ((i=0; i < ${#isalist[@]}; i++)) ; do
+ isa=${isalist[i]%% *}
+ ver=${isalist[i]##* }
+ [[ ${ver} > ${bver} ]] && filter-flags ${isa} ${isa/-m/-mno-}
+ done
+}
+
gcc_do_filter_flags() {
strip-flags
replace-flags -O? -O2
@@ -1217,23 +1341,10 @@ gcc_do_filter_flags() {
if tc_version_is_between 3.2 3.4 ; then
# XXX: this is so outdated it's barely useful, but it don't hurt...
- replace-cpu-flags k8 athlon64 opteron x86-64
- replace-cpu-flags pentium-m pentium3m pentium3
replace-cpu-flags G3 750
replace-cpu-flags G4 7400
replace-cpu-flags G5 7400
- case $(tc-arch) in
- amd64)
- replace-cpu-flags core2 nocona
- filter-flags '-mtune=*'
- ;;
- x86)
- replace-cpu-flags core2 prescott
- filter-flags '-mtune=*'
- ;;
- esac
-
# XXX: should add a sed or something to query all supported flags
# from the gcc source and trim everything else ...
filter-flags -f{no-,}unit-at-a-time -f{no-,}web -mno-tls-direct-seg-refs