Gentoo Archives: gentoo-commits

From: Sergei Trofimovich <slyfox@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/tests/, eclass/
Date: Sat, 11 Jan 2020 23:53:22
Message-Id: 1578786788.12bfa1e4f9595dbbcbe0a442c6a63bc3ef890cc2.slyfox@gentoo
1 commit: 12bfa1e4f9595dbbcbe0a442c6a63bc3ef890cc2
2 Author: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
3 AuthorDate: Sat Jan 11 23:11:13 2020 +0000
4 Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
5 CommitDate: Sat Jan 11 23:53:08 2020 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=12bfa1e4
7
8 toolchain.eclass: fix arch downgrade for gcc-10
9
10 The bug is in lexical comparison instead of version compare.
11
12 Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>
13
14 eclass/tests/toolchain.sh | 12 +++++++++++-
15 eclass/toolchain.eclass | 17 +++++++++--------
16 2 files changed, 20 insertions(+), 9 deletions(-)
17
18 diff --git a/eclass/tests/toolchain.sh b/eclass/tests/toolchain.sh
19 index 56609aa180e..1d05f6c126b 100755
20 --- a/eclass/tests/toolchain.sh
21 +++ b/eclass/tests/toolchain.sh
22 @@ -12,6 +12,12 @@ source tests-common.sh
23
24 inherit toolchain
25
26 +# Ignore actually running version of gcc and fake new version
27 +# to force downgrade test on all conditions below.
28 +gcc-version() {
29 + echo "99.99"
30 +}
31 +
32 test_downgrade_arch_flags() {
33 local exp msg ret=0 ver
34
35 @@ -26,13 +32,14 @@ test_downgrade_arch_flags() {
36 downgrade_arch_flags ${ver}
37
38 if [[ ${CFLAGS} != ${exp} ]]; then
39 - msg="Failure - Expected: \"${exp}\" Got: \"${CFLAGS}\""
40 + msg="Failure - Expected: \"${exp}\" Got: \"${CFLAGS}\" Ver: ${ver}"
41 ret=1
42 fi
43 tend ${ret} ${msg}
44 }
45
46 # ver expected given
47 +test_downgrade_arch_flags 10 "-march=haswell" "-march=haswell"
48 test_downgrade_arch_flags 4.9 "-march=haswell" "-march=haswell"
49 test_downgrade_arch_flags 4.8 "-march=core-avx2" "-march=haswell"
50 test_downgrade_arch_flags 4.7 "-march=core-avx2" "-march=haswell"
51 @@ -64,6 +71,7 @@ test_downgrade_arch_flags 3.3 "-march=c3" "-march=c3-2"
52
53 test_downgrade_arch_flags 4.5 "-march=garbage" "-march=garbage"
54
55 +test_downgrade_arch_flags 10 "-mtune=intel" "-mtune=intel"
56 test_downgrade_arch_flags 4.9 "-mtune=intel" "-mtune=intel"
57 test_downgrade_arch_flags 4.8 "-mtune=generic" "-mtune=intel"
58 test_downgrade_arch_flags 3.4 "" "-mtune=generic"
59 @@ -74,9 +82,11 @@ test_downgrade_arch_flags 4.5 "-march=amdfam10 -mtune=generic" "-march=btver2 -m
60 test_downgrade_arch_flags 3.3 "-march=k6-2" "-march=geode -mtune=barcelona"
61 test_downgrade_arch_flags 3.4 "-march=k8" "-march=btver2 -mtune=generic"
62
63 +test_downgrade_arch_flags 10 "-march=native" "-march=native"
64 test_downgrade_arch_flags 4.2 "-march=native" "-march=native"
65 test_downgrade_arch_flags 4.1 "-march=nocona" "-march=native"
66
67 +test_downgrade_arch_flags 10 "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
68 test_downgrade_arch_flags 4.9 "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
69 test_downgrade_arch_flags 4.8 "-march=foo -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
70 test_downgrade_arch_flags 4.7 "-march=foo -mno-avx2 -mno-avx -mno-sse4.1" "-march=foo -mno-sha -mno-rtm -mno-avx2 -mno-avx -mno-sse4.1"
71
72 diff --git a/eclass/toolchain.eclass b/eclass/toolchain.eclass
73 index 5f9bd7750dd..bd3d024f989 100644
74 --- a/eclass/toolchain.eclass
75 +++ b/eclass/toolchain.eclass
76 @@ -1406,7 +1406,8 @@ downgrade_arch_flags() {
77 local arch bver i isa myarch mytune rep ver
78
79 bver=${1:-${GCC_BRANCH_VER}}
80 - [[ $(gcc-version) < ${bver} ]] && return 0
81 + # Don't perform downgrade if running gcc is older than ebuild's.
82 + tc_version_is_at_least ${bver} $(gcc-version) || return 0
83 [[ $(tc-arch) != amd64 && $(tc-arch) != x86 ]] && return 0
84
85 myarch=$(get-flag march)
86 @@ -1414,7 +1415,7 @@ downgrade_arch_flags() {
87
88 # If -march=native isn't supported we have to tease out the actual arch
89 if [[ ${myarch} == native || ${mytune} == native ]] ; then
90 - if [[ ${bver} < 4.2 ]] ; then
91 + if ! tc_version_is_at_least 4.2 ${bver}; then
92 arch=$($(tc-getCC) -march=native -v -E -P - </dev/null 2>&1 \
93 | sed -rn "/cc1.*-march/s:.*-march=([^ ']*).*:\1:p")
94 replace-cpu-flags native ${arch}
95 @@ -1422,10 +1423,10 @@ downgrade_arch_flags() {
96 fi
97
98 # Handle special -mtune flags
99 - [[ ${mytune} == intel && ${bver} < 4.9 ]] && replace-cpu-flags intel generic
100 - [[ ${mytune} == generic && ${bver} < 4.2 ]] && filter-flags '-mtune=*'
101 + [[ ${mytune} == intel ]] && ! tc_version_is_at_least 4.9 ${bver} && replace-cpu-flags intel generic
102 + [[ ${mytune} == generic ]] && ! tc_version_is_at_least 4.2 ${bver} && filter-flags '-mtune=*'
103 [[ ${mytune} == x86-64 ]] && filter-flags '-mtune=*'
104 - [[ ${bver} < 3.4 ]] && filter-flags '-mtune=*'
105 + tc_version_is_at_least 3.4 ${bver} || filter-flags '-mtune=*'
106
107 # "added" "arch" "replacement"
108 local archlist=(
109 @@ -1475,8 +1476,8 @@ downgrade_arch_flags() {
110
111 [[ ${myarch} != ${arch} && ${mytune} != ${arch} ]] && continue
112
113 - if [[ ${ver} > ${bver} ]] ; then
114 - einfo "Replacing ${myarch} (added in gcc ${ver}) with ${rep}..."
115 + if ! tc_version_is_at_least ${ver} ${bver}; then
116 + einfo "Downgrading '${myarch}' (added in gcc ${ver}) with '${rep}'..."
117 [[ ${myarch} == ${arch} ]] && replace-cpu-flags ${myarch} ${rep}
118 [[ ${mytune} == ${arch} ]] && replace-cpu-flags ${mytune} ${rep}
119 continue
120 @@ -1524,7 +1525,7 @@ downgrade_arch_flags() {
121 for ((i = 0; i < ${#isalist[@]}; i += 2)) ; do
122 ver=${isalist[i]}
123 isa=${isalist[i + 1]}
124 - [[ ${ver} > ${bver} ]] && filter-flags ${isa} ${isa/-m/-mno-}
125 + tc_version_is_at_least ${ver} ${bver} || filter-flags ${isa} ${isa/-m/-mno-}
126 done
127 }