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: Tue, 24 Dec 2019 11:01:16
Message-Id: 1577185261.28d6437fc7009002f98f28e8900e994109927726.slyfox@gentoo
1 commit: 28d6437fc7009002f98f28e8900e994109927726
2 Author: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
3 AuthorDate: Mon Dec 23 11:41:20 2019 +0000
4 Commit: Sergei Trofimovich <slyfox <AT> gentoo <DOT> org>
5 CommitDate: Tue Dec 24 11:01:01 2019 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=28d6437f
7
8 flag-o-matic.eclass: add LDFLAGS testing against linker
9
10 Before the change we tested only compiler driver (gcc flag parser)
11 for LDFLAGS.
12
13 This does not cover cases when we would really like to filter out
14 unsupported linker flags like -Wl,--hash-style=gnu passed to non-ELF
15 targets.
16
17 The change adds test-flag-CCLD() helper to perform all of assembly,
18 compilation and linking steps. Helper is used to filter LDFLAGS variable
19 in strip-unsupported-flags().
20
21 Closes: https://bugs.gentoo.org/333763
22 Signed-off-by: Sergei Trofimovich <slyfox <AT> gentoo.org>
23
24 eclass/flag-o-matic.eclass | 72 +++++++++++++++++++++++++++++++++++---------
25 eclass/tests/flag-o-matic.sh | 2 +-
26 2 files changed, 59 insertions(+), 15 deletions(-)
27
28 diff --git a/eclass/flag-o-matic.eclass b/eclass/flag-o-matic.eclass
29 index f882b09d621..0aec22c83f2 100644
30 --- a/eclass/flag-o-matic.eclass
31 +++ b/eclass/flag-o-matic.eclass
32 @@ -441,29 +441,63 @@ test-flag-PROG() {
33 # 'type' needs a binary name
34 type -p ${comp[0]} >/dev/null || return 1
35
36 + # Set up test file.
37 + local in_src in_ext cmdline_extra=()
38 + case "${lang}" in
39 + # compiler/assembler only
40 + c)
41 + in_ext='.c'
42 + in_src='int main(void) { return 0; }'
43 + cmdline_extra+=(-xc -c)
44 + ;;
45 + c++)
46 + in_ext='.cc'
47 + in_src='int main(void) { return 0; }'
48 + cmdline_extra+=(-xc++ -c)
49 + ;;
50 + f77)
51 + in_ext='.f'
52 + # fixed source form
53 + in_src=' end'
54 + cmdline_extra+=(-xf77 -c)
55 + ;;
56 + f95)
57 + in_ext='.f90'
58 + in_src='end'
59 + cmdline_extra+=(-xf95 -c)
60 + ;;
61 +
62 + # C compiler/assembler/linker
63 + c+ld)
64 + in_ext='.c'
65 + in_src='int main(void) { return 0; }'
66 + cmdline_extra+=(-xc)
67 + ;;
68 + esac
69 + local test_in=${T}/test-flag-${comp}.${lang}
70 + local test_out=${T}/test-flag-${comp}.exe
71 +
72 + printf "%s\n" "${in_src}" > "${test_in}" || return 1
73 +
74 local cmdline=(
75 "${comp[@]}"
76 # Clang will warn about unknown gcc flags but exit 0.
77 # Need -Werror to force it to exit non-zero.
78 -Werror
79 - # Use -c so we can test the assembler as well.
80 - -c -o /dev/null
81 + "$@"
82 + # -x<lang> options need to go before first source file
83 + "${cmdline_extra[@]}"
84 +
85 + "${test_in}" -o "${test_out}"
86 )
87 - if "${cmdline[@]}" -x${lang} - </dev/null &>/dev/null ; then
88 - cmdline+=( "$@" -x${lang} - )
89 - else
90 - # XXX: what's the purpose of this? does it even work with
91 - # any compiler?
92 - cmdline+=( "$@" -c -o /dev/null /dev/null )
93 - fi
94
95 - if ! "${cmdline[@]}" </dev/null &>/dev/null; then
96 + if ! "${cmdline[@]}" &>/dev/null; then
97 # -Werror makes clang bail out on unused arguments as well;
98 # try to add -Qunused-arguments to work-around that
99 # other compilers don't support it but then, it's failure like
100 # any other
101 cmdline+=( -Qunused-arguments )
102 - "${cmdline[@]}" </dev/null &>/dev/null
103 + "${cmdline[@]}" &>/dev/null
104 fi
105 }
106
107 @@ -491,6 +525,12 @@ test-flag-F77() { test-flag-PROG "F77" f77 "$@"; }
108 # Returns shell true if <flag> is supported by the Fortran 90 compiler, else returns shell false.
109 test-flag-FC() { test-flag-PROG "FC" f95 "$@"; }
110
111 +# @FUNCTION: test-flag-CCLD
112 +# @USAGE: <flag>
113 +# @DESCRIPTION:
114 +# Returns shell true if <flag> is supported by the C compiler and linker, else returns shell false.
115 +test-flag-CCLD() { test-flag-PROG "CC" c+ld "$@"; }
116 +
117 test-flags-PROG() {
118 local comp=$1
119 local flags=()
120 @@ -548,6 +588,12 @@ test-flags-F77() { test-flags-PROG "F77" "$@"; }
121 # Returns shell true if <flags> are supported by the Fortran 90 compiler, else returns shell false.
122 test-flags-FC() { test-flags-PROG "FC" "$@"; }
123
124 +# @FUNCTION: test-flags-CCLD
125 +# @USAGE: <flags>
126 +# @DESCRIPTION:
127 +# Returns shell true if <flags> are supported by the C compiler and default linker, else returns shell false.
128 +test-flags-CCLD() { test-flags-PROG "CCLD" "$@"; }
129 +
130 # @FUNCTION: test-flags
131 # @USAGE: <flags>
132 # @DESCRIPTION:
133 @@ -576,9 +622,7 @@ strip-unsupported-flags() {
134 export CXXFLAGS=$(test-flags-CXX ${CXXFLAGS})
135 export FFLAGS=$(test-flags-F77 ${FFLAGS})
136 export FCFLAGS=$(test-flags-FC ${FCFLAGS})
137 - # note: this does not verify the linker flags but it is enough
138 - # to strip invalid C flags which are much more likely, #621274
139 - export LDFLAGS=$(test-flags-CC ${LDFLAGS})
140 + export LDFLAGS=$(test-flags-CCLD ${LDFLAGS})
141 }
142
143 # @FUNCTION: get-flag
144
145 diff --git a/eclass/tests/flag-o-matic.sh b/eclass/tests/flag-o-matic.sh
146 index 7c078499d70..90eaf3a6ffb 100755
147 --- a/eclass/tests/flag-o-matic.sh
148 +++ b/eclass/tests/flag-o-matic.sh
149 @@ -8,7 +8,7 @@ inherit flag-o-matic
150
151 CFLAGS="-a -b -c=1 --param l1-cache-size=32"
152 CXXFLAGS="-x -y -z=2"
153 -LDFLAGS="-l -m -n=3"
154 +LDFLAGS="-l -m -n=3 -Wl,--remove-me"
155 ftend() {
156 local ret=$?
157 local msg="Failed; flags are:"