Detect invalid length field in debug frame FDE header.
[deliverable/binutils-gdb.git] / ld / testsuite / ld-plugin / lto.exp
CommitLineData
af55061b 1# Expect script for ld-plugin LTO tests
82704155 2# Copyright (C) 2011-2019 Free Software Foundation, Inc.
af55061b
L
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
47523653 21# Check to see if the C and C++ compilers work
44ed8092 22if { ![check_compiler_available] || [which $CXX] == 0 } {
4ce6ca2c
AM
23 return
24}
25
af55061b
L
26# These tests require plugin and LTO.
27if { ![check_plugin_api_available]
28 || ![check_lto_available] } {
29 return
30}
31
fef75122
L
32global INT128_CFLAGS
33
af55061b
L
34global CFLAGS
35global CXXFLAGS
36set saved_CFLAGS "$CFLAGS"
37set saved_CXXFLAGS "$CXXFLAGS"
17c34b8f
AS
38regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS
39regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS
af55061b
L
40
41proc restore_notify { } {
42 global saved_CFLAGS
43 global saved_CXXFLAGS
44 set CFLAGS "$saved_CFLAGS"
45 set CXXFLAGS "$saved_CXXFLAGS"
46}
47
c3e11cbe
AM
48set plugin_names {
49 liblto_plugin.so
50 liblto_plugin-0.dll
51 cyglto_plugin-0.dll
af55061b 52}
c3e11cbe
AM
53set plug_opt ""
54foreach plug $plugin_names {
4dea914e
AM
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 }
c3e11cbe
AM
59 if { $plug_so ne $plug } then {
60 set plug_opt "--plugin $plug_so"
61 break
62 }
63}
64set lto_fat ""
c5847ba7 65set lto_no_fat ""
c3e11cbe
AM
66if { [check_lto_fat_available] } {
67 set lto_fat "-ffat-lto-objects"
c5847ba7 68 set lto_no_fat "-fno-fat-lto-objects"
c3e11cbe
AM
69}
70
71# Simple LTO tests and generate input files for complex LTO tests.
72set 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"] \
60f79275
L
100 [list "Compile PR ld/12365" \
101 "" "-flto -O2 $lto_fat" \
102 {pr12365a.c pr12365b.c pr12365c.c} {} ""] \
c3e11cbe
AM
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" "" \
2bd7f877
AB
159 {dummy.c} {{warning "pr12760a.c:6: warning: Bad \\.?bar"}} \
160 "pr12760.exe" "c"] \
c3e11cbe
AM
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++"] \
6d636d8c 173 [list "PR ld/15323 (1)" \
c3e11cbe
AM
174 "" "-O2" \
175 {pr15323a.c} {} "" "c"] \
6d636d8c
L
176 [list "PR ld/15323 (2)" \
177 "-O2 -flto -r -nostdlib" "-O2 -flto" \
178 {pr15323a.c} {} "pr15323a-r.o" "c"] \
c3e11cbe
AM
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"] \
c5847ba7
L
191 [list "PR ld/19317 (1)" \
192 "$plug_opt" "-flto $lto_no_fat" \
193 {pr19317.c} {} "libpr19317.a"] \
0616a280
AM
194 [list "Build pr20276a.o" \
195 "" "-fno-lto" \
196 {pr20276a.c}] \
197 [list "Build pr20276b.o" \
198 "$plug_opt" "-flto $lto_no_fat" \
199 {pr20276b.c}] \
7dc3990e
L
200 [list "Build pr20267a.o" \
201 "" "" \
202 {pr20267a.c}] \
203 [list "Build libpr20267a.a" \
204 "$plug_opt" "-flto $lto_fat" \
205 {pr20267b.c} {} "libpr20267a.a"] \
206 [list "Build libpr20267b.a" \
207 "$plug_opt" "-flto $lto_no_fat" \
208 {pr20267b.c} {} "libpr20267b.a"] \
c3e1c28e 209 [list "Build pr20321" \
29d7478b 210 "-flto -Wl,-plugin,$plug_so" "-flto" \
2bd7f877
AB
211 {pr20321.c} {{warning ".*: duplicated plugin"}} \
212 "pr20321" "c"] \
a83ef4d1
L
213 [list "Build pr22502a.o" \
214 "" "" \
215 {pr22502a.c}] \
216 [list "Build pr22502b.o" \
217 "$plug_opt" "-flto $lto_no_fat" \
218 {pr22502b.c}] \
fef75122
L
219 [list "Build pr22751.a" \
220 "$plug_opt" "-flto $lto_no_fat $INT128_CFLAGS" \
221 {pr22751.c} {} "pr22751.a"] \
0a640d71
L
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"] \
fbcc8baf
L
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"] \
c3e11cbe 234]
af55061b 235
2810e26c 236if { [at_least_gcc_version 4 7] } {
c3e11cbe
AM
237 set lto_link_tests [concat $lto_link_tests [list \
238 [list "Compile PR ld/12942 (1)" \
239 "" "-flto -O2" \
240 {pr12942a.cc pr12942c.cc} {} "" "c++"] \
241 [list "Compile PR ld/12942 (2)" \
242 "" "-O0" \
243 {pr12942b.cc} {} "" "c++"] \
244 ]]
2810e26c
WN
245}
246
077c11e8 247set lto_compile_elf_tests [list \
c3e11cbe
AM
248 [list "Compile 7" \
249 "" "-flto -O2" \
250 {lto-7a.c lto-7b.c lto-7c.c} {} ""] \
c3e11cbe
AM
251 [list "Compile 8a" \
252 "" "-O2" \
253 {lto-8a.c} {} ""] \
254 [list "Compile 8b" \
255 "" "-flto -O2" \
256 {lto-8b.c} {} ""] \
94d401b8
L
257 [list "PR ld/23309" \
258 "-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections -Wl,--gc-sections,-u,KeepMe" \
259 "-O2 -flto -fuse-linker-plugin -fvisibility=hidden -ffunction-sections" \
260 {pr23309.c} {{"nm" {} "pr23309.d"}} "pr23309.exe" "c"] \
077c11e8
JW
261]
262
263# Generate input files for complex LTO tests for ELF.
264set lto_link_elf_tests [list \
265 [list "Build liblto-7.so" \
266 "-shared" "-O2 -fpic" \
267 {lto-7d.c} {} "liblto-7.so" "c"] \
c3e11cbe
AM
268 [list "Build liblto-17a.so" \
269 "-shared -O2 -fpic -flto -fuse-linker-plugin" "-O2 -fpic -flto" \
270 {lto-17a.c} {{"nm" {} "lto-17a.d"}} "liblto-17a.so" "c"] \
271 [list "Build liblto-17b.so 1" \
272 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
273 {lto-17b.c} {{"nm" {} "lto-17b-1.d"}} "liblto-17b.so"] \
274 [list "Build liblto-17b.so 2" \
275 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
276 {lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"] \
c3e11cbe
AM
277 [list "PR ld/12975" \
278 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \
279 {pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"] \
280 [list "PR ld/13229" \
281 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -finline -fno-early-inlining -flto" \
282 {pr13229.cc} {{"readelf" {-s --wide} "pr13229.d"}} "pr13229.so" "c++"] \
283 [list "PR ld/13244" \
284 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \
285 {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \
286 [list "Build libpr15146a.a" \
287 "$plug_opt" "-flto -O2" \
288 {pr15146a.c} {} "lib15146a.a"] \
289 [list "Build pr15146b.so" \
290 "-shared" "-O2 -fpic" \
291 {pr15146b.c} {} "pr15146b.so" "c"] \
292 [list "Build pr15146c.so" \
293 "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic" \
294 {pr15146c.c} {} "pr15146c.so" "c"] \
295 [list "PR ld/15146 (1)" \
296 "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \
297 {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"] \
298 [list "Build libpr15146d.a" \
299 "$plug_opt" "-flto -O2" \
300 {pr15146d.c} {} "lib15146d.a"] \
db712946
L
301 [list "Build libpr16746a.a" \
302 "" "" \
303 {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
304 [list "Build libpr16746b.a" \
305 "$plug_opt" "-O2 -flto" \
306 {pr16746c.c pr16746d.c} {} "lib15146b.a"] \
307 [list "PR ld/16746 (1)" \
308 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \
309 {dummy.c} {} "pr16746a.exe"] \
310 [list "PR ld/16746 (2)" \
311 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto" \
312 {dummy.c} {} "pr16746b.exe"] \
59fa66c5
L
313 [list "Build pr21382a.o" \
314 "" "-O2 -flto" \
315 {pr21382a.c} {} "" "c"] \
316 [list "Build pr21382.so" \
317 "-shared" "-O2 -fpic" \
318 {pr21382b.c} {} "pr21382.so" "c"] \
1a3b5c34
AM
319 [list {Build pr22220lib.so} \
320 {-shared -Wl,--version-script=pr22220lib.ver} {-fPIC} \
321 {pr22220lib.cc} {} {pr22220lib.so} {c++}] \
322 [list {Build pr22220main.o} \
323 {} {-flto} \
324 {pr22220main.cc} {} {} {c++}] \
c3e11cbe 325]
af55061b 326
231ca753
NC
327# PR 14918 checks that libgcc is not spuriously included in a shared link of
328# an empty program. The ARM crt1.o startup code however calls __libc_csu_init
329# in /usr/lib/libc_nonshared.a(elf-init.oS). This in turn needs
330# __aeabi_unwind_cpp_pr0@@GCC_3.5 which is provided by libgcc_s.so.1, so the
331# test fails. Hence this code to skip the test.
332if { ! [istarget "arm*-*-*"] } {
333 set lto_link_elf_tests [concat $lto_link_elf_tests [list \
334 [list "PR ld/14918" \
335 "-flto" "-flto" \
336 {pr14918.c} {{"readelf" {-d --wide} "pr14918.d"}} "pr14918.exe" "c"] \
337 ]]
338}
339
8a28fa1b
NC
340# PR 12982 checks that an executable stack is not created by default
341# when using the LTO plugin. The HPPA target however requires an
342# executable stack for syscall restarts and signal returns, so we
343# skip this test for that target.
344if { ! [istarget "hppa*-*-*"] } {
345 set lto_link_elf_tests [concat $lto_link_elf_tests [list \
346 [list "PR ld/12982" \
347 "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
348 {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
349 ]]
350}
351
af55061b 352# Check final symbols in executables.
c3e11cbe
AM
353set lto_link_symbol_tests [list \
354 [list "LTO 3 symbol" \
355 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
356 {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"] \
357 [list "LTO 5 symbol" \
358 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
359 {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"] \
360 [list "LTO 9 symbol" \
361 "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" \
362 {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"] \
363 [list "LTO 16a symbol" \
364 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" "-flto" \
365 {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"] \
366 [list "LTO 16b symbol" \
367 "-O2 -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" "-flto" \
368 {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"] \
369 [list "PR ld/13183" \
370 "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" \
371 {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"] \
372]
af55061b
L
373
374# LTO run-time tests.
c3e11cbe
AM
375set lto_run_tests [list \
376 [list "LTO 3a" \
377 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
378 {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"] \
379 [list "LTO 3b" \
380 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" \
381 {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"] \
382 [list "LTO 3c" \
383 "-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" "" \
384 {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
385 [list "LTO 5" \
386 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
387 {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
388 [list "LTO 11" \
389 "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
390 {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
391 [list "LTO 12a" \
392 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" \
393 {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"] \
394 [list "LTO 12b" \
395 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" \
396 {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"] \
397 [list "LTO 13" \
398 "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" \
399 {dummy.c} "lto-13.exe" "lto-13.out" "" "c"] \
400 [list "LTO 14" \
401 "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" \
402 {dummy.c} "lto-14.exe" "lto-14.out" "" "c"] \
403 [list "LTO 15" \
404 "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" \
405 {dummy.c} "lto-15.exe" "lto-15.out" "" "c"] \
406 [list "PR ld/13066" \
407 "-O2 -flto -fuse-linker-plugin" "" \
408 {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"] \
409 [list "PR ld/13201" \
410 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" \
411 {dummy.c} "pr13201.exe" "pr13201.out" "" "c"] \
6d636d8c 412 [list "PR ld/15323 (3)" \
c3e11cbe
AM
413 "-O2 -flto -fuse-linker-plugin tmpdir/pr15323a.o" "" \
414 {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"] \
6d636d8c
L
415 [list "PR ld/15323 (4)" \
416 "-O2 -flto tmpdir/pr15323a-r.o" "" \
417 {dummy.c} "pr15323a.exe" "pr15323.out" "-flto -O2" "c"] \
c5847ba7
L
418 [list "PR ld/19317 (3)" \
419 "-O2 -flto tmpdir/pr19317-r.o" "" \
420 {dummy.c} "pr19317.exe" "pr19317.out" "-flto -O2" "c"] \
0616a280
AM
421 [list "Run pr20276" \
422 "-O2 -flto tmpdir/pr20276a.o tmpdir/pr20276b.o" "" \
423 {dummy.c} "pr20276" "pass.out" "-flto -O2" "c"] \
7dc3990e
L
424 [list "Run pr20267a" \
425 "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267a.a" "" \
426 {dummy.c} "pr20267a" "pass.out" "-flto -O2" "c"] \
427 [list "Run pr20267b" \
428 "-O2 -flto tmpdir/pr20267a.o tmpdir/libpr20267b.a" "" \
429 {dummy.c} "pr20267b" "pass.out" "-flto -O2" "c"] \
a83ef4d1
L
430 [list "Run pr22502" \
431 "-O2 -flto tmpdir/pr22502a.o tmpdir/pr22502b.o" "" \
432 {dummy.c} "pr20267" "pass.out" "-flto -O2" "c"] \
fef75122
L
433 [list "Run pr22751" \
434 "-O2 -flto" "" \
435 {dummy.c} "pr22751" "pass.out" "-flto -O2" "c" "" \
436 "-Wl,--whole-archive tmpdir/pr22751.a -Wl,--no-whole-archive"] \
c3e11cbe 437]
af55061b 438
2810e26c 439if { [at_least_gcc_version 4 7] } {
c3e11cbe
AM
440 set lto_run_tests [concat $lto_run_tests [list \
441 [list "PR ld/12942 (1)" \
442 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" \
443 {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"] \
444 [list "PR ld/12942 (2)" \
445 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" \
446 {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"] \
447 ]]
2810e26c
WN
448}
449
077c11e8
JW
450# LTO run-time tests for ELF which require shared library support.
451set lto_run_elf_shared_tests [list \
c3e11cbe
AM
452 [list "LTO 7" \
453 "-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" "" \
454 {dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \
59fa66c5
L
455 [list "Run pr21382" \
456 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr21382a.o tmpdir/pr21382.so" "" \
457 {dummy.c} "pr21382.exe" "pass.out" "" "c"] \
1a3b5c34
AM
458 [list {pr22220a} \
459 {-flto -fuse-linker-plugin tmpdir/pr22220main.o tmpdir/pr22220lib.so} {} \
460 {dummy.c} {pr22220a.exe} {pass.out} {} {c++}] \
461 [list {pr22220b} \
462 {-flto -fuse-linker-plugin -Wl,--no-as-needed tmpdir/pr22220lib.so tmpdir/pr22220main.o} {} \
463 {dummy.c} {pr22220b.exe} {pass.out} {} {c++}] \
077c11e8
JW
464]
465
466# LTO run-time tests for ELF
467set lto_run_elf_tests [list \
c3e11cbe
AM
468 [list "LTO 8" \
469 "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \
470 {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \
471 [list "LTO TLS IE" \
472 "-O2 -flto -fuse-linker-plugin" "" \
473 {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \
474]
af55061b
L
475
476run_cc_link_tests $lto_link_tests
477
077c11e8
JW
478# These compilation tests generate intermediate object files which will be used
479# by some elf tests besides shared libs tests. So, always compile them.
480run_cc_link_tests $lto_compile_elf_tests
481
36591ba1 482# Restrict these to ELF targets that support shared libs and PIC.
92c09111 483if { [is_elf_format] && [check_lto_shared_available] } {
af55061b 484 run_cc_link_tests $lto_link_elf_tests
3d5bef4c 485 set testname "PR ld/15146 (2)"
f1d7f4a6 486 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"]
4e95fbcd 487 if { [ regexp "undefined reference to symbol '\\.?xxx'" $exec_output ] } {
3d5bef4c
L
488 pass $testname
489 } {
490 fail $testname
491 }
db712946
L
492 set testname "PR ld/16746 (3)"
493 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
4e95fbcd 494 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
db712946
L
495 pass $testname
496 } {
497 fail $testname
498 }
499 set testname "PR ld/16746 (4)"
500 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
4e95fbcd 501 if { [ regexp "warning: \\.?foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
db712946
L
502 pass $testname
503 } {
504 fail $testname
505 }
af55061b
L
506}
507
508set testname "Build liblto-11.a"
509remote_file host delete "tmpdir/liblto-11.a"
37a6ac44 510set 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"]
af55061b
L
511if {![string match "" $catch_output]} {
512 unresolved $testname
513 restore_notify
514 return
515}
516
2810e26c
WN
517if { [at_least_gcc_version 4 7] } {
518 # Check expected LTO linker errors.
9e2dec47
L
519 # Since the asm symbol name hack in pr12365b.c doesn't work on all
520 # targets, run PR ld/12365 tests only for known targets.
521 if { ([istarget "i?86-*-elf*"]
c65c21e1
AM
522 || [istarget "i?86-*-linux*"]
523 || [istarget "i?86-*-gnu*"]
9e2dec47
L
524 || [istarget "i?86-*-nacl*"]
525 || [istarget "x86_64-*-nacl*"]
526 || [istarget "x86_64-*-linux*"]
527 || [istarget "amd64-*-linux*"]) } {
528 set testname "PR ld/12365"
ef621b15 529 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"]
7dd36a6f 530 set exec_output [prune_warnings $exec_output]
9e2dec47 531 if { [ regexp "undefined reference to `my_bcopy'" $exec_output ] } {
ef621b15
L
532 # Linker should catch the reference to undefined `my_bcopy'
533 # error caused by a GCC bug.
9e2dec47 534 pass $testname
ef621b15
L
535 } elseif { [ string match "" $exec_output ] } {
536 global READELF
537 set exec_output [run_host_cmd "$READELF" "-s -W tmpdir/pr12365"]
538 if { [ regexp "my_bcopy" $exec_output ] } {
539 # Verify that there is no `my_bcopy' symbol in executable.
540 fail $testname
541 } {
542 pass $testname
543 }
9e2dec47
L
544 } {
545 fail $testname
546 }
8a1b824a
L
547
548 run_cc_link_tests [list \
549 [list \
550 "Build pr22721a.so" \
551 "-shared -nostdlib -nostartfiles -Wl,-version-script,pr22721.t" \
552 "" \
553 {pr22721a.s} \
554 {} \
555 "pr22721a.so" \
556 ] \
557 [list \
558 "Build pr22721b.o" \
559 "$plug_opt" \
560 "-O2 -fPIC -flto $lto_no_fat" \
561 {pr22721b.c} \
562 ] \
563 [list \
564 "Build PR ld/pr22721" \
565 "-O2 -flto -fuse-linker-plugin -nostdlib -nostartfiles \
566 -Wl,-e,_start tmpdir/pr22721b.o tmpdir/pr22721a.so" \
567 "" \
568 {dummy.c} \
569 {} \
570 "pr22721.exe"
571 ] \
572 ]
60f79275 573 }
2810e26c 574 set testname "PR ld/12942 (3)"
f1d7f4a6 575 set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
4e95fbcd 576 if { [ regexp "undefined reference to `\\.?link_error\\(\\)'" $exec_output ] } {
2810e26c
WN
577 pass $testname
578 } {
579 fail $testname
580 }
36a900f4
L
581
582 run_cc_link_tests [list \
583 [list \
584 "Build pr23460*.o" \
585 "$plug_opt" \
586 "-O2 -fPIC -flto $lto_no_fat" \
587 {pr23460a.c pr23460b.c pr23460c.c \
588 pr23460d.c pr23460e.c pr23460f.c} \
589 ] \
590 ]
591 set exec_output [run_host_cmd "sh" \
592 "-c \"ulimit -n 16; \
593 $ar -rc $plug_opt \
594 tmpdir/libpr23460.a \
595 tmpdir/pr23460a.o \
596 tmpdir/pr23460b.o \
597 tmpdir/pr23460c.o \
598 tmpdir/pr23460d.o \
599 tmpdir/pr23460e.o \
600 tmpdir/pr23460f.o\""]
601 set exec_output [prune_warnings $exec_output]
602 if [string match "" $exec_output] then {
603 pass "PR binutils/23460"
604 } else {
605 fail "PR binutils/23460"
606 }
af55061b
L
607}
608
609# Run "ld -r" to generate inputs for complex LTO tests.
610run_dump_test "lto-3r"
611remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
612run_dump_test "lto-5r"
613remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
614
615run_cc_link_tests $lto_link_symbol_tests
616
c5847ba7
L
617run_ld_link_tests [list \
618 [list "PR ld/19317 (2)" \
619 "-r tmpdir/pr19317.o" "" "" \
620 {dummy.s} {} "pr19317-r.o"] \
621]
622
982c6f26 623run_ld_link_exec_tests $lto_run_tests
af55061b
L
624
625if { [is_elf_format] } {
982c6f26 626 run_ld_link_exec_tests $lto_run_elf_tests
212b9bc7
NC
627
628 # Note - it is not guaranteed that the ordering of symbols in the dynamic
629 # symbol table will match the ordering of the symbols specified by the
630 # --dynamic-list command line option.
631 #
632 # For PR22983 we want to make sure that all four symbols specified in
633 # pr222983.t are present in the output, but a simple sequences of regexps
634 # will not work as we do not know the order of the symbols. (Readelf
635 # does not have a symbol sorting option and the run_cc_list_tests proc
636 # does not allow for the output of the dump program to piped into `sort`).
637 #
638 # So instead we run readelf four times, each time checking for the
639 # presence of a specific symbol from the pr22983.t file.
416c34d6
L
640 run_cc_link_tests [list \
641 [list \
642 "Build pr22983" \
643 "-Wl,--dynamic-list,pr22983.t" \
644 "-flto" \
212b9bc7
NC
645 {pr22983a.c pr22983b.c} \
646 {{readelf {--dyn-syms --wide} pr22983.1.d} \
647 {readelf {--dyn-syms --wide} pr22983.2.d} \
648 {readelf {--dyn-syms --wide} pr22983.3.d} \
649 {readelf {--dyn-syms --wide} pr22983.4.d}} \
416c34d6
L
650 "pr22983" \
651 ] \
652 ]
af55061b
L
653}
654
077c11e8
JW
655if { [is_elf_format] && [check_lto_shared_available] } {
656 run_ld_link_exec_tests $lto_run_elf_shared_tests
657}
658
b95a0a31
L
659proc pr20103 {cflags libs} {
660 global CC
661
662 set testname "PR ld/20103 ($cflags $libs)"
663 set exec_output [run_host_cmd "$CC" "$cflags $libs"]
4e95fbcd 664 if { [ regexp "undefined reference to `\\.?dead'" $exec_output ] } {
b95a0a31
L
665 pass "$testname (1)"
666 } {
667 fail "$testname (1)"
668 }
669 if { [ regexp "plugin needed to handle lto object" $exec_output ] } {
670 fail "$testname (2)"
671 } {
672 pass "$testname (2)"
673 }
674}
675
676if { [check_lto_fat_available] } {
677 run_cc_link_tests [list \
678 [list \
679 "Build fatpr20103a.a" \
680 "$plug_opt" "-flto -ffat-lto-objects" \
681 {pr20103a.c} {} "fatpr20103a.a"
682 ] \
683 [list \
684 "Build fatpr20103b.a" \
685 "$plug_opt" "-flto -ffat-lto-objects" \
686 {pr20103b.c} {} "fatpr20103b.a"
687 ] \
688 [list \
689 "Build fatpr20103c.a" \
690 "$plug_opt" "-flto -ffat-lto-objects" \
691 {pr20103c.c} {} "fatpr20103c.a" \
692 ] \
693 [list \
694 "Build thinpr20103a.a" \
695 "$plug_opt" "-flto -fno-fat-lto-objects" \
696 {pr20103a.c} {} "thinpr20103a.a"
697 ] \
698 [list \
699 "Build thinpr20103b.a" \
700 "$plug_opt" "-flto -fno-fat-lto-objects" \
701 {pr20103b.c} {} "thinpr20103b.a"
702 ] \
703 [list \
704 "Build thinpr20103c.a" \
705 "$plug_opt" "-flto -fno-fat-lto-objects" \
706 {pr20103c.c} {} "thinpr20103c.a" \
707 ] \
708 [list \
709 "Build pr20103a" \
710 "-O2 -flto -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
711 "-O2 -flto" \
712 {dummy.c} {} "pr20103a" \
713 ] \
714 [list \
715 "Build pr20103b" \
716 "-O2 -flto -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
717 "-O2 -flto" \
718 {dummy.c} {} "pr20103b" \
719 ] \
720 [list \
721 "Build pr20103c" \
722 "-O2 -Wl,--start-group tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a -Wl,--end-group" \
723 "-O2" \
724 {dummy.c} {} "pr20103c" \
725 ] \
726 ]
727 pr20103 "-O2 -flto" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
728 pr20103 "-O2 -flto" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
729 pr20103 "-O2" "tmpdir/fatpr20103a.a tmpdir/fatpr20103b.a tmpdir/fatpr20103c.a"
730
731 if { [at_least_gcc_version 4 9] } {
732 run_cc_link_tests [list \
733 [list \
734 "Build pr20103d" \
735 "-O2 -Wl,--start-group tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a -Wl,--end-group" \
736 "-O2" \
737 {dummy.c} {} "pr20103d" \
738 ] \
739 ]
740 pr20103 "-O2" "tmpdir/thinpr20103a.a tmpdir/thinpr20103b.a tmpdir/thinpr20103c.a"
741 }
742}
743
af55061b 744restore_notify
This page took 0.365369 seconds and 4 git commands to generate.