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