1 # Expect script for ld-plugin LTO tests
2 # Copyright (C) 2011-2020 Free Software Foundation, Inc.
4 # This file is part of the GNU Binutils.
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.
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.
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,
21 # Check to see if the C and C++ compilers work
22 if { ![check_compiler_available] || [which $CXX] == 0 } {
26 # These tests require plugin and LTO.
27 if { ![check_plugin_api_available]
28 || ![check_lto_available] } {
32 set saved_CFLAGS "$CFLAGS"
33 set saved_CXXFLAGS "$CXXFLAGS"
34 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS
35 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS
37 proc restore_notify { } {
40 set CFLAGS "$saved_CFLAGS"
41 set CXXFLAGS "$saved_CXXFLAGS"
50 foreach plug $plugin_names {
51 set plug_so [run_host_cmd $CC "--print-prog-name $plug"]
52 if { $plug_so eq $plug } then {
53 set plug_so [run_host_cmd $CC "--print-file-name $plug"]
55 if { $plug_so ne $plug } then {
56 set plug_opt "--plugin $plug_so"
62 if { [check_lto_fat_available] } {
63 set lto_fat "-ffat-lto-objects"
64 set lto_no_fat "-fno-fat-lto-objects"
68 # Simple LTO tests and generate input files for complex LTO tests.
69 set lto_link_tests [list \
71 "-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" \
72 {lto-1a.c lto-1b.c} {} "lto-1.exe"] \
74 "" "-O2 -flto -fuse-linker-plugin $NOSANTIZE_CFLAGS" \
77 "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" \
79 {dummy.c} {} "lto-2.exe"] \
86 [list "Build liblto-3.a" \
88 {lto-3b.c} {} "liblto-3.a"] \
95 [list "Compile PR ld/12365" \
96 "" "-flto -O2 $lto_fat" \
97 {pr12365a.c pr12365b.c pr12365c.c} {} ""] \
99 "" "-O2 -finline -flto" \
100 {lto-9.cc} {} "" "c++"] \
101 [list "Compile 11a" \
104 [list "Compile 11b" \
107 [list "Compile 11c" \
110 [list "Build liblto-12.a" \
111 "$plug_opt" "-O2 -flto" \
112 {lto-12c.c} {} "liblto-12.a"] \
115 {lto-12a.c lto-12b.c} {} ""] \
118 {lto-13a.c lto-13b.c} {} ""] \
119 [list "Build liblto-13.a" \
121 {lto-13c.c} {} "liblto-13.a"] \
122 [list "Compile 14a" \
124 {lto-14a.c lto-14b.c} {} ""] \
125 [list "Build liblto-14.a" \
126 "$plug_opt" "-flto" \
127 {lto-14c.c} {} "liblto-14.a"] \
128 [list "Compile 15a" \
131 [list "Build liblto-15.a" \
132 "$plug_opt" "-flto" \
133 {lto-15b.c} {} "liblto-15.a"] \
134 [list "PR ld/12696" \
135 "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" \
136 {pr12696-1.cc} {} "pr12696-1r.o" "c++"] \
137 [list "Compile PR ld/12758" \
139 {pr12758a.s} {} ""] \
140 [list "Build libpr12758.a" \
141 "" "-flto -O2 $lto_fat $NOSANTIZE_CFLAGS" \
142 {pr12758b.c} {} "libpr12758.a"] \
143 [list "PR ld/12758" \
144 "$NOPIE_LDFLAGS -O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" \
145 "$NOSANTIZE_CFLAGS" \
146 {dummy.c} {} "pr12758.exe"] \
147 [list "Build libpr13183.a" \
148 "-T" "-flto -O2 $lto_fat" \
149 {pr13183a.c} {} "libpr13183.a"] \
150 [list "Compile PR ld/13183" \
152 {pr13183b.c} {} ""] \
153 [list "Compile PR ld/13201" \
156 [list "PR ld/13287" \
157 "-flto -fuse-linker-plugin -Wl,--as-needed" "-flto" \
158 {pr13287.cc} {} "pr13287.exe" "c++"] \
159 [list "PR ld/15323 (1)" \
161 {pr15323a.c} {} "" "c"] \
162 [list "PR ld/15323 (2)" \
163 "-O2 -flto -r -nostdlib" "-O2 -flto" \
164 {pr15323a.c} {} "pr15323a-r.o" "c"] \
165 [list "Compile(1) PR ld/pr16846" \
167 {pr16846a.c pr16846b.c} {} ""] \
168 [list "Compile(2) PR ld/pr16846" \
170 {pr16846c.c} {} ""] \
171 [list "PR ld/pr16846(1)" \
172 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846b.o tmpdir/pr16846c.o" "" \
173 {dummy.c} {} "pr16846a.exe"] \
174 [list "PR ld/pr16846(2)" \
175 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846c.o tmpdir/pr16846b.o" "" \
176 {dummy.c} {} "pr16846b.exe"] \
177 [list "PR ld/19317 (1)" \
178 "$plug_opt" "-flto $lto_no_fat" \
179 {pr19317.c} {} "libpr19317.a"] \
180 [list "Build pr20276a.o" \
181 "" "-fno-lto -fcommon" \
183 [list "Build pr20276b.o" \
184 "$plug_opt" "-flto $lto_no_fat -fcommon" \
186 [list "Build pr20267a.o" \
189 [list "Build libpr20267a.a" \
190 "$plug_opt" "-flto $lto_fat -fcommon" \
191 {pr20267b.c} {} "libpr20267a.a"] \
192 [list "Build libpr20267b.a" \
193 "$plug_opt" "-flto $lto_no_fat -fcommon" \
194 {pr20267b.c} {} "libpr20267b.a"] \
195 [list "Build pr20321" \
196 "-flto -Wl,-plugin,$plug_so" "-flto" \
197 {pr20321.c} {{warning ".*: duplicated plugin"}} \
199 [list "Build pr22502a.o" \
202 [list "Build pr22502b.o" \
203 "$plug_opt" "-flto $lto_no_fat" \
205 [list "Build pr22751.a" \
206 "$plug_opt" "-flto $lto_no_fat $INT128_CFLAGS" \
207 {pr22751.c} {} "pr22751.a"] \
208 [list "Build pr24406-2b.o" \
211 [list "Build pr26163a.o" \
214 [list "Build pr26262b.o" \
216 {pr26262b.c} {} "" "c"] \
217 [list "Build pr26262c.o" \
219 {pr26262c.c} {} "" "c"] \
220 [list "Build pr26267a.o" \
221 "" "-O2 -flto $lto_no_fat" \
222 {pr26267a.c} {} "" "c"] \
223 [list "Build pr26267b.o" \
225 {pr26267b.c} {} "" "c"] \
226 [list "Build pr26267c.o" \
228 {pr26267c.c} {} "" "c"] \
229 [list "Build pr26267a" \
231 {pr26267a.c} {} "" "c"] \
232 [list "Build pr26267a" \
233 "-flto tmpdir/pr26267a.o tmpdir/pr26267b.o tmpdir/pr26267c.o" \
234 "-flto $lto_no_fat" \
236 {{error_output "pr26267.err"}} \
238 [list "Build pr26267b" \
239 "-flto tmpdir/pr26267b.o tmpdir/pr26267c.o tmpdir/pr26267a.o" \
240 "-flto $lto_no_fat" \
242 {{error_output "pr26267.err"}} \
244 [list "Build pr26389.o" \
245 "$plug_opt" "-flto $lto_no_fat -fcommon" \
247 [list [list "nm" "$plug_opt" "pr26389.d"]]] \
250 if { [at_least_gcc_version 10 0] } {
251 set lto_link_tests [concat $lto_link_tests [list \
254 "-flto -fno-common $lto_no_fat" \
256 [list [list "nm" "$plug_opt" "pr25355.d"]]] \
260 if { [at_least_gcc_version 4 7] } {
261 set lto_link_tests [concat $lto_link_tests [list \
262 [list "Compile PR ld/12942 (1)" \
264 {pr12942a.cc pr12942c.cc} {} "" "c++"] \
265 [list "Compile PR ld/12942 (2)" \
267 {pr12942b.cc} {} "" "c++"] \
271 set lto_compile_elf_tests [list \
274 {lto-7a.c lto-7b.c lto-7c.c} {} ""] \
281 [list "PR ld/23309" \
282 "-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections -Wl,--gc-sections,-u,KeepMe" \
283 "-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections" \
284 {pr23309.c} {{"nm" {} "pr23309.d"}} "pr23309.exe" "c"] \
287 # Generate input files for complex LTO tests for ELF.
288 set lto_link_elf_tests [list \
290 "-O2 -flto -fuse-linker-plugin" "" \
291 {lto-6.c} {} "lto-6.exe" "c"] \
292 [list "Build liblto-7.so" \
293 "-shared" "-O2 -fpic" \
294 {lto-7d.c} {} "liblto-7.so" "c"] \
295 [list "Build liblto-17a.so" \
296 "-shared -O2 -fpic -flto -fuse-linker-plugin" "-O2 -fpic -flto" \
297 {lto-17a.c} {{"nm" {} "lto-17a.d"}} "liblto-17a.so" "c"] \
298 [list "Build liblto-17b.so 1" \
299 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
300 {lto-17b.c} {{"nm" {} "lto-17b-1.d"}} "liblto-17b.so"] \
301 [list "Build liblto-17b.so 2" \
302 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
303 {lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"] \
304 [list "Compile PR ld/12760" \
306 {pr12760a.c} {} ""] \
307 [list "Build libpr12760.a" \
308 "" "-flto -O2 $lto_fat" \
309 {pr12760b.c} {} "libpr12760.a"] \
310 [list "PR ld/12760" \
311 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" \
312 {dummy.c} {{warning "pr12760a.c:6: warning: Bad \\.?bar"}} \
314 [list "PR ld/12975" \
315 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \
316 {pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"] \
317 [list "PR ld/13229" \
318 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -finline -fno-early-inlining -flto" \
319 {pr13229.cc} {{"readelf" {-s --wide} "pr13229.d"}} "pr13229.so" "c++"] \
320 [list "PR ld/13244" \
321 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \
322 {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \
323 [list "Build libpr15146a.a" \
324 "$plug_opt" "-flto -O2" \
325 {pr15146a.c} {} "lib15146a.a"] \
326 [list "Build pr15146b.so" \
327 "-shared" "-O2 -fpic" \
328 {pr15146b.c} {} "pr15146b.so" "c"] \
329 [list "Build pr15146c.so" \
330 "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic $no_lto" \
331 {pr15146c.c} {} "pr15146c.so" "c"] \
332 [list "PR ld/15146 (1)" \
333 "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \
334 {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"] \
335 [list "Build libpr15146d.a" \
336 "$plug_opt" "-flto -O2" \
337 {pr15146d.c} {} "lib15146d.a"] \
338 [list "Build libpr16746a.a" \
340 {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
341 [list "Build libpr16746b.a" \
342 "$plug_opt" "-O2 -flto" \
343 {pr16746c.c pr16746d.c} {} "lib15146b.a"] \
344 [list "PR ld/16746 (1)" \
345 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \
346 {dummy.c} {} "pr16746a.exe"] \
347 [list "PR ld/16746 (2)" \
348 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto" \
349 {dummy.c} {} "pr16746b.exe"] \
350 [list "Build pr21382a.o" \
352 {pr21382a.c} {} "" "c"] \
353 [list "Build pr21382.so" \
354 "-shared" "-O2 -fpic" \
355 {pr21382b.c} {} "pr21382.so" "c"] \
356 [list {Build pr22220lib.so} \
357 {-shared -Wl,--version-script=pr22220lib.ver} {-fPIC} \
358 {pr22220lib.cc} {} {pr22220lib.so} {c++}] \
359 [list {Build pr22220main.o} \
361 {pr22220main.cc} {} {} {c++}] \
362 [list "Build libpr23818.so" \
363 "-shared -flto -g -Wl,-version-script,pr23818.t" \
364 "-g -flto $lto_fat" \
365 {pr23818a.c pr23818b.c} \
366 {{"readelf" {-s --wide} "pr23818.d"}} \
368 [list "Build libpr23958.so" \
369 "-shared -flto -Wl,-version-script,pr23958.t" \
370 "-g -flto $lto_fat" \
374 [list "Build pr24486a.o" \
375 "$plug_opt" "-flto -O2" \
376 {pr24486a.c} {} "" "c"] \
377 [list "Build pr24486b.so" \
378 "-shared" "-O2 -fpic" \
379 {pr24486b.c} {} "pr24486b.so" "c"] \
380 [list "Build pr24486c.so" \
381 "-shared -Wl,--no-as-needed tmpdir/pr24486b.so" "-O2 -fpic" \
382 {pr24486c.c} {} "pr24486c.so" "c"] \
383 [list "PR ld/24486" \
384 "-O2 -flto tmpdir/pr24486a.o tmpdir/pr24486c.so -Wl,--as-needed tmpdir/pr24486b.so" "" \
385 {dummy.c} {} "pr24486.exe"] \
386 [list "Build pr25593a-1.o" \
387 "$plug_opt" "-flto -O2" \
388 {pr25593a-1.c} {} "" "c"] \
389 [list "Build pr25593a-2.o" \
391 {pr25593a-2.c} {} "" "c"] \
392 [list "Build pr25593b.o" \
394 {pr25593b.c} {} "" "c"] \
395 [list "Build pr25593c.so" \
396 "-shared" "-O2 -fpic" \
397 {pr25593c.c} {} "pr25593c.so" "c"] \
398 [list "Build pr25593d.so" \
399 "-shared" "-O2 -fpic" \
400 {pr25593d.c} {} "pr25593d.so" "c"] \
401 [list "Build pr25593e.so" \
402 "-shared" "-O2 -fpic" \
403 {pr25593e.c} {} "pr25593e.so" "c"] \
404 [list "PR ld/r25593 (LTO)" \
405 "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-1.o tmpdir/pr25593b.o \
406 tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
407 {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593a.exe"] \
408 [list "PR ld/r25593" \
409 "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-2.o tmpdir/pr25593b.o \
410 tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
411 {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593b.exe"] \
412 [list "Build pr25618a.o" \
413 "$plug_opt" "-O2 -flto -fpic" \
414 {pr25618a.cc} {} "" "c++"] \
415 [list "Build pr25618.a" \
416 "$plug_opt" "-O2 -flto -fpic" \
417 {pr25618b.cc} {} "pr25618.a" "c++"] \
418 [list "Build pr25618.so" \
419 "-shared -Wl,--exclude-libs,ALL tmpdir/pr25618a.o tmpdir/pr25618.a" \
421 {dummy.c} {{readelf {--dyn-syms --wide} pr25618.d}} "pr25618.so" "c++"] \
424 # PR 14918 checks that libgcc is not spuriously included in a shared link of
425 # an empty program. The ARM crt1.o startup code however calls __libc_csu_init
426 # in /usr/lib/libc_nonshared.a(elf-init.oS). This in turn needs
427 # __aeabi_unwind_cpp_pr0@@GCC_3.5 which is provided by libgcc_s.so.1, so the
428 # test fails. Hence this code to skip the test.
429 if { ! [istarget "arm*-*-*"] } {
430 set lto_link_elf_tests [concat $lto_link_elf_tests [list \
431 [list "PR ld/14918" \
433 {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \
437 # PR 12982 checks that an executable stack is not created by default
438 # when using the LTO plugin. The HPPA target however requires an
439 # executable stack for syscall restarts and signal returns, so we
440 # skip this test for that target.
441 if { ! [istarget "hppa*-*-*"] } {
442 set lto_link_elf_tests [concat $lto_link_elf_tests [list \
443 [list "PR ld/12982" \
444 "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
445 {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
449 # Check final symbols in executables.
450 set lto_link_symbol_tests [list \
451 [list "LTO 3 symbol" \
452 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
453 {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"] \
454 [list "LTO 5 symbol" \
455 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
456 {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"] \
457 [list "LTO 9 symbol" \
458 "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" \
459 {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"] \
460 [list "LTO 16a symbol" \
461 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" "-flto" \
462 {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"] \
463 [list "LTO 16b symbol" \
464 "-O2 -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" "-flto" \
465 {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"] \
466 [list "PR ld/13183" \
467 "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" \
468 {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"] \
471 # LTO run-time tests.
472 set lto_run_tests [list \
474 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
475 {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"] \
477 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" \
478 {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"] \
480 "-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" "" \
481 {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
483 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
484 {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
486 "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
487 {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
489 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" \
490 {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"] \
492 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" \
493 {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"] \
495 "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" \
496 {dummy.c} "lto-13.exe" "lto-13.out" "" "c"] \
498 "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" \
499 {dummy.c} "lto-14.exe" "lto-14.out" "" "c"] \
501 "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" \
502 {dummy.c} "lto-15.exe" "lto-15.out" "" "c"] \
503 [list "PR ld/13066" \
504 "-O2 -flto -fuse-linker-plugin" "" \
505 {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"] \
506 [list "PR ld/13201" \
507 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" \
508 {dummy.c} "pr13201.exe" "pr13201.out" "" "c"] \
509 [list "PR ld/15323 (3)" \
510 "-O2 -flto -fuse-linker-plugin tmpdir/pr15323a.o" "" \
511 {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"] \
512 [list "PR ld/15323 (4)" \
513 "-O2 -flto tmpdir/pr15323a-r.o" "" \
514 {dummy.c} "pr15323a.exe" "pr15323.out" "-flto -O2" "c"] \
515 [list "PR ld/19317 (3)" \
516 "-O2 -flto tmpdir/pr19317-r.o" "" \
517 {dummy.c} "pr19317.exe" "pr19317.out" "-flto -O2" "c"] \
518 [list "Run pr20276" \
519 "-O2 -flto tmpdir/pr20276a.o tmpdir/pr20276b.o" "" \
520 {dummy.c} "pr20276" "pass.out" "-flto -O2" "c"] \
521 [list "Run pr20267a" \
522 "-O2 -flto -fcommon tmpdir/pr20267a.o tmpdir/libpr20267a.a" "" \
523 {dummy.c} "pr20267a" "pass.out" "-flto -O2 -fcommon" "c"] \
524 [list "Run pr20267b" \
525 "-O2 -flto -fcommon tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \
526 {dummy.c} "pr20267b" "pass.out" "-flto -O2 -fcommon" "c"] \
527 [list "Run pr22502" \
528 "-O2 -flto tmpdir/pr22502a.o tmpdir/pr22502b.o" "" \
529 {dummy.c} "pr20267" "pass.out" "-flto -O2 -fcommon" "c"] \
530 [list "Run pr22751" \
532 {dummy.c} "pr22751" "pass.out" "-flto -O2" "c" "" \
533 "-Wl,--whole-archive tmpdir/pr22751.a -Wl,--no-whole-archive"] \
534 [list "Run pr24406-1" \
536 {pr24406-1.c} "pr24406-1" "pass.out" "-flto -O2" "c" "" \
538 [list "Run pr24406-2" \
540 {pr24406-2a.c} "pr24406-2" "pass.out" \
542 "tmpdir/pr24406-2b.o -Wl,--wrap=cook"] \
543 [list "Run pr26163" \
545 {pr26163b.c} "pr24406-2" "pass.out" \
547 "tmpdir/pr26163a.o -Wl,--defsym,g=real_g"] \
548 [list "Run pr26262a" \
550 {pr26262a.c} "pr26262a" "pass.out" \
552 "tmpdir/pr26262b.o tmpdir/pr26262c.o"] \
553 [list "Run pr26262b" \
554 "-flto -O2 tmpdir/pr26262b.o tmpdir/pr26262c.o" "" \
555 {pr26262a.c} "pr26262b" "pass.out" \
560 if { [at_least_gcc_version 4 7] } {
561 set lto_run_tests [concat $lto_run_tests [list \
562 [list "PR ld/12942 (1)" \
563 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" \
564 {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"] \
565 [list "PR ld/12942 (2)" \
566 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" \
567 {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"] \
571 # LTO run-time tests for ELF which require shared library support.
572 set lto_run_elf_shared_tests [list \
574 "-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" "" \
575 {dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \
576 [list "Run pr21382" \
577 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr21382a.o tmpdir/pr21382.so" "" \
578 {dummy.c} "pr21382.exe" "pass.out" "" "c"] \
580 {-flto -fuse-linker-plugin tmpdir/pr22220main.o tmpdir/pr22220lib.so} {} \
581 {dummy.c} {pr22220a.exe} {pass.out} {} {c++}] \
583 {-flto -fuse-linker-plugin -Wl,--no-as-needed tmpdir/pr22220lib.so tmpdir/pr22220main.o} {} \
584 {dummy.c} {pr22220b.exe} {pass.out} {} {c++}] \
587 # LTO run-time tests for ELF
588 set lto_run_elf_tests [list \
590 "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \
591 {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \
593 "-O2 -flto -fuse-linker-plugin" "" \
594 {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \
597 run_cc_link_tests $lto_link_tests
599 # These compilation tests generate intermediate object files which will be used
600 # by some elf tests besides shared libs tests. So, always compile them.
601 run_cc_link_tests $lto_compile_elf_tests
603 # Restrict these to ELF targets that support shared libs and PIC.
604 if { [is_elf_format] && [check_lto_shared_available] } {
605 run_cc_link_tests $lto_link_elf_tests
606 set testname "PR ld/15146 (2)"
607 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"]
608 if { [ regexp "undefined reference to symbol '\\.?xxx'" $exec_output ] } {
613 set testname "PR ld/16746 (3)"
614 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
615 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
620 set testname "PR ld/16746 (4)"
621 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
622 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
629 set testname "Build liblto-11.a"
630 remote_file host delete "tmpdir/liblto-11.a"
631 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"]
632 if {![string match "" $catch_output]} {
638 if { [at_least_gcc_version 4 7] } {
639 # Check expected LTO linker errors.
640 # Since the asm symbol name hack in pr12365b.c doesn't work on all
641 # targets, run PR ld/12365 tests only for known targets.
642 if { ([istarget "i?86-*-elf*"]
643 || [istarget "i?86-*-linux*"]
644 || [istarget "i?86-*-gnu*"]
645 || [istarget "x86_64-*-linux*"]
646 || [istarget "amd64-*-linux*"]) } {
647 set testname "PR ld/12365"
648 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"]
649 set exec_output [prune_warnings $exec_output]
650 if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
651 # Linker should catch the reference to undefined `my_bcopy'
652 # error caused by a GCC bug.
654 } elseif { [ string match "" $exec_output ] } {
656 set exec_output [run_host_cmd "$READELF" "-s -W tmpdir/pr12365"]
657 if { [ regexp "my_bcopy" $exec_output ] } {
658 # Verify that there is no `my_bcopy' symbol in executable.
667 run_cc_link_tests [list \
669 "Build pr22721a.so" \
670 "-shared -nostdlib -nostartfiles -Wl,-version-script,pr22721.t" \
679 "-O2 -fPIC -flto $lto_no_fat" \
683 "Build PR ld/pr22721" \
684 "-O2 -flto -fuse-linker-plugin -nostdlib -nostartfiles \
685 -Wl,-e,_start tmpdir/pr22721b.o tmpdir/pr22721a.so" \
693 set testname "PR ld/12942 (3)"
694 set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
695 if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
701 run_cc_link_tests [list \
705 "-O2 -fPIC -flto $lto_no_fat" \
706 {pr23460a.c pr23460b.c pr23460c.c \
707 pr23460d.c pr23460e.c pr23460f.c} \
710 set exec_output [run_host_cmd "sh" \
711 "-c \"ulimit -n 16; \
713 tmpdir/libpr23460.a \
719 tmpdir/pr23460f.o\""]
720 set exec_output [prune_warnings $exec_output]
721 if [string match "" $exec_output] then {
722 pass "PR binutils/23460"
724 fail "PR binutils/23460"
728 # Run "ld -r" to generate inputs for complex LTO tests.
729 run_dump_test "lto-3r"
730 remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
731 run_dump_test "lto-5r"
732 remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
734 run_cc_link_tests $lto_link_symbol_tests
736 run_ld_link_tests [list \
737 [list "PR ld/19317 (2)" \
738 "-r tmpdir/pr19317.o" "" "" \
739 {dummy.s} {} "pr19317-r.o"] \
742 run_ld_link_exec_tests $lto_run_tests
744 if { [is_elf_format] } {
745 run_ld_link_exec_tests $lto_run_elf_tests
747 # Note - it is not guaranteed that the ordering of symbols in the dynamic
748 # symbol table will match the ordering of the symbols specified by the
749 # --dynamic-list command line option.
751 # For PR22983 we want to make sure that all four symbols specified in
752 # pr222983.t are present in the output, but a simple sequences of regexps
753 # will not work as we do not know the order of the symbols. (Readelf
754 # does not have a symbol sorting option and the run_cc_list_tests proc
755 # does not allow for the output of the dump program to piped into `sort`).
757 # So instead we run readelf four times, each time checking for the
758 # presence of a specific symbol from the pr22983.t file.
759 run_cc_link_tests [list \
762 "-Wl,--dynamic-list,pr22983.t" \
764 {pr22983a.c pr22983b.c} \
765 {{readelf {--dyn-syms --wide} pr22983.1.d} \
766 {readelf {--dyn-syms --wide} pr22983.2.d} \
767 {readelf {--dyn-syms --wide} pr22983.3.d} \
768 {readelf {--dyn-syms --wide} pr22983.4.d}} \
774 if { [is_elf_format] && [check_lto_shared_available] } {
775 run_ld_link_exec_tests $lto_run_elf_shared_tests
778 proc pr20103 {cflags libs} {
781 set testname "PR ld/20103 ($cflags $libs)"
782 set exec_output [run_host_cmd "$CC" "$cflags $libs"]
783 if { [ regexp "undefined reference to `\\.?dead'" $exec_output ] } {
788 if { [ regexp "plugin needed to handle lto object" $exec_output ] } {
795 if { [check_lto_fat_available] } {
796 run_cc_link_tests [list \
798 "Build fatpr20103a.a" \
799 "$plug_opt" "-flto -ffat-lto-objects" \
800 {pr20103a.c} {} "fatpr20103a.a"
803 "Build fatpr20103b.a" \
804 "$plug_opt" "-flto -ffat-lto-objects" \
805 {pr20103b.c} {} "fatpr20103b.a"
808 "Build fatpr20103c.a" \
809 "$plug_opt" "-flto -ffat-lto-objects" \
810 {pr20103c.c} {} "fatpr20103c.a" \
813 "Build thinpr20103a.a" \
814 "$plug_opt" "-flto -fno-fat-lto-objects" \
815 {pr20103a.c} {} "thinpr20103a.a"
818 "Build thinpr20103b.a" \
819 "$plug_opt" "-flto -fno-fat-lto-objects" \
820 {pr20103b.c} {} "thinpr20103b.a"
823 "Build thinpr20103c.a" \
824 "$plug_opt" "-flto -fno-fat-lto-objects" \
825 {pr20103c.c} {} "thinpr20103c.a" \
829 "-O2 -flto -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
831 {dummy.c} {} "pr20103a" \
835 "-O2 -flto -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
837 {dummy.c} {} "pr20103b" \
841 "-O2 -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
843 {dummy.c} {} "pr20103c" \
846 pr20103 "-O2 -flto" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
847 pr20103 "-O2 -flto" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
848 pr20103 "-O2" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
850 if { [at_least_gcc_version 4 9] } {
851 run_cc_link_tests [list \
854 "-O2 -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
856 {dummy.c} {} "pr20103d" \
859 pr20103 "-O2" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"