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"
46 if { [check_lto_fat_available] } {
47 set lto_fat "-ffat-lto-objects"
48 set lto_no_fat "-fno-fat-lto-objects"
52 # Simple LTO tests and generate input files for complex LTO tests.
53 set lto_link_tests [list \
55 "-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" \
56 {lto-1a.c lto-1b.c} {} "lto-1.exe"] \
58 "" "-O2 -flto -fuse-linker-plugin $NOSANITIZE_CFLAGS" \
61 "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" \
62 "$NOSANITIZE_CFLAGS" \
63 {dummy.c} {} "lto-2.exe"] \
70 [list "Build liblto-3.a" \
72 {lto-3b.c} {} "liblto-3.a"] \
79 [list "Compile PR ld/12365" \
80 "" "-flto -O2 $lto_fat" \
81 {pr12365a.c pr12365b.c pr12365c.c} {} ""] \
83 "" "-O2 -finline -flto" \
84 {lto-9.cc} {} "" "c++"] \
94 [list "Build liblto-12.a" \
95 "$plug_opt" "-O2 -flto" \
96 {lto-12c.c} {} "liblto-12.a"] \
99 {lto-12a.c lto-12b.c} {} ""] \
102 {lto-13a.c lto-13b.c} {} ""] \
103 [list "Build liblto-13.a" \
105 {lto-13c.c} {} "liblto-13.a"] \
106 [list "Compile 14a" \
108 {lto-14a.c lto-14b.c} {} ""] \
109 [list "Build liblto-14.a" \
110 "$plug_opt" "-flto" \
111 {lto-14c.c} {} "liblto-14.a"] \
112 [list "Compile 15a" \
115 [list "Build liblto-15.a" \
116 "$plug_opt" "-flto" \
117 {lto-15b.c} {} "liblto-15.a"] \
118 [list "PR ld/12696" \
119 "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" \
120 {pr12696-1.cc} {} "pr12696-1r.o" "c++"] \
121 [list "Compile PR ld/12758" \
123 {pr12758a.s} {} ""] \
124 [list "Build libpr12758.a" \
125 "" "-flto -O2 $lto_fat $NOSANITIZE_CFLAGS" \
126 {pr12758b.c} {} "libpr12758.a"] \
127 [list "PR ld/12758" \
128 "$NOPIE_LDFLAGS $NOSANITIZE_CFLAGS -O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" \
129 "$NOSANITIZE_CFLAGS" \
130 {dummy.c} {} "pr12758.exe"] \
131 [list "Build libpr13183.a" \
132 "-T" "-flto -O2 $lto_fat" \
133 {pr13183a.c} {} "libpr13183.a"] \
134 [list "Compile PR ld/13183" \
136 {pr13183b.c} {} ""] \
137 [list "Compile PR ld/13201" \
140 [list "PR ld/13287" \
141 "-flto -fuse-linker-plugin -Wl,--as-needed" "-flto" \
142 {pr13287.cc} {} "pr13287.exe" "c++"] \
143 [list "PR ld/15323 (1)" \
145 {pr15323a.c} {} "" "c"] \
146 [list "PR ld/15323 (2)" \
147 "-O2 -flto -r -nostdlib" "-O2 -flto" \
148 {pr15323a.c} {} "pr15323a-r.o" "c"] \
149 [list "Compile(1) PR ld/pr16846" \
151 {pr16846a.c pr16846b.c} {} ""] \
152 [list "Compile(2) PR ld/pr16846" \
154 {pr16846c.c} {} ""] \
155 [list "PR ld/pr16846(1)" \
156 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846b.o tmpdir/pr16846c.o" "" \
157 {dummy.c} {} "pr16846a.exe"] \
158 [list "PR ld/pr16846(2)" \
159 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846c.o tmpdir/pr16846b.o" "" \
160 {dummy.c} {} "pr16846b.exe"] \
161 [list "PR ld/19317 (1)" \
162 "$plug_opt" "-flto $lto_no_fat" \
163 {pr19317.c} {} "libpr19317.a"] \
164 [list "Build pr20276a.o" \
165 "" "-fno-lto -fcommon" \
167 [list "Build pr20276b.o" \
168 "$plug_opt" "-flto $lto_no_fat -fcommon" \
170 [list "Build pr20267a.o" \
173 [list "Build libpr20267a.a" \
174 "$plug_opt" "-flto $lto_fat -fcommon" \
175 {pr20267b.c} {} "libpr20267a.a"] \
176 [list "Build libpr20267b.a" \
177 "$plug_opt" "-flto $lto_no_fat -fcommon" \
178 {pr20267b.c} {} "libpr20267b.a"] \
179 [list "Build pr20321" \
180 "-flto -Wl,-plugin,$plug_so" "-flto" \
181 {pr20321.c} {{warning ".*: duplicated plugin"}} \
183 [list "Build pr22502a.o" \
186 [list "Build pr22502b.o" \
187 "$plug_opt" "-flto $lto_no_fat" \
189 [list "Build pr22751.a" \
190 "$plug_opt" "-flto $lto_no_fat $INT128_CFLAGS" \
191 {pr22751.c} {} "pr22751.a"] \
192 [list "Build pr24406-2b.o" \
195 [list "Build pr26163a.o" \
198 [list "Build pr26262b.o" \
200 {pr26262b.c} {} "" "c"] \
201 [list "Build pr26262c.o" \
203 {pr26262c.c} {} "" "c"] \
204 [list "Build pr26267a.o" \
205 "" "-O2 -flto $lto_no_fat" \
206 {pr26267a.c} {} "" "c"] \
207 [list "Build pr26267b.o" \
209 {pr26267b.c} {} "" "c"] \
210 [list "Build pr26267c.o" \
212 {pr26267c.c} {} "" "c"] \
213 [list "Build pr26267a" \
215 {pr26267a.c} {} "" "c"] \
216 [list "Build pr26267a" \
217 "-flto tmpdir/pr26267a.o tmpdir/pr26267b.o tmpdir/pr26267c.o" \
218 "-flto $lto_no_fat" \
220 {{error_output "pr26267.err"}} \
222 [list "Build pr26267b" \
223 "-flto tmpdir/pr26267b.o tmpdir/pr26267c.o tmpdir/pr26267a.o" \
224 "-flto $lto_no_fat" \
226 {{error_output "pr26267.err"}} \
228 [list "Build pr26389.o" \
229 "$plug_opt" "-flto $lto_no_fat -fcommon" \
231 [list [list "nm" "$plug_opt" "pr26389.d"]]] \
234 if { [at_least_gcc_version 10 0] } {
235 set lto_link_tests [concat $lto_link_tests [list \
238 "-flto -fno-common $lto_no_fat" \
240 [list [list "nm" "$plug_opt" "pr25355.d"]]] \
244 if { [at_least_gcc_version 4 7] } {
245 set lto_link_tests [concat $lto_link_tests [list \
246 [list "Compile PR ld/12942 (1)" \
248 {pr12942a.cc pr12942c.cc} {} "" "c++"] \
249 [list "Compile PR ld/12942 (2)" \
251 {pr12942b.cc} {} "" "c++"] \
255 set lto_compile_elf_tests [list \
258 {lto-7a.c lto-7b.c lto-7c.c} {} ""] \
265 [list "PR ld/23309" \
266 "-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections -Wl,--gc-sections,-u,KeepMe" \
267 "-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections" \
268 {pr23309.c} {{"nm" {} "pr23309.d"}} "pr23309.exe" "c"] \
271 # Generate input files for complex LTO tests for ELF.
272 set lto_link_elf_tests [list \
274 "-O2 -flto -fuse-linker-plugin" "" \
275 {lto-6.c} {} "lto-6.exe" "c"] \
276 [list "Build liblto-7.so" \
277 "-shared" "-O2 -fpic" \
278 {lto-7d.c} {} "liblto-7.so" "c"] \
279 [list "Build liblto-17a.so" \
280 "-shared -O2 -fpic -flto -fuse-linker-plugin" "-O2 -fpic -flto" \
281 {lto-17a.c} {{"nm" {} "lto-17a.d"}} "liblto-17a.so" "c"] \
282 [list "Build liblto-17b.so 1" \
283 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
284 {lto-17b.c} {{"nm" {} "lto-17b-1.d"}} "liblto-17b.so"] \
285 [list "Build liblto-17b.so 2" \
286 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
287 {lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"] \
288 [list "Compile PR ld/12760" \
290 {pr12760a.c} {} ""] \
291 [list "Build libpr12760.a" \
292 "" "-flto -O2 $lto_fat" \
293 {pr12760b.c} {} "libpr12760.a"] \
294 [list "PR ld/12760" \
295 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" \
296 {dummy.c} {{warning "pr12760a.c:6: warning: Bad \\.?bar"}} \
298 [list "PR ld/12975" \
299 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \
300 {pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"] \
301 [list "PR ld/13229" \
302 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -finline -fno-early-inlining -flto" \
303 {pr13229.cc} {{"readelf" {-s --wide} "pr13229.d"}} "pr13229.so" "c++"] \
304 [list "PR ld/13244" \
305 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \
306 {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \
307 [list "Build libpr16746a.a" \
309 {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
310 [list "Build libpr16746b.a" \
311 "$plug_opt" "-O2 -flto" \
312 {pr16746c.c pr16746d.c} {} "lib15146b.a"] \
313 [list "PR ld/16746 (1)" \
314 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \
315 {dummy.c} {} "pr16746a.exe"] \
316 [list "PR ld/16746 (2)" \
317 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto" \
318 {dummy.c} {} "pr16746b.exe"] \
319 [list "Build pr21382a.o" \
321 {pr21382a.c} {} "" "c"] \
322 [list "Build pr21382.so" \
323 "-shared" "-O2 -fpic" \
324 {pr21382b.c} {} "pr21382.so" "c"] \
325 [list {Build pr22220lib.so} \
326 {-shared -Wl,--version-script=pr22220lib.ver} {-fPIC} \
327 {pr22220lib.cc} {} {pr22220lib.so} {c++}] \
328 [list {Build pr22220main.o} \
330 {pr22220main.cc} {} {} {c++}] \
331 [list "Build libpr23818.so" \
332 "-shared -flto -g -Wl,-version-script,pr23818.t" \
333 "-g -flto $lto_fat" \
334 {pr23818a.c pr23818b.c} \
335 {{"readelf" {-s --wide} "pr23818.d"}} \
337 [list "Build libpr23958.so" \
338 "-shared -flto -Wl,-version-script,pr23958.t" \
339 "-g -flto $lto_fat" \
343 [list "Build pr24486a.o" \
344 "$plug_opt" "-flto -O2" \
345 {pr24486a.c} {} "" "c"] \
346 [list "Build pr24486b.so" \
347 "-shared" "-O2 -fpic" \
348 {pr24486b.c} {} "pr24486b.so" "c"] \
349 [list "Build pr24486c.so" \
350 "-shared -Wl,--no-as-needed tmpdir/pr24486b.so" "-O2 -fpic" \
351 {pr24486c.c} {} "pr24486c.so" "c"] \
352 [list "PR ld/24486" \
353 "-O2 -flto tmpdir/pr24486a.o tmpdir/pr24486c.so -Wl,--as-needed tmpdir/pr24486b.so" "" \
354 {dummy.c} {} "pr24486.exe"] \
355 [list "Build pr25593a-1.o" \
356 "$plug_opt" "-flto -O2" \
357 {pr25593a-1.c} {} "" "c"] \
358 [list "Build pr25593a-2.o" \
360 {pr25593a-2.c} {} "" "c"] \
361 [list "Build pr25593b.o" \
363 {pr25593b.c} {} "" "c"] \
364 [list "Build pr25593c.so" \
365 "-shared" "-O2 -fpic" \
366 {pr25593c.c} {} "pr25593c.so" "c"] \
367 [list "Build pr25593d.so" \
368 "-shared" "-O2 -fpic" \
369 {pr25593d.c} {} "pr25593d.so" "c"] \
370 [list "Build pr25593e.so" \
371 "-shared" "-O2 -fpic" \
372 {pr25593e.c} {} "pr25593e.so" "c"] \
373 [list "PR ld/r25593 (LTO)" \
374 "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-1.o tmpdir/pr25593b.o \
375 tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
376 {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593a.exe"] \
377 [list "PR ld/r25593" \
378 "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-2.o tmpdir/pr25593b.o \
379 tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
380 {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593b.exe"] \
381 [list "Build pr25618a.o" \
382 "$plug_opt" "-O2 -flto -fpic" \
383 {pr25618a.cc} {} "" "c++"] \
384 [list "Build pr25618.a" \
385 "$plug_opt" "-O2 -flto -fpic" \
386 {pr25618b.cc} {} "pr25618.a" "c++"] \
387 [list "Build pr25618.so" \
388 "-shared -Wl,--exclude-libs,ALL tmpdir/pr25618a.o tmpdir/pr25618.a" \
390 {dummy.c} {{readelf {--dyn-syms --wide} pr25618.d}} "pr25618.so" "c++"] \
391 [list {liblto-18b.so} \
392 {-shared} {-O2 -fpic} \
393 {lto-18b.c} {} {liblto-18b.so}] \
394 [list {liblto-18b.a} \
395 "$plug_opt" {-flto -O2} \
396 {lto-18b.c} {} {liblto-18b.a}] \
397 [list {liblto-18c.so} \
398 {-shared} {-O2 -fpic} \
399 {lto-18c.c} {} {liblto-18c.so}] \
400 [list {liblto-18c.a} \
401 "$plug_opt" {-flto -O2} \
402 {lto-18c.c} {} {liblto-18c.a}] \
408 # PR 14918 checks that libgcc is not spuriously included in a shared link of
409 # an empty program. The ARM crt1.o startup code however calls __libc_csu_init
410 # in /usr/lib/libc_nonshared.a(elf-init.oS). This in turn needs
411 # __aeabi_unwind_cpp_pr0@@GCC_3.5 which is provided by libgcc_s.so.1, so the
412 # test fails. Hence this code to skip the test.
413 if { ! [istarget "arm*-*-*"] } {
414 lappend lto_link_elf_tests [list \
415 [list "PR ld/14918" \
417 {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \
421 # PR 12982 checks that an executable stack is not created by default
422 # when using the LTO plugin. The HPPA target however requires an
423 # executable stack for syscall restarts and signal returns, so we
424 # skip this test for that target.
425 if { ! [istarget "hppa*-*-*"] } {
426 lappend lto_link_elf_tests [list \
427 [list "PR ld/12982" \
428 "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
429 {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
433 # Check final symbols in executables.
434 set lto_link_symbol_tests [list \
435 [list "LTO 3 symbol" \
436 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
437 {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"] \
438 [list "LTO 5 symbol" \
439 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
440 {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"] \
441 [list "LTO 9 symbol" \
442 "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" \
443 {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"] \
444 [list "LTO 16a symbol" \
445 "-O2 $NOSANITIZE_CFLAGS -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" \
446 "-flto $NOSANITIZE_CFLAGS" \
447 {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"] \
448 [list "LTO 16b symbol" \
449 "-O2 $NOSANITIZE_CFLAGS -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" \
450 "-flto $NOSANITIZE_CFLAGS" \
451 {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"] \
452 [list "PR ld/13183" \
453 "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" \
454 {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"] \
457 # LTO run-time tests.
458 set lto_run_tests [list \
460 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
461 {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"] \
463 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" \
464 {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"] \
466 "-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" "" \
467 {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
469 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
470 {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
472 "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
473 {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
475 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" \
476 {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"] \
478 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" \
479 {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"] \
481 "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" \
482 {dummy.c} "lto-13.exe" "lto-13.out" "" "c"] \
484 "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" \
485 {dummy.c} "lto-14.exe" "lto-14.out" "" "c"] \
487 "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" \
488 {dummy.c} "lto-15.exe" "lto-15.out" "" "c"] \
489 [list "PR ld/13066" \
490 "-O2 -flto -fuse-linker-plugin" "" \
491 {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"] \
492 [list "PR ld/13201" \
493 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" \
494 {dummy.c} "pr13201.exe" "pr13201.out" "" "c"] \
495 [list "PR ld/15323 (3)" \
496 "-O2 -flto -fuse-linker-plugin tmpdir/pr15323a.o" "" \
497 {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"] \
498 [list "PR ld/15323 (4)" \
499 "-O2 -flto tmpdir/pr15323a-r.o" "" \
500 {dummy.c} "pr15323a.exe" "pr15323.out" "-flto -O2" "c"] \
501 [list "PR ld/19317 (3)" \
502 "-O2 -flto tmpdir/pr19317-r.o" "" \
503 {dummy.c} "pr19317.exe" "pr19317.out" "-flto -O2" "c"] \
504 [list "Run pr20276" \
505 "-O2 -flto tmpdir/pr20276a.o tmpdir/pr20276b.o" "" \
506 {dummy.c} "pr20276" "pass.out" "-flto -O2" "c"] \
507 [list "Run pr20267a" \
508 "-O2 -flto -fcommon tmpdir/pr20267a.o tmpdir/libpr20267a.a" "" \
509 {dummy.c} "pr20267a" "pass.out" "-flto -O2 -fcommon" "c"] \
510 [list "Run pr20267b" \
511 "-O2 -flto -fcommon tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \
512 {dummy.c} "pr20267b" "pass.out" "-flto -O2 -fcommon" "c"] \
513 [list "Run pr22502" \
514 "-O2 -flto tmpdir/pr22502a.o tmpdir/pr22502b.o" "" \
515 {dummy.c} "pr20267" "pass.out" "-flto -O2 -fcommon" "c"] \
516 [list "Run pr22751" \
518 {dummy.c} "pr22751" "pass.out" "-flto -O2" "c" "" \
519 "-Wl,--whole-archive tmpdir/pr22751.a -Wl,--no-whole-archive"] \
520 [list "Run pr24406-1" \
522 {pr24406-1.c} "pr24406-1" "pass.out" "-flto -O2" "c" "" \
524 [list "Run pr24406-2" \
526 {pr24406-2a.c} "pr24406-2" "pass.out" \
528 "tmpdir/pr24406-2b.o -Wl,--wrap=cook"] \
529 [list "Run pr26163" \
531 {pr26163b.c} "pr24406-2" "pass.out" \
533 "tmpdir/pr26163a.o -Wl,--defsym,g=real_g"] \
534 [list "Run pr26262a" \
536 {pr26262a.c} "pr26262a" "pass.out" \
538 "tmpdir/pr26262b.o tmpdir/pr26262c.o"] \
539 [list "Run pr26262b" \
540 "-flto -O2 tmpdir/pr26262b.o tmpdir/pr26262c.o" "" \
541 {pr26262a.c} "pr26262b" "pass.out" \
546 if { [at_least_gcc_version 4 7] } {
547 set lto_run_tests [concat $lto_run_tests [list \
548 [list "PR ld/12942 (1)" \
549 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" \
550 {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"] \
551 [list "PR ld/12942 (2)" \
552 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" \
553 {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"] \
557 # LTO run-time tests for ELF which require shared library support.
558 set lto_run_elf_shared_tests [list \
560 "-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" "" \
561 {dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \
562 [list "Run pr21382" \
563 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr21382a.o tmpdir/pr21382.so" "" \
564 {dummy.c} "pr21382.exe" "pass.out" "" "c"] \
566 {-flto -fuse-linker-plugin tmpdir/pr22220main.o tmpdir/pr22220lib.so} {} \
567 {dummy.c} {pr22220a.exe} {pass.out} {} {c++}] \
569 {-flto -fuse-linker-plugin -Wl,--no-as-needed tmpdir/pr22220lib.so tmpdir/pr22220main.o} {} \
570 {dummy.c} {pr22220b.exe} {pass.out} {} {c++}] \
572 {-flto -fuse-linker-plugin} {} \
573 {lto-18a.c} {lto-18-1.exe} {lto-18.out} {-flto -O2} {c} {} \
574 {tmpdir/lto-18d.o -Wl,--as-needed,-R,tmpdir -Ltmpdir -llto-18b -llto-18c}] \
576 {-flto -fuse-linker-plugin} {} \
577 {lto-18a.c} {lto-18-2.exe} {lto-18.out} {-flto -O2} {c} {} \
578 {-Wl,--as-needed,-R,tmpdir -Ltmpdir -llto-18b -llto-18c tmpdir/lto-18d.o}] \
580 {-static -flto -fuse-linker-plugin} {} \
581 {lto-18a.c} {lto-18-3.exe} {lto-18.out} {-flto -O2} {c} {} \
582 {tmpdir/lto-18d.o -Ltmpdir -llto-18b -llto-18c}] \
584 {-static -flto -fuse-linker-plugin} {} \
585 {lto-18a.c} {lto-18-4.exe} {lto-18.out} {-flto -O2} {c} {} \
586 { -Ltmpdir -llto-18b -llto-18c tmpdir/lto-18d.o}] \
589 # LTO run-time tests for ELF
590 set lto_run_elf_tests [list \
592 "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \
593 {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \
595 "-O2 -flto -fuse-linker-plugin" "" \
596 {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \
599 run_cc_link_tests $lto_link_tests
601 # These compilation tests generate intermediate object files which will be used
602 # by some elf tests besides shared libs tests. So, always compile them.
603 run_cc_link_tests $lto_compile_elf_tests
605 # Restrict these to ELF targets that support shared libs and PIC.
606 if { [is_elf_format] && [check_lto_shared_available] } {
607 run_cc_link_tests $lto_link_elf_tests
608 set testname "PR ld/16746 (3)"
609 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
610 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
615 set testname "PR ld/16746 (4)"
616 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
617 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
624 set testname "Build liblto-11.a"
625 remote_file host delete "tmpdir/liblto-11.a"
626 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"]
627 if {![string match "" $catch_output]} {
633 if { [at_least_gcc_version 4 7] } {
634 # Check expected LTO linker errors.
635 # Since the asm symbol name hack in pr12365b.c doesn't work on all
636 # targets, run PR ld/12365 tests only for known targets.
637 if { ([istarget "i?86-*-elf*"]
638 || [istarget "i?86-*-linux*"]
639 || [istarget "i?86-*-gnu*"]
640 || [istarget "x86_64-*-linux*"]
641 || [istarget "amd64-*-linux*"]) } {
642 set testname "PR ld/12365"
643 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"]
644 set exec_output [prune_warnings $exec_output]
645 if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
646 # Linker should catch the reference to undefined `my_bcopy'
647 # error caused by a GCC bug.
649 } elseif { [ string match "" $exec_output ] } {
651 set exec_output [run_host_cmd "$READELF" "-s -W tmpdir/pr12365"]
652 if { [ regexp "my_bcopy" $exec_output ] } {
653 # Verify that there is no `my_bcopy' symbol in executable.
662 run_cc_link_tests [list \
664 "Build pr22721a.so" \
665 "-shared $NOSANITIZE_CFLAGS -nostdlib -nostartfiles \
666 -Wl,-version-script,pr22721.t" \
674 "$plug_opt $NOSANITIZE_CFLAGS" \
675 "-O2 -fPIC -flto $lto_no_fat" \
679 "Build PR ld/pr22721" \
680 "-O2 -flto -fuse-linker-plugin -nostdlib -nostartfiles \
682 -Wl,-e,_start tmpdir/pr22721b.o tmpdir/pr22721a.so" \
683 "$NOSANITIZE_CFLAGS" \
690 set testname "PR ld/12942 (3)"
691 set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
692 if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
698 run_cc_link_tests [list \
702 "-O2 -fPIC -flto $lto_no_fat" \
703 {pr23460a.c pr23460b.c pr23460c.c \
704 pr23460d.c pr23460e.c pr23460f.c} \
707 set exec_output [run_host_cmd "sh" \
708 "-c \"ulimit -n 16; \
710 tmpdir/libpr23460.a \
716 tmpdir/pr23460f.o\""]
717 set exec_output [prune_warnings $exec_output]
718 if [string match "" $exec_output] then {
719 pass "PR binutils/23460"
721 fail "PR binutils/23460"
725 # Run "ld -r" to generate inputs for complex LTO tests.
726 run_dump_test "lto-3r"
727 remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
728 run_dump_test "lto-5r"
729 remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
731 run_cc_link_tests $lto_link_symbol_tests
733 run_ld_link_tests [list \
734 [list "PR ld/19317 (2)" \
735 "-r tmpdir/pr19317.o" "" "" \
736 {dummy.s} {} "pr19317-r.o"] \
739 run_ld_link_exec_tests $lto_run_tests
741 if { [is_elf_format] } {
742 run_ld_link_exec_tests $lto_run_elf_tests
744 # Note - it is not guaranteed that the ordering of symbols in the dynamic
745 # symbol table will match the ordering of the symbols specified by the
746 # --dynamic-list command line option.
748 # For PR22983 we want to make sure that all four symbols specified in
749 # pr222983.t are present in the output, but a simple sequences of regexps
750 # will not work as we do not know the order of the symbols. (Readelf
751 # does not have a symbol sorting option and the run_cc_list_tests proc
752 # does not allow for the output of the dump program to piped into `sort`).
754 # So instead we run readelf four times, each time checking for the
755 # presence of a specific symbol from the pr22983.t file.
756 run_cc_link_tests [list \
759 "-Wl,--dynamic-list,pr22983.t" \
761 {pr22983a.c pr22983b.c} \
762 {{readelf {--dyn-syms --wide} pr22983.1.d} \
763 {readelf {--dyn-syms --wide} pr22983.2.d} \
764 {readelf {--dyn-syms --wide} pr22983.3.d} \
765 {readelf {--dyn-syms --wide} pr22983.4.d}} \
771 if { [is_elf_format] && [check_lto_shared_available] } {
772 run_ld_link_exec_tests $lto_run_elf_shared_tests
775 proc pr20103 {cflags libs} {
778 set testname "PR ld/20103 ($cflags $libs)"
779 set exec_output [run_host_cmd "$CC" "$cflags $libs"]
780 if { [ regexp "undefined reference to `\\.?dead'" $exec_output ] } {
785 if { [ regexp "plugin needed to handle lto object" $exec_output ] } {
792 if { [check_lto_fat_available] } {
793 run_cc_link_tests [list \
795 "Build fatpr20103a.a" \
796 "$plug_opt" "-flto -ffat-lto-objects" \
797 {pr20103a.c} {} "fatpr20103a.a"
800 "Build fatpr20103b.a" \
801 "$plug_opt" "-flto -ffat-lto-objects" \
802 {pr20103b.c} {} "fatpr20103b.a"
805 "Build fatpr20103c.a" \
806 "$plug_opt" "-flto -ffat-lto-objects" \
807 {pr20103c.c} {} "fatpr20103c.a" \
810 "Build thinpr20103a.a" \
811 "$plug_opt" "-flto -fno-fat-lto-objects" \
812 {pr20103a.c} {} "thinpr20103a.a"
815 "Build thinpr20103b.a" \
816 "$plug_opt" "-flto -fno-fat-lto-objects" \
817 {pr20103b.c} {} "thinpr20103b.a"
820 "Build thinpr20103c.a" \
821 "$plug_opt" "-flto -fno-fat-lto-objects" \
822 {pr20103c.c} {} "thinpr20103c.a" \
826 "-O2 -flto -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
828 {dummy.c} {} "pr20103a" \
832 "-O2 -flto -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
834 {dummy.c} {} "pr20103b" \
838 "-O2 -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
840 {dummy.c} {} "pr20103c" \
843 pr20103 "-O2 -flto" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
844 pr20103 "-O2 -flto" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
845 pr20103 "-O2" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
847 if { [at_least_gcc_version 4 9] } {
848 run_cc_link_tests [list \
851 "-O2 -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
853 {dummy.c} {} "pr20103d" \
856 pr20103 "-O2" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"