]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-plugin/lto.exp
Handle symbol defined in IR and referenced in DSO
[thirdparty/binutils-gdb.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 ]
299
300 # Check final symbols in executables.
301 set lto_link_symbol_tests [list \
302 [list "LTO 3 symbol" \
303 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
304 {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"] \
305 [list "LTO 5 symbol" \
306 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
307 {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"] \
308 [list "LTO 9 symbol" \
309 "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" \
310 {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"] \
311 [list "LTO 16a symbol" \
312 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" "-flto" \
313 {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"] \
314 [list "LTO 16b symbol" \
315 "-O2 -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" "-flto" \
316 {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"] \
317 [list "PR ld/13183" \
318 "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" \
319 {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"] \
320 ]
321
322 # LTO run-time tests.
323 set lto_run_tests [list \
324 [list "LTO 3a" \
325 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
326 {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"] \
327 [list "LTO 3b" \
328 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" \
329 {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"] \
330 [list "LTO 3c" \
331 "-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" "" \
332 {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
333 [list "LTO 5" \
334 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
335 {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
336 [list "LTO 11" \
337 "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
338 {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
339 [list "LTO 12a" \
340 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" \
341 {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"] \
342 [list "LTO 12b" \
343 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" \
344 {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"] \
345 [list "LTO 13" \
346 "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" \
347 {dummy.c} "lto-13.exe" "lto-13.out" "" "c"] \
348 [list "LTO 14" \
349 "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" \
350 {dummy.c} "lto-14.exe" "lto-14.out" "" "c"] \
351 [list "LTO 15" \
352 "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" \
353 {dummy.c} "lto-15.exe" "lto-15.out" "" "c"] \
354 [list "PR ld/13066" \
355 "-O2 -flto -fuse-linker-plugin" "" \
356 {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"] \
357 [list "PR ld/13201" \
358 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" \
359 {dummy.c} "pr13201.exe" "pr13201.out" "" "c"] \
360 [list "PR ld/15323 (3)" \
361 "-O2 -flto -fuse-linker-plugin tmpdir/pr15323a.o" "" \
362 {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"] \
363 [list "PR ld/15323 (4)" \
364 "-O2 -flto tmpdir/pr15323a-r.o" "" \
365 {dummy.c} "pr15323a.exe" "pr15323.out" "-flto -O2" "c"] \
366 [list "PR ld/19317 (3)" \
367 "-O2 -flto tmpdir/pr19317-r.o" "" \
368 {dummy.c} "pr19317.exe" "pr19317.out" "-flto -O2" "c"] \
369 [list "Run pr20276" \
370 "-O2 -flto tmpdir/pr20276a.o tmpdir/pr20276b.o" "" \
371 {dummy.c} "pr20276" "pass.out" "-flto -O2" "c"] \
372 [list "Run pr20267a" \
373 "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267a.a" "" \
374 {dummy.c} "pr20267a" "pass.out" "-flto -O2" "c"] \
375 [list "Run pr20267b" \
376 "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \
377 {dummy.c} "pr20267b" "pass.out" "-flto -O2" "c"] \
378 ]
379
380 if { [at_least_gcc_version 4 7] } {
381 set lto_run_tests [concat $lto_run_tests [list \
382 [list "PR ld/12942 (1)" \
383 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" \
384 {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"] \
385 [list "PR ld/12942 (2)" \
386 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" \
387 {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"] \
388 ]]
389 }
390
391 # LTO run-time tests for ELF which require shared library support.
392 set lto_run_elf_shared_tests [list \
393 [list "LTO 7" \
394 "-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" "" \
395 {dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \
396 [list "Run pr21382" \
397 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr21382a.o tmpdir/pr21382.so" "" \
398 {dummy.c} "pr21382.exe" "pass.out" "" "c"] \
399 ]
400
401 # LTO run-time tests for ELF
402 set lto_run_elf_tests [list \
403 [list "LTO 8" \
404 "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \
405 {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \
406 [list "LTO TLS IE" \
407 "-O2 -flto -fuse-linker-plugin" "" \
408 {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \
409 ]
410
411 run_cc_link_tests $lto_link_tests
412
413 # These compilation tests generate intermediate object files which will be used
414 # by some elf tests besides shared libs tests. So, always compile them.
415 run_cc_link_tests $lto_compile_elf_tests
416
417 # Restrict these to ELF targets that support shared libs and PIC.
418 if { [is_elf_format] && [check_lto_shared_available] } {
419 run_cc_link_tests $lto_link_elf_tests
420 set testname "PR ld/15146 (2)"
421 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"]
422 if { [ regexp "undefined reference to symbol '\\.?xxx'" $exec_output ] } {
423 pass $testname
424 } {
425 fail $testname
426 }
427 set testname "PR ld/16746 (3)"
428 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
429 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
430 pass $testname
431 } {
432 fail $testname
433 }
434 set testname "PR ld/16746 (4)"
435 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
436 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
437 pass $testname
438 } {
439 fail $testname
440 }
441 }
442
443 set testname "Build liblto-11.a"
444 remote_file host delete "tmpdir/liblto-11.a"
445 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"]
446 if {![string match "" $catch_output]} {
447 unresolved $testname
448 restore_notify
449 return
450 }
451
452 if { [at_least_gcc_version 4 7] } {
453 # Check expected LTO linker errors.
454 # Since the asm symbol name hack in pr12365b.c doesn't work on all
455 # targets, run PR ld/12365 tests only for known targets.
456 if { ([istarget "i?86-*-elf*"]
457 || (([istarget "i?86-*-linux*"] || [istarget "i?86-*-gnu*"])
458 && ![istarget "*-*-*aout*"]
459 && ![istarget "*-*-*oldld*"])
460 || [istarget "i?86-*-nacl*"]
461 || [istarget "x86_64-*-nacl*"]
462 || [istarget "x86_64-*-linux*"]
463 || [istarget "amd64-*-linux*"]) } {
464 set testname "PR ld/12365"
465 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"]
466 if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
467 # Linker should catch the reference to undefined `my_bcopy'
468 # error caused by a GCC bug.
469 pass $testname
470 } elseif { [ string match "" $exec_output ] } {
471 global READELF
472 set exec_output [run_host_cmd "$READELF" "-s -W tmpdir/pr12365"]
473 if { [ regexp "my_bcopy" $exec_output ] } {
474 # Verify that there is no `my_bcopy' symbol in executable.
475 fail $testname
476 } {
477 pass $testname
478 }
479 } {
480 fail $testname
481 }
482 }
483 set testname "PR ld/12942 (3)"
484 set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
485 if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
486 pass $testname
487 } {
488 fail $testname
489 }
490 }
491
492 # Run "ld -r" to generate inputs for complex LTO tests.
493 run_dump_test "lto-3r"
494 remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
495 run_dump_test "lto-5r"
496 remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
497
498 run_cc_link_tests $lto_link_symbol_tests
499
500 run_ld_link_tests [list \
501 [list "PR ld/19317 (2)" \
502 "-r tmpdir/pr19317.o" "" "" \
503 {dummy.s} {} "pr19317-r.o"] \
504 ]
505
506 run_ld_link_exec_tests $lto_run_tests
507
508 if { [is_elf_format] } {
509 run_ld_link_exec_tests $lto_run_elf_tests
510 }
511
512 if { [is_elf_format] && [check_lto_shared_available] } {
513 run_ld_link_exec_tests $lto_run_elf_shared_tests
514 }
515
516 proc pr20103 {cflags libs} {
517 global CC
518
519 set testname "PR ld/20103 ($cflags $libs)"
520 set exec_output [run_host_cmd "$CC" "$cflags $libs"]
521 if { [ regexp "undefined reference to `\\.?dead'" $exec_output ] } {
522 pass "$testname (1)"
523 } {
524 fail "$testname (1)"
525 }
526 if { [ regexp "plugin needed to handle lto object" $exec_output ] } {
527 fail "$testname (2)"
528 } {
529 pass "$testname (2)"
530 }
531 }
532
533 if { [check_lto_fat_available] } {
534 run_cc_link_tests [list \
535 [list \
536 "Build fatpr20103a.a" \
537 "$plug_opt" "-flto -ffat-lto-objects" \
538 {pr20103a.c} {} "fatpr20103a.a"
539 ] \
540 [list \
541 "Build fatpr20103b.a" \
542 "$plug_opt" "-flto -ffat-lto-objects" \
543 {pr20103b.c} {} "fatpr20103b.a"
544 ] \
545 [list \
546 "Build fatpr20103c.a" \
547 "$plug_opt" "-flto -ffat-lto-objects" \
548 {pr20103c.c} {} "fatpr20103c.a" \
549 ] \
550 [list \
551 "Build thinpr20103a.a" \
552 "$plug_opt" "-flto -fno-fat-lto-objects" \
553 {pr20103a.c} {} "thinpr20103a.a"
554 ] \
555 [list \
556 "Build thinpr20103b.a" \
557 "$plug_opt" "-flto -fno-fat-lto-objects" \
558 {pr20103b.c} {} "thinpr20103b.a"
559 ] \
560 [list \
561 "Build thinpr20103c.a" \
562 "$plug_opt" "-flto -fno-fat-lto-objects" \
563 {pr20103c.c} {} "thinpr20103c.a" \
564 ] \
565 [list \
566 "Build pr20103a" \
567 "-O2 -flto -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
568 "-O2 -flto" \
569 {dummy.c} {} "pr20103a" \
570 ] \
571 [list \
572 "Build pr20103b" \
573 "-O2 -flto -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
574 "-O2 -flto" \
575 {dummy.c} {} "pr20103b" \
576 ] \
577 [list \
578 "Build pr20103c" \
579 "-O2 -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
580 "-O2" \
581 {dummy.c} {} "pr20103c" \
582 ] \
583 ]
584 pr20103 "-O2 -flto" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
585 pr20103 "-O2 -flto" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
586 pr20103 "-O2" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
587
588 if { [at_least_gcc_version 4 9] } {
589 run_cc_link_tests [list \
590 [list \
591 "Build pr20103d" \
592 "-O2 -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
593 "-O2" \
594 {dummy.c} {} "pr20103d" \
595 ] \
596 ]
597 pr20103 "-O2" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
598 }
599 }
600
601 restore_notify