Gentoo Archives: gentoo-dev

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