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] } {
36 set saved_CFLAGS "$CFLAGS"
37 set saved_CXXFLAGS "$CXXFLAGS"
38 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS
39 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS
41 proc restore_notify { } {
44 set CFLAGS "$saved_CFLAGS"
45 set CXXFLAGS "$saved_CXXFLAGS"
54 foreach plug $plugin_names {
55 set plug_so [run_host_cmd $CC "--print-prog-name $plug"]
56 if { $plug_so eq $plug } then {
57 set plug_so [run_host_cmd $CC "--print-file-name $plug"]
59 if { $plug_so ne $plug } then {
60 set plug_opt "--plugin $plug_so"
66 if { [check_lto_fat_available] } {
67 set lto_fat "-ffat-lto-objects"
68 set lto_no_fat "-fno-fat-lto-objects"
71 # Simple LTO tests and generate input files for complex LTO tests.
72 set lto_link_tests [list \
74 "-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" \
75 {lto-1a.c lto-1b.c} {} "lto-1.exe"] \
77 "" "-O2 -flto -fuse-linker-plugin" \
80 "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" "" \
81 {dummy.c} {} "lto-2.exe"] \
88 [list "Build liblto-3.a" \
90 {lto-3b.c} {} "liblto-3.a"] \
98 "-O2 -flto -fuse-linker-plugin" "" \
99 {lto-6.c} {} "lto-6.exe" "c"] \
100 [list "Compile PR ld/12365" \
101 "" "-flto -O2 $lto_fat" \
102 {pr12365a.c pr12365b.c pr12365c.c} {} ""] \
104 "" "-O2 -finline -flto" \
105 {lto-9.cc} {} "" "c++"] \
106 [list "Compile 11a" \
109 [list "Compile 11b" \
112 [list "Compile 11c" \
115 [list "Build liblto-12.a" \
116 "$plug_opt" "-O2 -flto" \
117 {lto-12c.c} {} "liblto-12.a"] \
120 {lto-12a.c lto-12b.c} {} ""] \
123 {lto-13a.c lto-13b.c} {} ""] \
124 [list "Build liblto-13.a" \
126 {lto-13c.c} {} "liblto-13.a"] \
127 [list "Compile 14a" \
129 {lto-14a.c lto-14b.c} {} ""] \
130 [list "Build liblto-14.a" \
131 "$plug_opt" "-flto" \
132 {lto-14c.c} {} "liblto-14.a"] \
133 [list "Compile 15a" \
136 [list "Build liblto-15.a" \
137 "$plug_opt" "-flto" \
138 {lto-15b.c} {} "liblto-15.a"] \
139 [list "PR ld/12696" \
140 "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" \
141 {pr12696-1.cc} {} "pr12696-1r.o" "c++"] \
142 [list "Compile PR ld/12758" \
144 {pr12758a.s} {} ""] \
145 [list "Build libpr12758.a" \
146 "" "-flto -O2 $lto_fat" \
147 {pr12758b.c} {} "libpr12758.a"] \
148 [list "PR ld/12758" \
149 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" "" \
150 {dummy.c} {} "pr12758.exe"] \
151 [list "Compile PR ld/12760" \
153 {pr12760a.c} {} ""] \
154 [list "Build libpr12760.a" \
155 "" "-flto -O2 $lto_fat" \
156 {pr12760b.c} {} "libpr12760.a"] \
157 [list "PR ld/12760" \
158 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" \
159 {dummy.c} {{warning "pr12760a.c:6: warning: Bad \\.?bar"}} \
161 [list "Build libpr13183.a" \
162 "-T" "-flto -O2 $lto_fat" \
163 {pr13183a.c} {} "libpr13183.a"] \
164 [list "Compile PR ld/13183" \
166 {pr13183b.c} {} ""] \
167 [list "Compile PR ld/13201" \
170 [list "PR ld/13287" \
171 "-flto -fuse-linker-plugin -Wl,--as-needed" "-flto" \
172 {pr13287.cc} {} "pr13287.exe" "c++"] \
173 [list "PR ld/15323 (1)" \
175 {pr15323a.c} {} "" "c"] \
176 [list "PR ld/15323 (2)" \
177 "-O2 -flto -r -nostdlib" "-O2 -flto" \
178 {pr15323a.c} {} "pr15323a-r.o" "c"] \
179 [list "Compile(1) PR ld/pr16846" \
181 {pr16846a.c pr16846b.c} {} ""] \
182 [list "Compile(2) PR ld/pr16846" \
184 {pr16846c.c} {} ""] \
185 [list "PR ld/pr16846(1)" \
186 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846b.o tmpdir/pr16846c.o" "" \
187 {dummy.c} {} "pr16846a.exe"] \
188 [list "PR ld/pr16846(2)" \
189 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846c.o tmpdir/pr16846b.o" "" \
190 {dummy.c} {} "pr16846b.exe"] \
191 [list "PR ld/19317 (1)" \
192 "$plug_opt" "-flto $lto_no_fat" \
193 {pr19317.c} {} "libpr19317.a"] \
194 [list "Build pr20276a.o" \
195 "" "-fno-lto -fcommon" \
197 [list "Build pr20276b.o" \
198 "$plug_opt" "-flto $lto_no_fat -fcommon" \
200 [list "Build pr20267a.o" \
203 [list "Build libpr20267a.a" \
204 "$plug_opt" "-flto $lto_fat -fcommon" \
205 {pr20267b.c} {} "libpr20267a.a"] \
206 [list "Build libpr20267b.a" \
207 "$plug_opt" "-flto $lto_no_fat -fcommon" \
208 {pr20267b.c} {} "libpr20267b.a"] \
209 [list "Build pr20321" \
210 "-flto -Wl,-plugin,$plug_so" "-flto" \
211 {pr20321.c} {{warning ".*: duplicated plugin"}} \
213 [list "Build pr22502a.o" \
216 [list "Build pr22502b.o" \
217 "$plug_opt" "-flto $lto_no_fat" \
219 [list "Build pr22751.a" \
220 "$plug_opt" "-flto $lto_no_fat $INT128_CFLAGS" \
221 {pr22751.c} {} "pr22751.a"] \
222 [list "Build libpr23818.so" \
223 "-shared -flto -g -Wl,-version-script,pr23818.t" \
224 "-g -flto $lto_fat" \
225 {pr23818a.c pr23818b.c} \
226 {{"readelf" {-s --wide} "pr23818.d"}} \
228 [list "Build libpr23958.so" \
229 "-shared -flto -Wl,-version-script,pr23958.t" \
230 "-g -flto $lto_fat" \
234 [list "Build pr24406-2b.o" \
239 "-flto -fno-common $lto_no_fat" \
241 [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 \
273 [list "Build liblto-7.so" \
274 "-shared" "-O2 -fpic" \
275 {lto-7d.c} {} "liblto-7.so" "c"] \
276 [list "Build liblto-17a.so" \
277 "-shared -O2 -fpic -flto -fuse-linker-plugin" "-O2 -fpic -flto" \
278 {lto-17a.c} {{"nm" {} "lto-17a.d"}} "liblto-17a.so" "c"] \
279 [list "Build liblto-17b.so 1" \
280 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
281 {lto-17b.c} {{"nm" {} "lto-17b-1.d"}} "liblto-17b.so"] \
282 [list "Build liblto-17b.so 2" \
283 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
284 {lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"] \
285 [list "PR ld/12975" \
286 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \
287 {pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"] \
288 [list "PR ld/13229" \
289 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -finline -fno-early-inlining -flto" \
290 {pr13229.cc} {{"readelf" {-s --wide} "pr13229.d"}} "pr13229.so" "c++"] \
291 [list "PR ld/13244" \
292 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \
293 {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \
294 [list "Build libpr15146a.a" \
295 "$plug_opt" "-flto -O2" \
296 {pr15146a.c} {} "lib15146a.a"] \
297 [list "Build pr15146b.so" \
298 "-shared" "-O2 -fpic" \
299 {pr15146b.c} {} "pr15146b.so" "c"] \
300 [list "Build pr15146c.so" \
301 "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic" \
302 {pr15146c.c} {} "pr15146c.so" "c"] \
303 [list "PR ld/15146 (1)" \
304 "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \
305 {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"] \
306 [list "Build libpr15146d.a" \
307 "$plug_opt" "-flto -O2" \
308 {pr15146d.c} {} "lib15146d.a"] \
309 [list "Build libpr16746a.a" \
311 {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
312 [list "Build libpr16746b.a" \
313 "$plug_opt" "-O2 -flto" \
314 {pr16746c.c pr16746d.c} {} "lib15146b.a"] \
315 [list "PR ld/16746 (1)" \
316 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \
317 {dummy.c} {} "pr16746a.exe"] \
318 [list "PR ld/16746 (2)" \
319 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto" \
320 {dummy.c} {} "pr16746b.exe"] \
321 [list "Build pr21382a.o" \
323 {pr21382a.c} {} "" "c"] \
324 [list "Build pr21382.so" \
325 "-shared" "-O2 -fpic" \
326 {pr21382b.c} {} "pr21382.so" "c"] \
327 [list {Build pr22220lib.so} \
328 {-shared -Wl,--version-script=pr22220lib.ver} {-fPIC} \
329 {pr22220lib.cc} {} {pr22220lib.so} {c++}] \
330 [list {Build pr22220main.o} \
332 {pr22220main.cc} {} {} {c++}] \
333 [list "Build pr24486a.o" \
334 "$plug_opt" "-flto -O2" \
335 {pr24486a.c} {} "" "c"] \
336 [list "Build pr24486b.so" \
337 "-shared" "-O2 -fpic" \
338 {pr24486b.c} {} "pr24486b.so" "c"] \
339 [list "Build pr24486c.so" \
340 "-shared -Wl,--no-as-needed tmpdir/pr24486b.so" "-O2 -fpic" \
341 {pr24486c.c} {} "pr24486c.so" "c"] \
342 [list "PR ld/24486" \
343 "-O2 -flto tmpdir/pr24486a.o tmpdir/pr24486c.so -Wl,--as-needed tmpdir/pr24486b.so" "" \
344 {dummy.c} {} "pr24486.exe"] \
345 [list "Build pr25593a-1.o" \
346 "$plug_opt" "-flto -O2" \
347 {pr25593a-1.c} {} "" "c"] \
348 [list "Build pr25593a-2.o" \
350 {pr25593a-2.c} {} "" "c"] \
351 [list "Build pr25593b.o" \
353 {pr25593b.c} {} "" "c"] \
354 [list "Build pr25593c.so" \
355 "-shared" "-O2 -fpic" \
356 {pr25593c.c} {} "pr25593c.so" "c"] \
357 [list "Build pr25593d.so" \
358 "-shared" "-O2 -fpic" \
359 {pr25593d.c} {} "pr25593d.so" "c"] \
360 [list "Build pr25593e.so" \
361 "-shared" "-O2 -fpic" \
362 {pr25593e.c} {} "pr25593e.so" "c"] \
363 [list "PR ld/r25593 (LTO)" \
364 "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-1.o tmpdir/pr25593b.o \
365 tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
366 {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593a.exe"] \
367 [list "PR ld/r25593" \
368 "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-2.o tmpdir/pr25593b.o \
369 tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
370 {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593b.exe"] \
371 [list "Build pr25618a.o" \
372 "$plug_opt" "-O2 -flto -fpic" \
373 {pr25618a.cc} {} "" "c++"] \
374 [list "Build pr25618.a" \
375 "$plug_opt" "-O2 -flto -fpic" \
376 {pr25618b.cc} {} "pr25618.a" "c++"] \
377 [list "Build pr25618.so" \
378 "-shared -Wl,--exclude-libs,ALL tmpdir/pr25618a.o tmpdir/pr25618.a" \
380 {dummy.c} {{readelf {--dyn-syms --wide} pr25618.d}} "pr25618.so" "c++"] \
383 # PR 14918 checks that libgcc is not spuriously included in a shared link of
384 # an empty program. The ARM crt1.o startup code however calls __libc_csu_init
385 # in /usr/lib/libc_nonshared.a(elf-init.oS). This in turn needs
386 # __aeabi_unwind_cpp_pr0@@GCC_3.5 which is provided by libgcc_s.so.1, so the
387 # test fails. Hence this code to skip the test.
388 if { ! [istarget "arm*-*-*"] } {
389 set lto_link_elf_tests [concat $lto_link_elf_tests [list \
390 [list "PR ld/14918" \
392 {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \
396 # PR 12982 checks that an executable stack is not created by default
397 # when using the LTO plugin. The HPPA target however requires an
398 # executable stack for syscall restarts and signal returns, so we
399 # skip this test for that target.
400 if { ! [istarget "hppa*-*-*"] } {
401 set lto_link_elf_tests [concat $lto_link_elf_tests [list \
402 [list "PR ld/12982" \
403 "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
404 {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
408 # Check final symbols in executables.
409 set lto_link_symbol_tests [list \
410 [list "LTO 3 symbol" \
411 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
412 {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"] \
413 [list "LTO 5 symbol" \
414 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
415 {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"] \
416 [list "LTO 9 symbol" \
417 "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" \
418 {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"] \
419 [list "LTO 16a symbol" \
420 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" "-flto" \
421 {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"] \
422 [list "LTO 16b symbol" \
423 "-O2 -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" "-flto" \
424 {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"] \
425 [list "PR ld/13183" \
426 "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" \
427 {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"] \
430 # LTO run-time tests.
431 set lto_run_tests [list \
433 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
434 {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"] \
436 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" \
437 {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"] \
439 "-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" "" \
440 {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
442 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
443 {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
445 "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
446 {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
448 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" \
449 {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"] \
451 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" \
452 {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"] \
454 "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" \
455 {dummy.c} "lto-13.exe" "lto-13.out" "" "c"] \
457 "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" \
458 {dummy.c} "lto-14.exe" "lto-14.out" "" "c"] \
460 "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" \
461 {dummy.c} "lto-15.exe" "lto-15.out" "" "c"] \
462 [list "PR ld/13066" \
463 "-O2 -flto -fuse-linker-plugin" "" \
464 {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"] \
465 [list "PR ld/13201" \
466 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" \
467 {dummy.c} "pr13201.exe" "pr13201.out" "" "c"] \
468 [list "PR ld/15323 (3)" \
469 "-O2 -flto -fuse-linker-plugin tmpdir/pr15323a.o" "" \
470 {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"] \
471 [list "PR ld/15323 (4)" \
472 "-O2 -flto tmpdir/pr15323a-r.o" "" \
473 {dummy.c} "pr15323a.exe" "pr15323.out" "-flto -O2" "c"] \
474 [list "PR ld/19317 (3)" \
475 "-O2 -flto tmpdir/pr19317-r.o" "" \
476 {dummy.c} "pr19317.exe" "pr19317.out" "-flto -O2" "c"] \
477 [list "Run pr20276" \
478 "-O2 -flto tmpdir/pr20276a.o tmpdir/pr20276b.o" "" \
479 {dummy.c} "pr20276" "pass.out" "-flto -O2" "c"] \
480 [list "Run pr20267a" \
481 "-O2 -flto -fcommon tmpdir/pr20267a.o tmpdir/libpr20267a.a" "" \
482 {dummy.c} "pr20267a" "pass.out" "-flto -O2 -fcommon" "c"] \
483 [list "Run pr20267b" \
484 "-O2 -flto -fcommon tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \
485 {dummy.c} "pr20267b" "pass.out" "-flto -O2 -fcommon" "c"] \
486 [list "Run pr22502" \
487 "-O2 -flto tmpdir/pr22502a.o tmpdir/pr22502b.o" "" \
488 {dummy.c} "pr20267" "pass.out" "-flto -O2 -fcommon" "c"] \
489 [list "Run pr22751" \
491 {dummy.c} "pr22751" "pass.out" "-flto -O2" "c" "" \
492 "-Wl,--whole-archive tmpdir/pr22751.a -Wl,--no-whole-archive"] \
493 [list "Run pr24406-1" \
495 {pr24406-1.c} "pr24406-1" "pass.out" "-flto -O2" "c" "" \
497 [list "Run pr24406-2" \
499 {pr24406-2a.c} "pr24406-2" "pass.out" \
501 "tmpdir/pr24406-2b.o -Wl,--wrap=cook"] \
504 if { [at_least_gcc_version 4 7] } {
505 set lto_run_tests [concat $lto_run_tests [list \
506 [list "PR ld/12942 (1)" \
507 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" \
508 {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"] \
509 [list "PR ld/12942 (2)" \
510 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" \
511 {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"] \
515 # LTO run-time tests for ELF which require shared library support.
516 set lto_run_elf_shared_tests [list \
518 "-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" "" \
519 {dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \
520 [list "Run pr21382" \
521 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr21382a.o tmpdir/pr21382.so" "" \
522 {dummy.c} "pr21382.exe" "pass.out" "" "c"] \
524 {-flto -fuse-linker-plugin tmpdir/pr22220main.o tmpdir/pr22220lib.so} {} \
525 {dummy.c} {pr22220a.exe} {pass.out} {} {c++}] \
527 {-flto -fuse-linker-plugin -Wl,--no-as-needed tmpdir/pr22220lib.so tmpdir/pr22220main.o} {} \
528 {dummy.c} {pr22220b.exe} {pass.out} {} {c++}] \
531 # LTO run-time tests for ELF
532 set lto_run_elf_tests [list \
534 "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \
535 {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \
537 "-O2 -flto -fuse-linker-plugin" "" \
538 {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \
541 run_cc_link_tests $lto_link_tests
543 # These compilation tests generate intermediate object files which will be used
544 # by some elf tests besides shared libs tests. So, always compile them.
545 run_cc_link_tests $lto_compile_elf_tests
547 # Restrict these to ELF targets that support shared libs and PIC.
548 if { [is_elf_format] && [check_lto_shared_available] } {
549 run_cc_link_tests $lto_link_elf_tests
550 set testname "PR ld/15146 (2)"
551 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"]
552 if { [ regexp "undefined reference to symbol '\\.?xxx'" $exec_output ] } {
557 set testname "PR ld/16746 (3)"
558 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
559 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
564 set testname "PR ld/16746 (4)"
565 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
566 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
573 set testname "Build liblto-11.a"
574 remote_file host delete "tmpdir/liblto-11.a"
575 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"]
576 if {![string match "" $catch_output]} {
582 if { [at_least_gcc_version 4 7] } {
583 # Check expected LTO linker errors.
584 # Since the asm symbol name hack in pr12365b.c doesn't work on all
585 # targets, run PR ld/12365 tests only for known targets.
586 if { ([istarget "i?86-*-elf*"]
587 || [istarget "i?86-*-linux*"]
588 || [istarget "i?86-*-gnu*"]
589 || [istarget "i?86-*-nacl*"]
590 || [istarget "x86_64-*-nacl*"]
591 || [istarget "x86_64-*-linux*"]
592 || [istarget "amd64-*-linux*"]) } {
593 set testname "PR ld/12365"
594 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"]
595 set exec_output [prune_warnings $exec_output]
596 if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
597 # Linker should catch the reference to undefined `my_bcopy'
598 # error caused by a GCC bug.
600 } elseif { [ string match "" $exec_output ] } {
602 set exec_output [run_host_cmd "$READELF" "-s -W tmpdir/pr12365"]
603 if { [ regexp "my_bcopy" $exec_output ] } {
604 # Verify that there is no `my_bcopy' symbol in executable.
613 run_cc_link_tests [list \
615 "Build pr22721a.so" \
616 "-shared -nostdlib -nostartfiles -Wl,-version-script,pr22721.t" \
625 "-O2 -fPIC -flto $lto_no_fat" \
629 "Build PR ld/pr22721" \
630 "-O2 -flto -fuse-linker-plugin -nostdlib -nostartfiles \
631 -Wl,-e,_start tmpdir/pr22721b.o tmpdir/pr22721a.so" \
639 set testname "PR ld/12942 (3)"
640 set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
641 if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
647 run_cc_link_tests [list \
651 "-O2 -fPIC -flto $lto_no_fat" \
652 {pr23460a.c pr23460b.c pr23460c.c \
653 pr23460d.c pr23460e.c pr23460f.c} \
656 set exec_output [run_host_cmd "sh" \
657 "-c \"ulimit -n 16; \
659 tmpdir/libpr23460.a \
665 tmpdir/pr23460f.o\""]
666 set exec_output [prune_warnings $exec_output]
667 if [string match "" $exec_output] then {
668 pass "PR binutils/23460"
670 fail "PR binutils/23460"
674 # Run "ld -r" to generate inputs for complex LTO tests.
675 run_dump_test "lto-3r"
676 remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
677 run_dump_test "lto-5r"
678 remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
680 run_cc_link_tests $lto_link_symbol_tests
682 run_ld_link_tests [list \
683 [list "PR ld/19317 (2)" \
684 "-r tmpdir/pr19317.o" "" "" \
685 {dummy.s} {} "pr19317-r.o"] \
688 run_ld_link_exec_tests $lto_run_tests
690 if { [is_elf_format] } {
691 run_ld_link_exec_tests $lto_run_elf_tests
693 # Note - it is not guaranteed that the ordering of symbols in the dynamic
694 # symbol table will match the ordering of the symbols specified by the
695 # --dynamic-list command line option.
697 # For PR22983 we want to make sure that all four symbols specified in
698 # pr222983.t are present in the output, but a simple sequences of regexps
699 # will not work as we do not know the order of the symbols. (Readelf
700 # does not have a symbol sorting option and the run_cc_list_tests proc
701 # does not allow for the output of the dump program to piped into `sort`).
703 # So instead we run readelf four times, each time checking for the
704 # presence of a specific symbol from the pr22983.t file.
705 run_cc_link_tests [list \
708 "-Wl,--dynamic-list,pr22983.t" \
710 {pr22983a.c pr22983b.c} \
711 {{readelf {--dyn-syms --wide} pr22983.1.d} \
712 {readelf {--dyn-syms --wide} pr22983.2.d} \
713 {readelf {--dyn-syms --wide} pr22983.3.d} \
714 {readelf {--dyn-syms --wide} pr22983.4.d}} \
720 if { [is_elf_format] && [check_lto_shared_available] } {
721 run_ld_link_exec_tests $lto_run_elf_shared_tests
724 proc pr20103 {cflags libs} {
727 set testname "PR ld/20103 ($cflags $libs)"
728 set exec_output [run_host_cmd "$CC" "$cflags $libs"]
729 if { [ regexp "undefined reference to `\\.?dead'" $exec_output ] } {
734 if { [ regexp "plugin needed to handle lto object" $exec_output ] } {
741 if { [check_lto_fat_available] } {
742 run_cc_link_tests [list \
744 "Build fatpr20103a.a" \
745 "$plug_opt" "-flto -ffat-lto-objects" \
746 {pr20103a.c} {} "fatpr20103a.a"
749 "Build fatpr20103b.a" \
750 "$plug_opt" "-flto -ffat-lto-objects" \
751 {pr20103b.c} {} "fatpr20103b.a"
754 "Build fatpr20103c.a" \
755 "$plug_opt" "-flto -ffat-lto-objects" \
756 {pr20103c.c} {} "fatpr20103c.a" \
759 "Build thinpr20103a.a" \
760 "$plug_opt" "-flto -fno-fat-lto-objects" \
761 {pr20103a.c} {} "thinpr20103a.a"
764 "Build thinpr20103b.a" \
765 "$plug_opt" "-flto -fno-fat-lto-objects" \
766 {pr20103b.c} {} "thinpr20103b.a"
769 "Build thinpr20103c.a" \
770 "$plug_opt" "-flto -fno-fat-lto-objects" \
771 {pr20103c.c} {} "thinpr20103c.a" \
775 "-O2 -flto -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
777 {dummy.c} {} "pr20103a" \
781 "-O2 -flto -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
783 {dummy.c} {} "pr20103b" \
787 "-O2 -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
789 {dummy.c} {} "pr20103c" \
792 pr20103 "-O2 -flto" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
793 pr20103 "-O2 -flto" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
794 pr20103 "-O2" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
796 if { [at_least_gcc_version 4 9] } {
797 run_cc_link_tests [list \
800 "-O2 -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
802 {dummy.c} {} "pr20103d" \
805 pr20103 "-O2" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"