]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-plugin/lto.exp
ld: Add a PR binutils/26389 test
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-plugin / lto.exp
1 # Expect script for ld-plugin LTO tests
2 # Copyright (C) 2011-2020 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 { ![check_compiler_available] || [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 set saved_CFLAGS "$CFLAGS"
33 set saved_CXXFLAGS "$CXXFLAGS"
34 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS
35 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS
36
37 proc restore_notify { } {
38 global saved_CFLAGS
39 global saved_CXXFLAGS
40 set CFLAGS "$saved_CFLAGS"
41 set CXXFLAGS "$saved_CXXFLAGS"
42 }
43
44 set plugin_names {
45 liblto_plugin.so
46 liblto_plugin-0.dll
47 cyglto_plugin-0.dll
48 }
49 set plug_opt ""
50 foreach plug $plugin_names {
51 set plug_so [run_host_cmd $CC "--print-prog-name $plug"]
52 if { $plug_so eq $plug } then {
53 set plug_so [run_host_cmd $CC "--print-file-name $plug"]
54 }
55 if { $plug_so ne $plug } then {
56 set plug_opt "--plugin $plug_so"
57 break
58 }
59 }
60 set lto_fat ""
61 set lto_no_fat ""
62 if { [check_lto_fat_available] } {
63 set lto_fat "-ffat-lto-objects"
64 set lto_no_fat "-fno-fat-lto-objects"
65 set no_lto "-fno-lto"
66 }
67
68 # Simple LTO tests and generate input files for complex LTO tests.
69 set lto_link_tests [list \
70 [list "LTO 1" \
71 "-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" \
72 {lto-1a.c lto-1b.c} {} "lto-1.exe"] \
73 [list "Compile 2" \
74 "" "-O2 -flto -fuse-linker-plugin $NOSANTIZE_CFLAGS" \
75 {lto-2.c} {} ""] \
76 [list "LTO 2" \
77 "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" \
78 "$NOSANTIZE_CFLAGS" \
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 "Compile PR ld/12365" \
96 "" "-flto -O2 $lto_fat" \
97 {pr12365a.c pr12365b.c pr12365c.c} {} ""] \
98 [list "Compile 9" \
99 "" "-O2 -finline -flto" \
100 {lto-9.cc} {} "" "c++"] \
101 [list "Compile 11a" \
102 "" "-O -flto" \
103 {lto-11a.c} {} ""] \
104 [list "Compile 11b" \
105 "" "-O -flto" \
106 {lto-11b.c} {} ""] \
107 [list "Compile 11c" \
108 "" "-O" \
109 {lto-11c.c} {} ""] \
110 [list "Build liblto-12.a" \
111 "$plug_opt" "-O2 -flto" \
112 {lto-12c.c} {} "liblto-12.a"] \
113 [list "Compile 12" \
114 "" "-O2 -flto" \
115 {lto-12a.c lto-12b.c} {} ""] \
116 [list "Compile 13" \
117 "" "-O2 -flto" \
118 {lto-13a.c lto-13b.c} {} ""] \
119 [list "Build liblto-13.a" \
120 "" "-O2" \
121 {lto-13c.c} {} "liblto-13.a"] \
122 [list "Compile 14a" \
123 "" "-flto" \
124 {lto-14a.c lto-14b.c} {} ""] \
125 [list "Build liblto-14.a" \
126 "$plug_opt" "-flto" \
127 {lto-14c.c} {} "liblto-14.a"] \
128 [list "Compile 15a" \
129 "" "-flto" \
130 {lto-15a.c} {} ""] \
131 [list "Build liblto-15.a" \
132 "$plug_opt" "-flto" \
133 {lto-15b.c} {} "liblto-15.a"] \
134 [list "PR ld/12696" \
135 "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" \
136 {pr12696-1.cc} {} "pr12696-1r.o" "c++"] \
137 [list "Compile PR ld/12758" \
138 "" "" \
139 {pr12758a.s} {} ""] \
140 [list "Build libpr12758.a" \
141 "" "-flto -O2 $lto_fat $NOSANTIZE_CFLAGS" \
142 {pr12758b.c} {} "libpr12758.a"] \
143 [list "PR ld/12758" \
144 "$NOPIE_LDFLAGS -O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" \
145 "$NOSANTIZE_CFLAGS" \
146 {dummy.c} {} "pr12758.exe"] \
147 [list "Build libpr13183.a" \
148 "-T" "-flto -O2 $lto_fat" \
149 {pr13183a.c} {} "libpr13183.a"] \
150 [list "Compile PR ld/13183" \
151 "" "-flto -O2" \
152 {pr13183b.c} {} ""] \
153 [list "Compile PR ld/13201" \
154 "" "-flto -O2" \
155 {pr13201.c} {} ""] \
156 [list "PR ld/13287" \
157 "-flto -fuse-linker-plugin -Wl,--as-needed" "-flto" \
158 {pr13287.cc} {} "pr13287.exe" "c++"] \
159 [list "PR ld/15323 (1)" \
160 "" "-O2" \
161 {pr15323a.c} {} "" "c"] \
162 [list "PR ld/15323 (2)" \
163 "-O2 -flto -r -nostdlib" "-O2 -flto" \
164 {pr15323a.c} {} "pr15323a-r.o" "c"] \
165 [list "Compile(1) PR ld/pr16846" \
166 "" "-flto" \
167 {pr16846a.c pr16846b.c} {} ""] \
168 [list "Compile(2) PR ld/pr16846" \
169 "" "" \
170 {pr16846c.c} {} ""] \
171 [list "PR ld/pr16846(1)" \
172 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846b.o tmpdir/pr16846c.o" "" \
173 {dummy.c} {} "pr16846a.exe"] \
174 [list "PR ld/pr16846(2)" \
175 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846c.o tmpdir/pr16846b.o" "" \
176 {dummy.c} {} "pr16846b.exe"] \
177 [list "PR ld/19317 (1)" \
178 "$plug_opt" "-flto $lto_no_fat" \
179 {pr19317.c} {} "libpr19317.a"] \
180 [list "Build pr20276a.o" \
181 "" "-fno-lto -fcommon" \
182 {pr20276a.c}] \
183 [list "Build pr20276b.o" \
184 "$plug_opt" "-flto $lto_no_fat -fcommon" \
185 {pr20276b.c}] \
186 [list "Build pr20267a.o" \
187 "" "-fcommon" \
188 {pr20267a.c}] \
189 [list "Build libpr20267a.a" \
190 "$plug_opt" "-flto $lto_fat -fcommon" \
191 {pr20267b.c} {} "libpr20267a.a"] \
192 [list "Build libpr20267b.a" \
193 "$plug_opt" "-flto $lto_no_fat -fcommon" \
194 {pr20267b.c} {} "libpr20267b.a"] \
195 [list "Build pr20321" \
196 "-flto -Wl,-plugin,$plug_so" "-flto" \
197 {pr20321.c} {{warning ".*: duplicated plugin"}} \
198 "pr20321" "c"] \
199 [list "Build pr22502a.o" \
200 "" "" \
201 {pr22502a.c}] \
202 [list "Build pr22502b.o" \
203 "$plug_opt" "-flto $lto_no_fat" \
204 {pr22502b.c}] \
205 [list "Build pr22751.a" \
206 "$plug_opt" "-flto $lto_no_fat $INT128_CFLAGS" \
207 {pr22751.c} {} "pr22751.a"] \
208 [list "Build pr24406-2b.o" \
209 "" "-O2 -fno-lto" \
210 {pr24406-2b.c}] \
211 [list "Build pr26163a.o" \
212 "" "-O2 -fno-lto" \
213 {pr26163a.c}] \
214 [list "Build pr26262b.o" \
215 "" "-O2" \
216 {pr26262b.c} {} "" "c"] \
217 [list "Build pr26262c.o" \
218 "" "-O2" \
219 {pr26262c.c} {} "" "c"] \
220 [list "Build pr26267a.o" \
221 "" "-O2 -flto $lto_no_fat" \
222 {pr26267a.c} {} "" "c"] \
223 [list "Build pr26267b.o" \
224 "" "-O2" \
225 {pr26267b.c} {} "" "c"] \
226 [list "Build pr26267c.o" \
227 "" "-O2" \
228 {pr26267c.c} {} "" "c"] \
229 [list "Build pr26267a" \
230 "" "-O2" \
231 {pr26267a.c} {} "" "c"] \
232 [list "Build pr26267a" \
233 "-flto tmpdir/pr26267a.o tmpdir/pr26267b.o tmpdir/pr26267c.o" \
234 "-flto $lto_no_fat" \
235 {dummy.c} \
236 {{error_output "pr26267.err"}} \
237 "pr26267a"] \
238 [list "Build pr26267b" \
239 "-flto tmpdir/pr26267b.o tmpdir/pr26267c.o tmpdir/pr26267a.o" \
240 "-flto $lto_no_fat" \
241 {dummy.c} \
242 {{error_output "pr26267.err"}} \
243 "pr26267b"] \
244 [list "Build pr26389.o" \
245 "$plug_opt" "-flto $lto_no_fat -fcommon" \
246 {pr26389.c} \
247 [list [list "nm" "$plug_opt" "pr26389.d"]]] \
248 ]
249
250 if { [at_least_gcc_version 10 0] } {
251 set lto_link_tests [concat $lto_link_tests [list \
252 [list "pr25355.o" \
253 "" \
254 "-flto -fno-common $lto_no_fat" \
255 {pr25355.c} \
256 [list [list "nm" "$plug_opt" "pr25355.d"]]] \
257 ]]
258 }
259
260 if { [at_least_gcc_version 4 7] } {
261 set lto_link_tests [concat $lto_link_tests [list \
262 [list "Compile PR ld/12942 (1)" \
263 "" "-flto -O2" \
264 {pr12942a.cc pr12942c.cc} {} "" "c++"] \
265 [list "Compile PR ld/12942 (2)" \
266 "" "-O0" \
267 {pr12942b.cc} {} "" "c++"] \
268 ]]
269 }
270
271 set lto_compile_elf_tests [list \
272 [list "Compile 7" \
273 "" "-flto -O2" \
274 {lto-7a.c lto-7b.c lto-7c.c} {} ""] \
275 [list "Compile 8a" \
276 "" "-O2" \
277 {lto-8a.c} {} ""] \
278 [list "Compile 8b" \
279 "" "-flto -O2" \
280 {lto-8b.c} {} ""] \
281 [list "PR ld/23309" \
282 "-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections -Wl,--gc-sections,-u,KeepMe" \
283 "-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections" \
284 {pr23309.c} {{"nm" {} "pr23309.d"}} "pr23309.exe" "c"] \
285 ]
286
287 # Generate input files for complex LTO tests for ELF.
288 set lto_link_elf_tests [list \
289 [list "LTO 6" \
290 "-O2 -flto -fuse-linker-plugin" "" \
291 {lto-6.c} {} "lto-6.exe" "c"] \
292 [list "Build liblto-7.so" \
293 "-shared" "-O2 -fpic" \
294 {lto-7d.c} {} "liblto-7.so" "c"] \
295 [list "Build liblto-17a.so" \
296 "-shared -O2 -fpic -flto -fuse-linker-plugin" "-O2 -fpic -flto" \
297 {lto-17a.c} {{"nm" {} "lto-17a.d"}} "liblto-17a.so" "c"] \
298 [list "Build liblto-17b.so 1" \
299 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
300 {lto-17b.c} {{"nm" {} "lto-17b-1.d"}} "liblto-17b.so"] \
301 [list "Build liblto-17b.so 2" \
302 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
303 {lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"] \
304 [list "Compile PR ld/12760" \
305 "" "-g -O0" \
306 {pr12760a.c} {} ""] \
307 [list "Build libpr12760.a" \
308 "" "-flto -O2 $lto_fat" \
309 {pr12760b.c} {} "libpr12760.a"] \
310 [list "PR ld/12760" \
311 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" \
312 {dummy.c} {{warning "pr12760a.c:6: warning: Bad \\.?bar"}} \
313 "pr12760.exe" "c"] \
314 [list "PR ld/12975" \
315 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \
316 {pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"] \
317 [list "PR ld/13229" \
318 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -finline -fno-early-inlining -flto" \
319 {pr13229.cc} {{"readelf" {-s --wide} "pr13229.d"}} "pr13229.so" "c++"] \
320 [list "PR ld/13244" \
321 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \
322 {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \
323 [list "Build libpr15146a.a" \
324 "$plug_opt" "-flto -O2" \
325 {pr15146a.c} {} "lib15146a.a"] \
326 [list "Build pr15146b.so" \
327 "-shared" "-O2 -fpic" \
328 {pr15146b.c} {} "pr15146b.so" "c"] \
329 [list "Build pr15146c.so" \
330 "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic $no_lto" \
331 {pr15146c.c} {} "pr15146c.so" "c"] \
332 [list "PR ld/15146 (1)" \
333 "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \
334 {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"] \
335 [list "Build libpr15146d.a" \
336 "$plug_opt" "-flto -O2" \
337 {pr15146d.c} {} "lib15146d.a"] \
338 [list "Build libpr16746a.a" \
339 "" "" \
340 {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
341 [list "Build libpr16746b.a" \
342 "$plug_opt" "-O2 -flto" \
343 {pr16746c.c pr16746d.c} {} "lib15146b.a"] \
344 [list "PR ld/16746 (1)" \
345 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \
346 {dummy.c} {} "pr16746a.exe"] \
347 [list "PR ld/16746 (2)" \
348 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto" \
349 {dummy.c} {} "pr16746b.exe"] \
350 [list "Build pr21382a.o" \
351 "" "-O2 -flto" \
352 {pr21382a.c} {} "" "c"] \
353 [list "Build pr21382.so" \
354 "-shared" "-O2 -fpic" \
355 {pr21382b.c} {} "pr21382.so" "c"] \
356 [list {Build pr22220lib.so} \
357 {-shared -Wl,--version-script=pr22220lib.ver} {-fPIC} \
358 {pr22220lib.cc} {} {pr22220lib.so} {c++}] \
359 [list {Build pr22220main.o} \
360 {} {-flto} \
361 {pr22220main.cc} {} {} {c++}] \
362 [list "Build libpr23818.so" \
363 "-shared -flto -g -Wl,-version-script,pr23818.t" \
364 "-g -flto $lto_fat" \
365 {pr23818a.c pr23818b.c} \
366 {{"readelf" {-s --wide} "pr23818.d"}} \
367 "libpr23818.so"] \
368 [list "Build libpr23958.so" \
369 "-shared -flto -Wl,-version-script,pr23958.t" \
370 "-g -flto $lto_fat" \
371 {pr23958.c} \
372 "" \
373 "libpr23958.so"] \
374 [list "Build pr24486a.o" \
375 "$plug_opt" "-flto -O2" \
376 {pr24486a.c} {} "" "c"] \
377 [list "Build pr24486b.so" \
378 "-shared" "-O2 -fpic" \
379 {pr24486b.c} {} "pr24486b.so" "c"] \
380 [list "Build pr24486c.so" \
381 "-shared -Wl,--no-as-needed tmpdir/pr24486b.so" "-O2 -fpic" \
382 {pr24486c.c} {} "pr24486c.so" "c"] \
383 [list "PR ld/24486" \
384 "-O2 -flto tmpdir/pr24486a.o tmpdir/pr24486c.so -Wl,--as-needed tmpdir/pr24486b.so" "" \
385 {dummy.c} {} "pr24486.exe"] \
386 [list "Build pr25593a-1.o" \
387 "$plug_opt" "-flto -O2" \
388 {pr25593a-1.c} {} "" "c"] \
389 [list "Build pr25593a-2.o" \
390 "" "-O2" \
391 {pr25593a-2.c} {} "" "c"] \
392 [list "Build pr25593b.o" \
393 "" "-O2" \
394 {pr25593b.c} {} "" "c"] \
395 [list "Build pr25593c.so" \
396 "-shared" "-O2 -fpic" \
397 {pr25593c.c} {} "pr25593c.so" "c"] \
398 [list "Build pr25593d.so" \
399 "-shared" "-O2 -fpic" \
400 {pr25593d.c} {} "pr25593d.so" "c"] \
401 [list "Build pr25593e.so" \
402 "-shared" "-O2 -fpic" \
403 {pr25593e.c} {} "pr25593e.so" "c"] \
404 [list "PR ld/r25593 (LTO)" \
405 "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-1.o tmpdir/pr25593b.o \
406 tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
407 {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593a.exe"] \
408 [list "PR ld/r25593" \
409 "-O2 -flto -Wl,--as-needed tmpdir/pr25593a-2.o tmpdir/pr25593b.o \
410 tmpdir/pr25593c.so tmpdir/pr25593d.so tmpdir/pr25593e.so" "" \
411 {dummy.c} {{readelf {-d --wide} pr25593.d}} "pr25593b.exe"] \
412 [list "Build pr25618a.o" \
413 "$plug_opt" "-O2 -flto -fpic" \
414 {pr25618a.cc} {} "" "c++"] \
415 [list "Build pr25618.a" \
416 "$plug_opt" "-O2 -flto -fpic" \
417 {pr25618b.cc} {} "pr25618.a" "c++"] \
418 [list "Build pr25618.so" \
419 "-shared -Wl,--exclude-libs,ALL tmpdir/pr25618a.o tmpdir/pr25618.a" \
420 "-fpic" \
421 {dummy.c} {{readelf {--dyn-syms --wide} pr25618.d}} "pr25618.so" "c++"] \
422 ]
423
424 # PR 14918 checks that libgcc is not spuriously included in a shared link of
425 # an empty program. The ARM crt1.o startup code however calls __libc_csu_init
426 # in /usr/lib/libc_nonshared.a(elf-init.oS). This in turn needs
427 # __aeabi_unwind_cpp_pr0@@GCC_3.5 which is provided by libgcc_s.so.1, so the
428 # test fails. Hence this code to skip the test.
429 if { ! [istarget "arm*-*-*"] } {
430 set lto_link_elf_tests [concat $lto_link_elf_tests [list \
431 [list "PR ld/14918" \
432 "-flto" "-flto" \
433 {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \
434 ]]
435 }
436
437 # PR 12982 checks that an executable stack is not created by default
438 # when using the LTO plugin. The HPPA target however requires an
439 # executable stack for syscall restarts and signal returns, so we
440 # skip this test for that target.
441 if { ! [istarget "hppa*-*-*"] } {
442 set lto_link_elf_tests [concat $lto_link_elf_tests [list \
443 [list "PR ld/12982" \
444 "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
445 {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
446 ]]
447 }
448
449 # Check final symbols in executables.
450 set lto_link_symbol_tests [list \
451 [list "LTO 3 symbol" \
452 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
453 {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"] \
454 [list "LTO 5 symbol" \
455 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
456 {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"] \
457 [list "LTO 9 symbol" \
458 "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" \
459 {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"] \
460 [list "LTO 16a symbol" \
461 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" "-flto" \
462 {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"] \
463 [list "LTO 16b symbol" \
464 "-O2 -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" "-flto" \
465 {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"] \
466 [list "PR ld/13183" \
467 "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" \
468 {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"] \
469 ]
470
471 # LTO run-time tests.
472 set lto_run_tests [list \
473 [list "LTO 3a" \
474 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
475 {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"] \
476 [list "LTO 3b" \
477 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" \
478 {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"] \
479 [list "LTO 3c" \
480 "-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" "" \
481 {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
482 [list "LTO 5" \
483 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
484 {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
485 [list "LTO 11" \
486 "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
487 {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
488 [list "LTO 12a" \
489 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" \
490 {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"] \
491 [list "LTO 12b" \
492 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" \
493 {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"] \
494 [list "LTO 13" \
495 "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" \
496 {dummy.c} "lto-13.exe" "lto-13.out" "" "c"] \
497 [list "LTO 14" \
498 "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" \
499 {dummy.c} "lto-14.exe" "lto-14.out" "" "c"] \
500 [list "LTO 15" \
501 "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" \
502 {dummy.c} "lto-15.exe" "lto-15.out" "" "c"] \
503 [list "PR ld/13066" \
504 "-O2 -flto -fuse-linker-plugin" "" \
505 {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"] \
506 [list "PR ld/13201" \
507 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" \
508 {dummy.c} "pr13201.exe" "pr13201.out" "" "c"] \
509 [list "PR ld/15323 (3)" \
510 "-O2 -flto -fuse-linker-plugin tmpdir/pr15323a.o" "" \
511 {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"] \
512 [list "PR ld/15323 (4)" \
513 "-O2 -flto tmpdir/pr15323a-r.o" "" \
514 {dummy.c} "pr15323a.exe" "pr15323.out" "-flto -O2" "c"] \
515 [list "PR ld/19317 (3)" \
516 "-O2 -flto tmpdir/pr19317-r.o" "" \
517 {dummy.c} "pr19317.exe" "pr19317.out" "-flto -O2" "c"] \
518 [list "Run pr20276" \
519 "-O2 -flto tmpdir/pr20276a.o tmpdir/pr20276b.o" "" \
520 {dummy.c} "pr20276" "pass.out" "-flto -O2" "c"] \
521 [list "Run pr20267a" \
522 "-O2 -flto -fcommon tmpdir/pr20267a.o tmpdir/libpr20267a.a" "" \
523 {dummy.c} "pr20267a" "pass.out" "-flto -O2 -fcommon" "c"] \
524 [list "Run pr20267b" \
525 "-O2 -flto -fcommon tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \
526 {dummy.c} "pr20267b" "pass.out" "-flto -O2 -fcommon" "c"] \
527 [list "Run pr22502" \
528 "-O2 -flto tmpdir/pr22502a.o tmpdir/pr22502b.o" "" \
529 {dummy.c} "pr20267" "pass.out" "-flto -O2 -fcommon" "c"] \
530 [list "Run pr22751" \
531 "-O2 -flto" "" \
532 {dummy.c} "pr22751" "pass.out" "-flto -O2" "c" "" \
533 "-Wl,--whole-archive tmpdir/pr22751.a -Wl,--no-whole-archive"] \
534 [list "Run pr24406-1" \
535 "-O2 -flto" "" \
536 {pr24406-1.c} "pr24406-1" "pass.out" "-flto -O2" "c" "" \
537 "-Wl,--wrap=read"] \
538 [list "Run pr24406-2" \
539 "-O2 -flto" "" \
540 {pr24406-2a.c} "pr24406-2" "pass.out" \
541 "-flto -O2" "c" "" \
542 "tmpdir/pr24406-2b.o -Wl,--wrap=cook"] \
543 [list "Run pr26163" \
544 "-O2 -flto" "" \
545 {pr26163b.c} "pr24406-2" "pass.out" \
546 "-flto -O2" "c" "" \
547 "tmpdir/pr26163a.o -Wl,--defsym,g=real_g"] \
548 [list "Run pr26262a" \
549 "-O2 -flto" "" \
550 {pr26262a.c} "pr26262a" "pass.out" \
551 "-flto -O2" "c" "" \
552 "tmpdir/pr26262b.o tmpdir/pr26262c.o"] \
553 [list "Run pr26262b" \
554 "-flto -O2 tmpdir/pr26262b.o tmpdir/pr26262c.o" "" \
555 {pr26262a.c} "pr26262b" "pass.out" \
556 "-flto -O2" "c" "" \
557 ""] \
558 ]
559
560 if { [at_least_gcc_version 4 7] } {
561 set lto_run_tests [concat $lto_run_tests [list \
562 [list "PR ld/12942 (1)" \
563 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" \
564 {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"] \
565 [list "PR ld/12942 (2)" \
566 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" \
567 {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"] \
568 ]]
569 }
570
571 # LTO run-time tests for ELF which require shared library support.
572 set lto_run_elf_shared_tests [list \
573 [list "LTO 7" \
574 "-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" "" \
575 {dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \
576 [list "Run pr21382" \
577 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr21382a.o tmpdir/pr21382.so" "" \
578 {dummy.c} "pr21382.exe" "pass.out" "" "c"] \
579 [list {pr22220a} \
580 {-flto -fuse-linker-plugin tmpdir/pr22220main.o tmpdir/pr22220lib.so} {} \
581 {dummy.c} {pr22220a.exe} {pass.out} {} {c++}] \
582 [list {pr22220b} \
583 {-flto -fuse-linker-plugin -Wl,--no-as-needed tmpdir/pr22220lib.so tmpdir/pr22220main.o} {} \
584 {dummy.c} {pr22220b.exe} {pass.out} {} {c++}] \
585 ]
586
587 # LTO run-time tests for ELF
588 set lto_run_elf_tests [list \
589 [list "LTO 8" \
590 "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \
591 {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \
592 [list "LTO TLS IE" \
593 "-O2 -flto -fuse-linker-plugin" "" \
594 {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \
595 ]
596
597 run_cc_link_tests $lto_link_tests
598
599 # These compilation tests generate intermediate object files which will be used
600 # by some elf tests besides shared libs tests. So, always compile them.
601 run_cc_link_tests $lto_compile_elf_tests
602
603 # Restrict these to ELF targets that support shared libs and PIC.
604 if { [is_elf_format] && [check_lto_shared_available] } {
605 run_cc_link_tests $lto_link_elf_tests
606 set testname "PR ld/15146 (2)"
607 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"]
608 if { [ regexp "undefined reference to symbol '\\.?xxx'" $exec_output ] } {
609 pass $testname
610 } {
611 fail $testname
612 }
613 set testname "PR ld/16746 (3)"
614 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
615 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
616 pass $testname
617 } {
618 fail $testname
619 }
620 set testname "PR ld/16746 (4)"
621 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
622 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
623 pass $testname
624 } {
625 fail $testname
626 }
627 }
628
629 set testname "Build liblto-11.a"
630 remote_file host delete "tmpdir/liblto-11.a"
631 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"]
632 if {![string match "" $catch_output]} {
633 unresolved $testname
634 restore_notify
635 return
636 }
637
638 if { [at_least_gcc_version 4 7] } {
639 # Check expected LTO linker errors.
640 # Since the asm symbol name hack in pr12365b.c doesn't work on all
641 # targets, run PR ld/12365 tests only for known targets.
642 if { ([istarget "i?86-*-elf*"]
643 || [istarget "i?86-*-linux*"]
644 || [istarget "i?86-*-gnu*"]
645 || [istarget "x86_64-*-linux*"]
646 || [istarget "amd64-*-linux*"]) } {
647 set testname "PR ld/12365"
648 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"]
649 set exec_output [prune_warnings $exec_output]
650 if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
651 # Linker should catch the reference to undefined `my_bcopy'
652 # error caused by a GCC bug.
653 pass $testname
654 } elseif { [ string match "" $exec_output ] } {
655 global READELF
656 set exec_output [run_host_cmd "$READELF" "-s -W tmpdir/pr12365"]
657 if { [ regexp "my_bcopy" $exec_output ] } {
658 # Verify that there is no `my_bcopy' symbol in executable.
659 fail $testname
660 } {
661 pass $testname
662 }
663 } {
664 fail $testname
665 }
666
667 run_cc_link_tests [list \
668 [list \
669 "Build pr22721a.so" \
670 "-shared -nostdlib -nostartfiles -Wl,-version-script,pr22721.t" \
671 "" \
672 {pr22721a.s} \
673 {} \
674 "pr22721a.so" \
675 ] \
676 [list \
677 "Build pr22721b.o" \
678 "$plug_opt" \
679 "-O2 -fPIC -flto $lto_no_fat" \
680 {pr22721b.c} \
681 ] \
682 [list \
683 "Build PR ld/pr22721" \
684 "-O2 -flto -fuse-linker-plugin -nostdlib -nostartfiles \
685 -Wl,-e,_start tmpdir/pr22721b.o tmpdir/pr22721a.so" \
686 "" \
687 {dummy.c} \
688 {} \
689 "pr22721.exe"
690 ] \
691 ]
692 }
693 set testname "PR ld/12942 (3)"
694 set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
695 if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
696 pass $testname
697 } {
698 fail $testname
699 }
700
701 run_cc_link_tests [list \
702 [list \
703 "Build pr23460*.o" \
704 "$plug_opt" \
705 "-O2 -fPIC -flto $lto_no_fat" \
706 {pr23460a.c pr23460b.c pr23460c.c \
707 pr23460d.c pr23460e.c pr23460f.c} \
708 ] \
709 ]
710 set exec_output [run_host_cmd "sh" \
711 "-c \"ulimit -n 16; \
712 $ar -rc $plug_opt \
713 tmpdir/libpr23460.a \
714 tmpdir/pr23460a.o \
715 tmpdir/pr23460b.o \
716 tmpdir/pr23460c.o \
717 tmpdir/pr23460d.o \
718 tmpdir/pr23460e.o \
719 tmpdir/pr23460f.o\""]
720 set exec_output [prune_warnings $exec_output]
721 if [string match "" $exec_output] then {
722 pass "PR binutils/23460"
723 } else {
724 fail "PR binutils/23460"
725 }
726 }
727
728 # Run "ld -r" to generate inputs for complex LTO tests.
729 run_dump_test "lto-3r"
730 remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
731 run_dump_test "lto-5r"
732 remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
733
734 run_cc_link_tests $lto_link_symbol_tests
735
736 run_ld_link_tests [list \
737 [list "PR ld/19317 (2)" \
738 "-r tmpdir/pr19317.o" "" "" \
739 {dummy.s} {} "pr19317-r.o"] \
740 ]
741
742 run_ld_link_exec_tests $lto_run_tests
743
744 if { [is_elf_format] } {
745 run_ld_link_exec_tests $lto_run_elf_tests
746
747 # Note - it is not guaranteed that the ordering of symbols in the dynamic
748 # symbol table will match the ordering of the symbols specified by the
749 # --dynamic-list command line option.
750 #
751 # For PR22983 we want to make sure that all four symbols specified in
752 # pr222983.t are present in the output, but a simple sequences of regexps
753 # will not work as we do not know the order of the symbols. (Readelf
754 # does not have a symbol sorting option and the run_cc_list_tests proc
755 # does not allow for the output of the dump program to piped into `sort`).
756 #
757 # So instead we run readelf four times, each time checking for the
758 # presence of a specific symbol from the pr22983.t file.
759 run_cc_link_tests [list \
760 [list \
761 "Build pr22983" \
762 "-Wl,--dynamic-list,pr22983.t" \
763 "-flto" \
764 {pr22983a.c pr22983b.c} \
765 {{readelf {--dyn-syms --wide} pr22983.1.d} \
766 {readelf {--dyn-syms --wide} pr22983.2.d} \
767 {readelf {--dyn-syms --wide} pr22983.3.d} \
768 {readelf {--dyn-syms --wide} pr22983.4.d}} \
769 "pr22983" \
770 ] \
771 ]
772 }
773
774 if { [is_elf_format] && [check_lto_shared_available] } {
775 run_ld_link_exec_tests $lto_run_elf_shared_tests
776 }
777
778 proc pr20103 {cflags libs} {
779 global CC
780
781 set testname "PR ld/20103 ($cflags $libs)"
782 set exec_output [run_host_cmd "$CC" "$cflags $libs"]
783 if { [ regexp "undefined reference to `\\.?dead'" $exec_output ] } {
784 pass "$testname (1)"
785 } {
786 fail "$testname (1)"
787 }
788 if { [ regexp "plugin needed to handle lto object" $exec_output ] } {
789 fail "$testname (2)"
790 } {
791 pass "$testname (2)"
792 }
793 }
794
795 if { [check_lto_fat_available] } {
796 run_cc_link_tests [list \
797 [list \
798 "Build fatpr20103a.a" \
799 "$plug_opt" "-flto -ffat-lto-objects" \
800 {pr20103a.c} {} "fatpr20103a.a"
801 ] \
802 [list \
803 "Build fatpr20103b.a" \
804 "$plug_opt" "-flto -ffat-lto-objects" \
805 {pr20103b.c} {} "fatpr20103b.a"
806 ] \
807 [list \
808 "Build fatpr20103c.a" \
809 "$plug_opt" "-flto -ffat-lto-objects" \
810 {pr20103c.c} {} "fatpr20103c.a" \
811 ] \
812 [list \
813 "Build thinpr20103a.a" \
814 "$plug_opt" "-flto -fno-fat-lto-objects" \
815 {pr20103a.c} {} "thinpr20103a.a"
816 ] \
817 [list \
818 "Build thinpr20103b.a" \
819 "$plug_opt" "-flto -fno-fat-lto-objects" \
820 {pr20103b.c} {} "thinpr20103b.a"
821 ] \
822 [list \
823 "Build thinpr20103c.a" \
824 "$plug_opt" "-flto -fno-fat-lto-objects" \
825 {pr20103c.c} {} "thinpr20103c.a" \
826 ] \
827 [list \
828 "Build pr20103a" \
829 "-O2 -flto -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
830 "-O2 -flto" \
831 {dummy.c} {} "pr20103a" \
832 ] \
833 [list \
834 "Build pr20103b" \
835 "-O2 -flto -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
836 "-O2 -flto" \
837 {dummy.c} {} "pr20103b" \
838 ] \
839 [list \
840 "Build pr20103c" \
841 "-O2 -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
842 "-O2" \
843 {dummy.c} {} "pr20103c" \
844 ] \
845 ]
846 pr20103 "-O2 -flto" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
847 pr20103 "-O2 -flto" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
848 pr20103 "-O2" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
849
850 if { [at_least_gcc_version 4 9] } {
851 run_cc_link_tests [list \
852 [list \
853 "Build pr20103d" \
854 "-O2 -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
855 "-O2" \
856 {dummy.c} {} "pr20103d" \
857 ] \
858 ]
859 pr20103 "-O2" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
860 }
861 }
862
863 restore_notify