ld: Add additional checking for warnings/errors in testsuite
[deliverable/binutils-gdb.git] / ld / testsuite / ld-plugin / lto.exp
1 # Expect script for ld-plugin LTO tests
2 # Copyright (C) 2011-2017 Free Software Foundation, Inc.
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20
21 # Check to see if the C and C++ compilers work
22 if { [which $CC] == 0 || [which $CXX] == 0 } {
23 return
24 }
25
26 # These tests require plugin and LTO.
27 if { ![check_plugin_api_available]
28 || ![check_lto_available] } {
29 return
30 }
31
32 global CFLAGS
33 global CXXFLAGS
34 set saved_CFLAGS "$CFLAGS"
35 set saved_CXXFLAGS "$CXXFLAGS"
36 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS
37 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS
38
39 proc restore_notify { } {
40 global saved_CFLAGS
41 global saved_CXXFLAGS
42 set CFLAGS "$saved_CFLAGS"
43 set CXXFLAGS "$saved_CXXFLAGS"
44 }
45
46 set plugin_names {
47 liblto_plugin.so
48 liblto_plugin-0.dll
49 cyglto_plugin-0.dll
50 }
51 set plug_opt ""
52 foreach plug $plugin_names {
53 set plug_so [run_host_cmd $CC "--print-prog-name $plug"]
54 if { $plug_so eq $plug } then {
55 set plug_so [run_host_cmd $CC "--print-file-name $plug"]
56 }
57 if { $plug_so ne $plug } then {
58 set plug_opt "--plugin $plug_so"
59 break
60 }
61 }
62 set lto_fat ""
63 set lto_no_fat ""
64 if { [check_lto_fat_available] } {
65 set lto_fat "-ffat-lto-objects"
66 set lto_no_fat "-fno-fat-lto-objects"
67 }
68
69 # Simple LTO tests and generate input files for complex LTO tests.
70 set lto_link_tests [list \
71 [list "LTO 1" \
72 "-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" \
73 {lto-1a.c lto-1b.c} {} "lto-1.exe"] \
74 [list "Compile 2" \
75 "" "-O2 -flto -fuse-linker-plugin" \
76 {lto-2.c} {} ""] \
77 [list "LTO 2" \
78 "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" "" \
79 {dummy.c} {} "lto-2.exe"] \
80 [list "Compile 3a" \
81 "" "-flto" \
82 {lto-3a.c} {} ""] \
83 [list "Compile 3c" \
84 "" "-O2" \
85 {lto-3c.c} {} ""] \
86 [list "Build liblto-3.a" \
87 "" "-flto $lto_fat" \
88 {lto-3b.c} {} "liblto-3.a"] \
89 [list "Compile 5a" \
90 "" "-flto $lto_fat" \
91 {lto-5a.c} {} ""] \
92 [list "Compile 5b" \
93 "" "-flto $lto_fat" \
94 {lto-5b.c} {} ""] \
95 [list "LTO 6" \
96 "-O2 -flto -fuse-linker-plugin" "" \
97 {lto-6.c} {} "lto-6.exe" "c"] \
98 [list "Compile PR ld/12365" \
99 "" "-flto -O2 $lto_fat" \
100 {pr12365a.c pr12365b.c pr12365c.c} {} ""] \
101 [list "Compile 9" \
102 "" "-O2 -finline -flto" \
103 {lto-9.cc} {} "" "c++"] \
104 [list "Compile 11a" \
105 "" "-O -flto" \
106 {lto-11a.c} {} ""] \
107 [list "Compile 11b" \
108 "" "-O -flto" \
109 {lto-11b.c} {} ""] \
110 [list "Compile 11c" \
111 "" "-O" \
112 {lto-11c.c} {} ""] \
113 [list "Build liblto-12.a" \
114 "$plug_opt" "-O2 -flto" \
115 {lto-12c.c} {} "liblto-12.a"] \
116 [list "Compile 12" \
117 "" "-O2 -flto" \
118 {lto-12a.c lto-12b.c} {} ""] \
119 [list "Compile 13" \
120 "" "-O2 -flto" \
121 {lto-13a.c lto-13b.c} {} ""] \
122 [list "Build liblto-13.a" \
123 "" "-O2" \
124 {lto-13c.c} {} "liblto-13.a"] \
125 [list "Compile 14a" \
126 "" "-flto" \
127 {lto-14a.c lto-14b.c} {} ""] \
128 [list "Build liblto-14.a" \
129 "$plug_opt" "-flto" \
130 {lto-14c.c} {} "liblto-14.a"] \
131 [list "Compile 15a" \
132 "" "-flto" \
133 {lto-15a.c} {} ""] \
134 [list "Build liblto-15.a" \
135 "$plug_opt" "-flto" \
136 {lto-15b.c} {} "liblto-15.a"] \
137 [list "PR ld/12696" \
138 "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" \
139 {pr12696-1.cc} {} "pr12696-1r.o" "c++"] \
140 [list "Compile PR ld/12758" \
141 "" "" \
142 {pr12758a.s} {} ""] \
143 [list "Build libpr12758.a" \
144 "" "-flto -O2 $lto_fat" \
145 {pr12758b.c} {} "libpr12758.a"] \
146 [list "PR ld/12758" \
147 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" "" \
148 {dummy.c} {} "pr12758.exe"] \
149 [list "Compile PR ld/12760" \
150 "" "-g -O0" \
151 {pr12760a.c} {} ""] \
152 [list "Build libpr12760.a" \
153 "" "-flto -O2 $lto_fat" \
154 {pr12760b.c} {} "libpr12760.a"] \
155 [list "PR ld/12760" \
156 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" \
157 {dummy.c} {{warning "pr12760a.c:6: warning: Bad \\.?bar"}} \
158 "pr12760.exe" "c"] \
159 [list "Build libpr13183.a" \
160 "-T" "-flto -O2 $lto_fat" \
161 {pr13183a.c} {} "libpr13183.a"] \
162 [list "Compile PR ld/13183" \
163 "" "-flto -O2" \
164 {pr13183b.c} {} ""] \
165 [list "Compile PR ld/13201" \
166 "" "-flto -O2" \
167 {pr13201.c} {} ""] \
168 [list "PR ld/13287" \
169 "-flto -fuse-linker-plugin -Wl,--as-needed" "-flto" \
170 {pr13287.cc} {} "pr13287.exe" "c++"] \
171 [list "PR ld/15323 (1)" \
172 "" "-O2" \
173 {pr15323a.c} {} "" "c"] \
174 [list "PR ld/15323 (2)" \
175 "-O2 -flto -r -nostdlib" "-O2 -flto" \
176 {pr15323a.c} {} "pr15323a-r.o" "c"] \
177 [list "Compile(1) PR ld/pr16846" \
178 "" "-flto" \
179 {pr16846a.c pr16846b.c} {} ""] \
180 [list "Compile(2) PR ld/pr16846" \
181 "" "" \
182 {pr16846c.c} {} ""] \
183 [list "PR ld/pr16846(1)" \
184 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846b.o tmpdir/pr16846c.o" "" \
185 {dummy.c} {} "pr16846a.exe"] \
186 [list "PR ld/pr16846(2)" \
187 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846c.o tmpdir/pr16846b.o" "" \
188 {dummy.c} {} "pr16846b.exe"] \
189 [list "PR ld/19317 (1)" \
190 "$plug_opt" "-flto $lto_no_fat" \
191 {pr19317.c} {} "libpr19317.a"] \
192 [list "Build pr20276a.o" \
193 "" "-fno-lto" \
194 {pr20276a.c}] \
195 [list "Build pr20276b.o" \
196 "$plug_opt" "-flto $lto_no_fat" \
197 {pr20276b.c}] \
198 [list "Build pr20267a.o" \
199 "" "" \
200 {pr20267a.c}] \
201 [list "Build libpr20267a.a" \
202 "$plug_opt" "-flto $lto_fat" \
203 {pr20267b.c} {} "libpr20267a.a"] \
204 [list "Build libpr20267b.a" \
205 "$plug_opt" "-flto $lto_no_fat" \
206 {pr20267b.c} {} "libpr20267b.a"] \
207 [list "Build pr20321" \
208 "-flto -Wl,-plugin,$plug_so" "-flto" \
209 {pr20321.c} {{warning ".*: duplicated plugin"}} \
210 "pr20321" "c"] \
211 ]
212
213 if { [at_least_gcc_version 4 7] } {
214 set lto_link_tests [concat $lto_link_tests [list \
215 [list "Compile PR ld/12942 (1)" \
216 "" "-flto -O2" \
217 {pr12942a.cc pr12942c.cc} {} "" "c++"] \
218 [list "Compile PR ld/12942 (2)" \
219 "" "-O0" \
220 {pr12942b.cc} {} "" "c++"] \
221 ]]
222 }
223
224 set lto_compile_elf_tests [list \
225 [list "Compile 7" \
226 "" "-flto -O2" \
227 {lto-7a.c lto-7b.c lto-7c.c} {} ""] \
228 [list "Compile 8a" \
229 "" "-O2" \
230 {lto-8a.c} {} ""] \
231 [list "Compile 8b" \
232 "" "-flto -O2" \
233 {lto-8b.c} {} ""] \
234 ]
235
236 # Generate input files for complex LTO tests for ELF.
237 set lto_link_elf_tests [list \
238 [list "Build liblto-7.so" \
239 "-shared" "-O2 -fpic" \
240 {lto-7d.c} {} "liblto-7.so" "c"] \
241 [list "Build liblto-17a.so" \
242 "-shared -O2 -fpic -flto -fuse-linker-plugin" "-O2 -fpic -flto" \
243 {lto-17a.c} {{"nm" {} "lto-17a.d"}} "liblto-17a.so" "c"] \
244 [list "Build liblto-17b.so 1" \
245 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
246 {lto-17b.c} {{"nm" {} "lto-17b-1.d"}} "liblto-17b.so"] \
247 [list "Build liblto-17b.so 2" \
248 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
249 {lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"] \
250 [list "PR ld/12982" \
251 "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
252 {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
253 [list "PR ld/12975" \
254 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \
255 {pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"] \
256 [list "PR ld/13229" \
257 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -finline -fno-early-inlining -flto" \
258 {pr13229.cc} {{"readelf" {-s --wide} "pr13229.d"}} "pr13229.so" "c++"] \
259 [list "PR ld/13244" \
260 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \
261 {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \
262 [list "Build libpr15146a.a" \
263 "$plug_opt" "-flto -O2" \
264 {pr15146a.c} {} "lib15146a.a"] \
265 [list "Build pr15146b.so" \
266 "-shared" "-O2 -fpic" \
267 {pr15146b.c} {} "pr15146b.so" "c"] \
268 [list "Build pr15146c.so" \
269 "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic" \
270 {pr15146c.c} {} "pr15146c.so" "c"] \
271 [list "PR ld/15146 (1)" \
272 "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \
273 {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"] \
274 [list "Build libpr15146d.a" \
275 "$plug_opt" "-flto -O2" \
276 {pr15146d.c} {} "lib15146d.a"] \
277 [list "Build libpr16746a.a" \
278 "" "" \
279 {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
280 [list "Build libpr16746b.a" \
281 "$plug_opt" "-O2 -flto" \
282 {pr16746c.c pr16746d.c} {} "lib15146b.a"] \
283 [list "PR ld/16746 (1)" \
284 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \
285 {dummy.c} {} "pr16746a.exe"] \
286 [list "PR ld/16746 (2)" \
287 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto" \
288 {dummy.c} {} "pr16746b.exe"] \
289 [list "PR ld/14918" \
290 "-flto" "-flto" \
291 {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \
292 ]
293
294 # Check final symbols in executables.
295 set lto_link_symbol_tests [list \
296 [list "LTO 3 symbol" \
297 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
298 {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"] \
299 [list "LTO 5 symbol" \
300 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
301 {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"] \
302 [list "LTO 9 symbol" \
303 "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" \
304 {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"] \
305 [list "LTO 16a symbol" \
306 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" "-flto" \
307 {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"] \
308 [list "LTO 16b symbol" \
309 "-O2 -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" "-flto" \
310 {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"] \
311 [list "PR ld/13183" \
312 "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" \
313 {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"] \
314 ]
315
316 # LTO run-time tests.
317 set lto_run_tests [list \
318 [list "LTO 3a" \
319 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
320 {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"] \
321 [list "LTO 3b" \
322 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" \
323 {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"] \
324 [list "LTO 3c" \
325 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o -Wl,--whole-archive tmpdir/liblto-3.a -Wl,--no-whole-archive tmpdir/liblto-3.a" "" \
326 {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
327 [list "LTO 5" \
328 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
329 {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
330 [list "LTO 11" \
331 "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
332 {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
333 [list "LTO 12a" \
334 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" \
335 {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"] \
336 [list "LTO 12b" \
337 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" \
338 {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"] \
339 [list "LTO 13" \
340 "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" \
341 {dummy.c} "lto-13.exe" "lto-13.out" "" "c"] \
342 [list "LTO 14" \
343 "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" \
344 {dummy.c} "lto-14.exe" "lto-14.out" "" "c"] \
345 [list "LTO 15" \
346 "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" \
347 {dummy.c} "lto-15.exe" "lto-15.out" "" "c"] \
348 [list "PR ld/13066" \
349 "-O2 -flto -fuse-linker-plugin" "" \
350 {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"] \
351 [list "PR ld/13201" \
352 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" \
353 {dummy.c} "pr13201.exe" "pr13201.out" "" "c"] \
354 [list "PR ld/15323 (3)" \
355 "-O2 -flto -fuse-linker-plugin tmpdir/pr15323a.o" "" \
356 {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"] \
357 [list "PR ld/15323 (4)" \
358 "-O2 -flto tmpdir/pr15323a-r.o" "" \
359 {dummy.c} "pr15323a.exe" "pr15323.out" "-flto -O2" "c"] \
360 [list "PR ld/19317 (3)" \
361 "-O2 -flto tmpdir/pr19317-r.o" "" \
362 {dummy.c} "pr19317.exe" "pr19317.out" "-flto -O2" "c"] \
363 [list "Run pr20276" \
364 "-O2 -flto tmpdir/pr20276a.o tmpdir/pr20276b.o" "" \
365 {dummy.c} "pr20276" "pass.out" "-flto -O2" "c"] \
366 [list "Run pr20267a" \
367 "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267a.a" "" \
368 {dummy.c} "pr20267a" "pass.out" "-flto -O2" "c"] \
369 [list "Run pr20267b" \
370 "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \
371 {dummy.c} "pr20267b" "pass.out" "-flto -O2" "c"] \
372 ]
373
374 if { [at_least_gcc_version 4 7] } {
375 set lto_run_tests [concat $lto_run_tests [list \
376 [list "PR ld/12942 (1)" \
377 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" \
378 {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"] \
379 [list "PR ld/12942 (2)" \
380 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" \
381 {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"] \
382 ]]
383 }
384
385 # LTO run-time tests for ELF which require shared library support.
386 set lto_run_elf_shared_tests [list \
387 [list "LTO 7" \
388 "-O2 -flto -fuse-linker-plugin tmpdir/lto-7b.o tmpdir/lto-7c.o tmpdir/lto-7a.o -Wl,--no-as-needed tmpdir/liblto-7.so" "" \
389 {dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \
390 ]
391
392 # LTO run-time tests for ELF
393 set lto_run_elf_tests [list \
394 [list "LTO 8" \
395 "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \
396 {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \
397 [list "LTO TLS IE" \
398 "-O2 -flto -fuse-linker-plugin" "" \
399 {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \
400 ]
401
402 run_cc_link_tests $lto_link_tests
403
404 # These compilation tests generate intermediate object files which will be used
405 # by some elf tests besides shared libs tests. So, always compile them.
406 run_cc_link_tests $lto_compile_elf_tests
407
408 # Restrict these to ELF targets that support shared libs and PIC.
409 if { [is_elf_format] && [check_lto_shared_available] } {
410 run_cc_link_tests $lto_link_elf_tests
411 set testname "PR ld/15146 (2)"
412 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"]
413 if { [ regexp "undefined reference to symbol '\\.?xxx'" $exec_output ] } {
414 pass $testname
415 } {
416 fail $testname
417 }
418 set testname "PR ld/16746 (3)"
419 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
420 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
421 pass $testname
422 } {
423 fail $testname
424 }
425 set testname "PR ld/16746 (4)"
426 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
427 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
428 pass $testname
429 } {
430 fail $testname
431 }
432 }
433
434 set testname "Build liblto-11.a"
435 remote_file host delete "tmpdir/liblto-11.a"
436 set catch_output [run_host_cmd "$ar" "rc $plug_opt tmpdir/liblto-11.a tmpdir/lto-11a.o tmpdir/lto-11b.o tmpdir/lto-11c.o"]
437 if {![string match "" $catch_output]} {
438 unresolved $testname
439 restore_notify
440 return
441 }
442
443 if { [at_least_gcc_version 4 7] } {
444 # Check expected LTO linker errors.
445 # Since the asm symbol name hack in pr12365b.c doesn't work on all
446 # targets, run PR ld/12365 tests only for known targets.
447 if { ([istarget "i?86-*-elf*"]
448 || (([istarget "i?86-*-linux*"] || [istarget "i?86-*-gnu*"])
449 && ![istarget "*-*-*aout*"]
450 && ![istarget "*-*-*oldld*"])
451 || [istarget "i?86-*-nacl*"]
452 || [istarget "x86_64-*-nacl*"]
453 || [istarget "x86_64-*-linux*"]
454 || [istarget "amd64-*-linux*"]) } {
455 set testname "PR ld/12365"
456 set exec_output [run_host_cmd "$CC" "-O2 -flto -flto-partition=none -fuse-linker-plugin -o tmpdir/pr12365 tmpdir/pr12365a.o tmpdir/pr12365b.o tmpdir/pr12365c.o"]
457 if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
458 # Linker should catch the reference to undefined `my_bcopy'
459 # error caused by a GCC bug.
460 pass $testname
461 } elseif { [ string match "" $exec_output ] } {
462 global READELF
463 set exec_output [run_host_cmd "$READELF" "-s -W tmpdir/pr12365"]
464 if { [ regexp "my_bcopy" $exec_output ] } {
465 # Verify that there is no `my_bcopy' symbol in executable.
466 fail $testname
467 } {
468 pass $testname
469 }
470 } {
471 fail $testname
472 }
473 }
474 set testname "PR ld/12942 (3)"
475 set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
476 if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
477 pass $testname
478 } {
479 fail $testname
480 }
481 }
482
483 # Run "ld -r" to generate inputs for complex LTO tests.
484 run_dump_test "lto-3r"
485 remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
486 run_dump_test "lto-5r"
487 remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
488
489 run_cc_link_tests $lto_link_symbol_tests
490
491 run_ld_link_tests [list \
492 [list "PR ld/19317 (2)" \
493 "-r tmpdir/pr19317.o" "" "" \
494 {dummy.s} {} "pr19317-r.o"] \
495 ]
496
497 run_ld_link_exec_tests $lto_run_tests
498
499 if { [is_elf_format] } {
500 run_ld_link_exec_tests $lto_run_elf_tests
501 }
502
503 if { [is_elf_format] && [check_lto_shared_available] } {
504 run_ld_link_exec_tests $lto_run_elf_shared_tests
505 }
506
507 proc pr20103 {cflags libs} {
508 global CC
509
510 set testname "PR ld/20103 ($cflags $libs)"
511 set exec_output [run_host_cmd "$CC" "$cflags $libs"]
512 if { [ regexp "undefined reference to `\\.?dead'" $exec_output ] } {
513 pass "$testname (1)"
514 } {
515 fail "$testname (1)"
516 }
517 if { [ regexp "plugin needed to handle lto object" $exec_output ] } {
518 fail "$testname (2)"
519 } {
520 pass "$testname (2)"
521 }
522 }
523
524 if { [check_lto_fat_available] } {
525 run_cc_link_tests [list \
526 [list \
527 "Build fatpr20103a.a" \
528 "$plug_opt" "-flto -ffat-lto-objects" \
529 {pr20103a.c} {} "fatpr20103a.a"
530 ] \
531 [list \
532 "Build fatpr20103b.a" \
533 "$plug_opt" "-flto -ffat-lto-objects" \
534 {pr20103b.c} {} "fatpr20103b.a"
535 ] \
536 [list \
537 "Build fatpr20103c.a" \
538 "$plug_opt" "-flto -ffat-lto-objects" \
539 {pr20103c.c} {} "fatpr20103c.a" \
540 ] \
541 [list \
542 "Build thinpr20103a.a" \
543 "$plug_opt" "-flto -fno-fat-lto-objects" \
544 {pr20103a.c} {} "thinpr20103a.a"
545 ] \
546 [list \
547 "Build thinpr20103b.a" \
548 "$plug_opt" "-flto -fno-fat-lto-objects" \
549 {pr20103b.c} {} "thinpr20103b.a"
550 ] \
551 [list \
552 "Build thinpr20103c.a" \
553 "$plug_opt" "-flto -fno-fat-lto-objects" \
554 {pr20103c.c} {} "thinpr20103c.a" \
555 ] \
556 [list \
557 "Build pr20103a" \
558 "-O2 -flto -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
559 "-O2 -flto" \
560 {dummy.c} {} "pr20103a" \
561 ] \
562 [list \
563 "Build pr20103b" \
564 "-O2 -flto -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
565 "-O2 -flto" \
566 {dummy.c} {} "pr20103b" \
567 ] \
568 [list \
569 "Build pr20103c" \
570 "-O2 -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
571 "-O2" \
572 {dummy.c} {} "pr20103c" \
573 ] \
574 ]
575 pr20103 "-O2 -flto" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
576 pr20103 "-O2 -flto" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
577 pr20103 "-O2" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
578
579 if { [at_least_gcc_version 4 9] } {
580 run_cc_link_tests [list \
581 [list \
582 "Build pr20103d" \
583 "-O2 -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
584 "-O2" \
585 {dummy.c} {} "pr20103d" \
586 ] \
587 ]
588 pr20103 "-O2" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
589 }
590 }
591
592 restore_notify
This page took 0.050807 seconds and 4 git commands to generate.