1 |
commit: 22340228f5dbbfcbb63f05b3b848616d6892f245 |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Nov 29 13:41:04 2020 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Nov 29 13:41:04 2020 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/proj/prefix.git/commit/?id=22340228 |
7 |
|
8 |
eclass/flag-o-matic: sync with gx86, bug #757258 |
9 |
|
10 |
Closes: https://bugs.gentoo.org/757258 |
11 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
12 |
|
13 |
eclass/flag-o-matic.eclass | 129 ++++++++++++++++++++++++++++++++++----------- |
14 |
1 file changed, 99 insertions(+), 30 deletions(-) |
15 |
|
16 |
diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass |
17 |
index 1a5d1e8099..f75a975a08 100644 |
18 |
--- a/eclass/flag-o-matic.eclass |
19 |
+++ b/eclass/flag-o-matic.eclass |
20 |
@@ -1,4 +1,4 @@ |
21 |
-# Copyright 1999-2017 Gentoo Foundation |
22 |
+# Copyright 1999-2020 Gentoo Authors |
23 |
# Distributed under the terms of the GNU General Public License v2 |
24 |
|
25 |
# @ECLASS: flag-o-matic.eclass |
26 |
@@ -27,7 +27,14 @@ setup-allowed-flags() { |
27 |
'-fstack-protector*' '-fsanitize*' '-fstack-check*' -fno-stack-check |
28 |
-fbounds-check -fbounds-checking -fno-strict-overflow |
29 |
-fno-PIE -fno-pie -nopie -no-pie -fno-unit-at-a-time |
30 |
- -g '-g[0-9]' -ggdb '-ggdb[0-9]' '-gdwarf-*' gstabs -gstabs+ -gz |
31 |
+ |
32 |
+ # debugging symbols should generally be very safe to add |
33 |
+ -g '-g[0-9]' |
34 |
+ -ggdb '-ggdb[0-9]' |
35 |
+ -gdwarf '-gdwarf-*' |
36 |
+ -gstabs -gstabs+ |
37 |
+ -gz |
38 |
+ |
39 |
-fno-ident -fpermissive -frecord-gcc-switches |
40 |
'-fdiagnostics*' '-fplugin*' |
41 |
'-W*' -w |
42 |
@@ -56,7 +63,9 @@ setup-allowed-flags() { |
43 |
-mno-faster-structs -mfaster-structs -m32 -m64 -mx32 -mabi |
44 |
-mlittle-endian -mbig-endian -EL -EB -fPIC -mlive-g0 -mcmodel |
45 |
-mstack-bias -mno-stack-bias -msecure-plt '-m*-toc' -mfloat-abi |
46 |
- -mfix-r10000 -mno-fix-r10000 -mthumb -marm |
47 |
+ -mfix-r4000 -mno-fix-r4000 -mfix-r4400 -mno-fix-r4400 |
48 |
+ -mfix-rm7000 -mno-fix-rm7000 -mfix-r10000 -mno-fix-r10000 |
49 |
+ -mr10k-cache-barrier -mthumb -marm |
50 |
|
51 |
# gcc 4.5 |
52 |
-mno-fma4 -mno-movbe -mno-xop -mno-lwp |
53 |
@@ -395,6 +404,7 @@ filter-mfpmath() { |
54 |
# Strip *FLAGS of everything except known good/safe flags. This runs over all |
55 |
# flags returned by all_flag_vars(). |
56 |
strip-flags() { |
57 |
+ [[ $# -ne 0 ]] && die "strip-flags takes no arguments" |
58 |
local x y var |
59 |
|
60 |
local ALLOWED_FLAGS |
61 |
@@ -436,25 +446,81 @@ test-flag-PROG() { |
62 |
local lang=$2 |
63 |
shift 2 |
64 |
|
65 |
- [[ -z ${comp} || -z $1 ]] && return 1 |
66 |
+ if [[ -z ${comp} ]]; then |
67 |
+ return 1 |
68 |
+ fi |
69 |
+ if [[ -z $1 ]]; then |
70 |
+ return 1 |
71 |
+ fi |
72 |
|
73 |
- local src=${T}/tf-${comp}-${SECONDS}.${lang} |
74 |
+ # verify selected compiler exists before using it |
75 |
+ comp=($(tc-get${comp})) |
76 |
+ # 'comp' can already contain compiler options. |
77 |
+ # 'type' needs a binary name |
78 |
+ if ! type -p ${comp[0]} >/dev/null; then |
79 |
+ return 1 |
80 |
+ fi |
81 |
+ |
82 |
+ # Set up test file. |
83 |
+ local in_src in_ext cmdline_extra=() |
84 |
+ case "${lang}" in |
85 |
+ # compiler/assembler only |
86 |
+ c) |
87 |
+ in_ext='c' |
88 |
+ in_src='int main(void) { return 0; }' |
89 |
+ cmdline_extra+=(-xc -c) |
90 |
+ ;; |
91 |
+ c++) |
92 |
+ in_ext='cc' |
93 |
+ in_src='int main(void) { return 0; }' |
94 |
+ cmdline_extra+=(-xc++ -c) |
95 |
+ ;; |
96 |
+ f77) |
97 |
+ in_ext='f' |
98 |
+ # fixed source form |
99 |
+ in_src=' end' |
100 |
+ cmdline_extra+=(-xf77 -c) |
101 |
+ ;; |
102 |
+ f95) |
103 |
+ in_ext='f90' |
104 |
+ in_src='end' |
105 |
+ cmdline_extra+=(-xf95 -c) |
106 |
+ ;; |
107 |
+ |
108 |
+ # C compiler/assembler/linker |
109 |
+ c+ld) |
110 |
+ in_ext='c' |
111 |
+ in_src='int main(void) { return 0; }' |
112 |
+ cmdline_extra+=(-xc) |
113 |
+ ;; |
114 |
+ esac |
115 |
+ local test_in=${T}/test-flag.${in_ext} |
116 |
+ local test_out=${T}/test-flag.exe |
117 |
+ |
118 |
+ printf "%s\n" "${in_src}" > "${test_in}" || die "Failed to create '${test_in}'" |
119 |
+ |
120 |
+ # Currently we rely on warning-free output of a compiler |
121 |
+ # before the flag to see if a flag prduces any warnings. |
122 |
+ # This has a few drawbacks: |
123 |
+ # - if compiler already generates warnings we filter out |
124 |
+ # every single flag: bug #712488 |
125 |
+ # - if user actually wants to see warnings we just strip |
126 |
+ # them regardless of warnings type. |
127 |
+ # |
128 |
+ # We can add more selective detection of no-op flags via |
129 |
+ # '-Werror=ignored-optimization-argument' and similar error options |
130 |
+ # similar to what we are doing with '-Qunused-arguments'. |
131 |
local cmdline=( |
132 |
- $(tc-get${comp}) |
133 |
+ "${comp[@]}" |
134 |
# Clang will warn about unknown gcc flags but exit 0. |
135 |
# Need -Werror to force it to exit non-zero. |
136 |
-Werror |
137 |
- # Use -c so we can test the assembler as well. |
138 |
- # don't use -o /dev/null: /usr/ccs/bin/as: File exists (Sun LD) |
139 |
- -c -o "${src}.o" |
140 |
+ "$@" |
141 |
+ # -x<lang> options need to go before first source file |
142 |
+ "${cmdline_extra[@]}" |
143 |
+ |
144 |
+ "${test_in}" -o "${test_out}" |
145 |
) |
146 |
- if "${cmdline[@]}" -x${lang} - </dev/null &>/dev/null ; then |
147 |
- cmdline+=( "$@" -x${lang} - ) |
148 |
- else |
149 |
- # don't use /dev/null as input: -xc flag needs not to exist #254120 |
150 |
- echo "int main() { return 0; }" > "${src}" |
151 |
- cmdline+=( "$@" -c -o "${src}.o" "${src}" ) |
152 |
- fi |
153 |
|
154 |
if ! "${cmdline[@]}" </dev/null &>/dev/null; then |
155 |
# -Werror makes clang bail out on unused arguments as well; |
156 |
@@ -464,9 +530,6 @@ test-flag-PROG() { |
157 |
cmdline+=( -Qunused-arguments ) |
158 |
"${cmdline[@]}" </dev/null &>/dev/null |
159 |
fi |
160 |
- local ret=$? |
161 |
- rm -f "${src}"{,.o} |
162 |
- [[ ${ret} == 0 ]] && true || false |
163 |
} |
164 |
|
165 |
# @FUNCTION: test-flag-CC |
166 |
@@ -493,6 +556,12 @@ test-flag-F77() { test-flag-PROG "F77" f77 "$@"; } |
167 |
# Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false. |
168 |
test-flag-FC() { test-flag-PROG "FC" f95 "$@"; } |
169 |
|
170 |
+# @FUNCTION: test-flag-CCLD |
171 |
+# @USAGE: <flag> |
172 |
+# @DESCRIPTION: |
173 |
+# Returns shell true if <flag> is supported by the C compiler and linker, else returns shell false. |
174 |
+test-flag-CCLD() { test-flag-PROG "CC" c+ld "$@"; } |
175 |
+ |
176 |
test-flags-PROG() { |
177 |
local comp=$1 |
178 |
local flags=() |
179 |
@@ -549,6 +618,12 @@ test-flags-F77() { test-flags-PROG "F77" "$@"; } |
180 |
# Returns shell true if <flags> are supported by the Fortran 90 compiler, else returns shell false. |
181 |
test-flags-FC() { test-flags-PROG "FC" "$@"; } |
182 |
|
183 |
+# @FUNCTION: test-flags-CCLD |
184 |
+# @USAGE: <flags> |
185 |
+# @DESCRIPTION: |
186 |
+# Returns shell true if <flags> are supported by the C compiler and default linker, else returns shell false. |
187 |
+test-flags-CCLD() { test-flags-PROG "CCLD" "$@"; } |
188 |
+ |
189 |
# @FUNCTION: test-flags |
190 |
# @USAGE: <flags> |
191 |
# @DESCRIPTION: |
192 |
@@ -573,13 +648,12 @@ test_version_info() { |
193 |
# @DESCRIPTION: |
194 |
# Strip {C,CXX,F,FC}FLAGS of any flags not supported by the active toolchain. |
195 |
strip-unsupported-flags() { |
196 |
+ [[ $# -ne 0 ]] && die "strip-unsupported-flags takes no arguments" |
197 |
export CFLAGS=$(test-flags-CC ${CFLAGS}) |
198 |
export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS}) |
199 |
export FFLAGS=$(test-flags-F77 ${FFLAGS}) |
200 |
export FCFLAGS=$(test-flags-FC ${FCFLAGS}) |
201 |
- # note: this does not verify the linker flags but it is enough |
202 |
- # to strip invalid C flags which are much more likely, #621274 |
203 |
- export LDFLAGS=$(test-flags-CC ${LDFLAGS}) |
204 |
+ export LDFLAGS=$(test-flags-CCLD ${LDFLAGS}) |
205 |
} |
206 |
|
207 |
# @FUNCTION: get-flag |
208 |
@@ -587,6 +661,7 @@ strip-unsupported-flags() { |
209 |
# @DESCRIPTION: |
210 |
# Find and echo the value for a particular flag. Accepts shell globs. |
211 |
get-flag() { |
212 |
+ [[ $# -ne 1 ]] && die "usage: <flag>" |
213 |
local f var findflag="$1" |
214 |
|
215 |
# this code looks a little flaky but seems to work for |
216 |
@@ -605,18 +680,11 @@ get-flag() { |
217 |
return 1 |
218 |
} |
219 |
|
220 |
-has_m64() { |
221 |
- die "${FUNCNAME}: don't use this anymore" |
222 |
-} |
223 |
- |
224 |
-has_m32() { |
225 |
- die "${FUNCNAME}: don't use this anymore" |
226 |
-} |
227 |
- |
228 |
# @FUNCTION: replace-sparc64-flags |
229 |
# @DESCRIPTION: |
230 |
# Sets mcpu to v8 and uses the original value as mtune if none specified. |
231 |
replace-sparc64-flags() { |
232 |
+ [[ $# -ne 0 ]] && die "replace-sparc64-flags takes no arguments" |
233 |
local SPARC64_CPUS="ultrasparc3 ultrasparc v9" |
234 |
|
235 |
if [ "${CFLAGS/mtune}" != "${CFLAGS}" ]; then |
236 |
@@ -700,6 +768,7 @@ raw-ldflags() { |
237 |
# @FUNCTION: no-as-needed |
238 |
# @RETURN: Flag to disable asneeded behavior for use with append-ldflags. |
239 |
no-as-needed() { |
240 |
+ [[ $# -ne 0 ]] && die "no-as-needed takes no arguments" |
241 |
case $($(tc-getLD) -v 2>&1 </dev/null) in |
242 |
*GNU*) # GNU ld |
243 |
echo "-Wl,--no-as-needed" ;; |