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