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