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