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