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