Don't issue a warning for references in LTO IR to warning symbols
[deliverable/binutils-gdb.git] / ld / testsuite / ld-plugin / lto.exp
1 # Expect script for ld-plugin LTO tests
2 # Copyright (C) 2011-2014 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 # These tests require plugin and LTO.
22 if { ![check_plugin_api_available]
23 || ![check_lto_available] } {
24 return
25 }
26
27 global CFLAGS
28 global CXXFLAGS
29 set saved_CFLAGS "$CFLAGS"
30 set saved_CXXFLAGS "$CXXFLAGS"
31 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS
32 regsub -all "(\\-Wp,)?-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS
33
34 proc restore_notify { } {
35 global saved_CFLAGS
36 global saved_CXXFLAGS
37 set CFLAGS "$saved_CFLAGS"
38 set CXXFLAGS "$saved_CXXFLAGS"
39 }
40
41 set plugin_names {
42 liblto_plugin.so
43 liblto_plugin-0.dll
44 cyglto_plugin-0.dll
45 }
46 set plug_opt ""
47 foreach plug $plugin_names {
48 set plug_so [run_host_cmd $CC "--print-prog-name $plug"]
49 if { $plug_so ne $plug } then {
50 set plug_opt "--plugin $plug_so"
51 break
52 }
53 }
54 set lto_fat ""
55 if { [check_lto_fat_available] } {
56 set lto_fat "-ffat-lto-objects"
57 }
58
59 # Simple LTO tests and generate input files for complex LTO tests.
60 set lto_link_tests [list \
61 [list "LTO 1" \
62 "-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" \
63 {lto-1a.c lto-1b.c} {} "lto-1.exe"] \
64 [list "Compile 2" \
65 "" "-O2 -flto -fuse-linker-plugin" \
66 {lto-2.c} {} ""] \
67 [list "LTO 2" \
68 "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" "" \
69 {dummy.c} {} "lto-2.exe"] \
70 [list "Compile 3a" \
71 "" "-flto" \
72 {lto-3a.c} {} ""] \
73 [list "Compile 3c" \
74 "" "-O2" \
75 {lto-3c.c} {} ""] \
76 [list "Build liblto-3.a" \
77 "" "-flto $lto_fat" \
78 {lto-3b.c} {} "liblto-3.a"] \
79 [list "Compile 5a" \
80 "" "-flto $lto_fat" \
81 {lto-5a.c} {} ""] \
82 [list "Compile 5b" \
83 "" "-flto $lto_fat" \
84 {lto-5b.c} {} ""] \
85 [list "LTO 6" \
86 "-O2 -flto -fuse-linker-plugin" "" \
87 {lto-6.c} {} "lto-6.exe" "c"] \
88 [list "Compile 9" \
89 "" "-O2 -finline -flto" \
90 {lto-9.cc} {} "" "c++"] \
91 [list "Compile 11a" \
92 "" "-O -flto" \
93 {lto-11a.c} {} ""] \
94 [list "Compile 11b" \
95 "" "-O -flto" \
96 {lto-11b.c} {} ""] \
97 [list "Compile 11c" \
98 "" "-O" \
99 {lto-11c.c} {} ""] \
100 [list "Build liblto-12.a" \
101 "$plug_opt" "-O2 -flto" \
102 {lto-12c.c} {} "liblto-12.a"] \
103 [list "Compile 12" \
104 "" "-O2 -flto" \
105 {lto-12a.c lto-12b.c} {} ""] \
106 [list "Compile 13" \
107 "" "-O2 -flto" \
108 {lto-13a.c lto-13b.c} {} ""] \
109 [list "Build liblto-13.a" \
110 "" "-O2" \
111 {lto-13c.c} {} "liblto-13.a"] \
112 [list "Compile 14a" \
113 "" "-flto" \
114 {lto-14a.c lto-14b.c} {} ""] \
115 [list "Build liblto-14.a" \
116 "$plug_opt" "-flto" \
117 {lto-14c.c} {} "liblto-14.a"] \
118 [list "Compile 15a" \
119 "" "-flto" \
120 {lto-15a.c} {} ""] \
121 [list "Build liblto-15.a" \
122 "$plug_opt" "-flto" \
123 {lto-15b.c} {} "liblto-15.a"] \
124 [list "PR ld/12696" \
125 "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" \
126 {pr12696-1.cc} {} "pr12696-1r.o" "c++"] \
127 [list "Compile PR ld/12758" \
128 "" "" \
129 {pr12758a.s} {} ""] \
130 [list "Build libpr12758.a" \
131 "" "-flto -O2 $lto_fat" \
132 {pr12758b.c} {} "libpr12758.a"] \
133 [list "PR ld/12758" \
134 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" "" \
135 {dummy.c} {} "pr12758.exe"] \
136 [list "Compile PR ld/12760" \
137 "" "-g -O0" \
138 {pr12760a.c} {} ""] \
139 [list "Build libpr12760.a" \
140 "" "-flto -O2 $lto_fat" \
141 {pr12760b.c} {} "libpr12760.a"] \
142 [list "PR ld/12760" \
143 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" \
144 {dummy.c} {} "pr12760.exe" "c" "pr12760a.c:6: warning: Bad bar"] \
145 [list "Build libpr13183.a" \
146 "-T" "-flto -O2 $lto_fat" \
147 {pr13183a.c} {} "libpr13183.a"] \
148 [list "Compile PR ld/13183" \
149 "" "-flto -O2" \
150 {pr13183b.c} {} ""] \
151 [list "Compile PR ld/13201" \
152 "" "-flto -O2" \
153 {pr13201.c} {} ""] \
154 [list "PR ld/13287" \
155 "-flto -fuse-linker-plugin -Wl,--as-needed" "-flto" \
156 {pr13287.cc} {} "pr13287.exe" "c++"] \
157 [list "PR ld/15323" \
158 "" "-O2" \
159 {pr15323a.c} {} "" "c"] \
160 [list "Compile(1) PR ld/pr16846" \
161 "" "-flto" \
162 {pr16846a.c pr16846b.c} {} ""] \
163 [list "Compile(2) PR ld/pr16846" \
164 "" "" \
165 {pr16846c.c} {} ""] \
166 [list "PR ld/pr16846(1)" \
167 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846b.o tmpdir/pr16846c.o" "" \
168 {dummy.c} {} "pr16846a.exe"] \
169 [list "PR ld/pr16846(2)" \
170 "-flto -fuse-linker-plugin tmpdir/pr16846a.o tmpdir/pr16846c.o tmpdir/pr16846b.o" "" \
171 {dummy.c} {} "pr16846b.exe"] \
172 ]
173
174 if { [at_least_gcc_version 4 7] } {
175 set lto_link_tests [concat $lto_link_tests [list \
176 [list "Compile PR ld/12942 (1)" \
177 "" "-flto -O2" \
178 {pr12942a.cc pr12942c.cc} {} "" "c++"] \
179 [list "Compile PR ld/12942 (2)" \
180 "" "-O0" \
181 {pr12942b.cc} {} "" "c++"] \
182 ]]
183 }
184
185 # Generate input files for complex LTO tests for ELF.
186 set lto_link_elf_tests [list \
187 [list "Compile 7" \
188 "" "-flto -O2" \
189 {lto-7a.c lto-7b.c lto-7c.c} {} ""] \
190 [list "Build liblto-7.so" \
191 "-shared" "-O2 -fpic" \
192 {lto-7d.c} {} "liblto-7.so" "c"] \
193 [list "Compile 8a" \
194 "" "-O2" \
195 {lto-8a.c} {} ""] \
196 [list "Compile 8b" \
197 "" "-flto -O2" \
198 {lto-8b.c} {} ""] \
199 [list "Build liblto-17a.so" \
200 "-shared -O2 -fpic -flto -fuse-linker-plugin" "-O2 -fpic -flto" \
201 {lto-17a.c} {{"nm" {} "lto-17a.d"}} "liblto-17a.so" "c"] \
202 [list "Build liblto-17b.so 1" \
203 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
204 {lto-17b.c} {{"nm" {} "lto-17b-1.d"}} "liblto-17b.so"] \
205 [list "Build liblto-17b.so 2" \
206 "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" \
207 {lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"] \
208 [list "PR ld/12982" \
209 "-O2 -flto -fuse-linker-plugin" "-O2 -flto" \
210 {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"] \
211 [list "PR ld/12975" \
212 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" \
213 {pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"] \
214 [list "PR ld/13229" \
215 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -finline -fno-early-inlining -flto" \
216 {pr13229.cc} {{"readelf" {-s --wide} "pr13229.d"}} "pr13229.so" "c++"] \
217 [list "PR ld/13244" \
218 "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" \
219 {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"] \
220 [list "Build libpr15146a.a" \
221 "$plug_opt" "-flto -O2" \
222 {pr15146a.c} {} "lib15146a.a"] \
223 [list "Build pr15146b.so" \
224 "-shared" "-O2 -fpic" \
225 {pr15146b.c} {} "pr15146b.so" "c"] \
226 [list "Build pr15146c.so" \
227 "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic" \
228 {pr15146c.c} {} "pr15146c.so" "c"] \
229 [list "PR ld/15146 (1)" \
230 "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" \
231 {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"] \
232 [list "Build libpr15146d.a" \
233 "$plug_opt" "-flto -O2" \
234 {pr15146d.c} {} "lib15146d.a"] \
235 [list "Build libpr16746a.a" \
236 "" "" \
237 {pr16746a.c pr16746b.c} {} "lib15146a.a"] \
238 [list "Build libpr16746b.a" \
239 "$plug_opt" "-O2 -flto" \
240 {pr16746c.c pr16746d.c} {} "lib15146b.a"] \
241 [list "PR ld/16746 (1)" \
242 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746a.o tmpdir/pr16746c.o" "-O2 -flto" \
243 {dummy.c} {} "pr16746a.exe"] \
244 [list "PR ld/16746 (2)" \
245 "-O2 -flto -fuse-linker-plugin tmpdir/pr16746c.o tmpdir/pr16746a.o" "-O2 -flto" \
246 {dummy.c} {} "pr16746b.exe"] \
247 ]
248
249 # Check final symbols in executables.
250 set lto_link_symbol_tests [list \
251 [list "LTO 3 symbol" \
252 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
253 {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"] \
254 [list "LTO 5 symbol" \
255 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
256 {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"] \
257 [list "LTO 9 symbol" \
258 "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" \
259 {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"] \
260 [list "LTO 16a symbol" \
261 "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" "-flto" \
262 {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"] \
263 [list "LTO 16b symbol" \
264 "-O2 -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" "-flto" \
265 {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"] \
266 [list "PR ld/13183" \
267 "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" \
268 {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"] \
269 ]
270
271 # LTO run-time tests.
272 set lto_run_tests [list \
273 [list "LTO 3a" \
274 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" \
275 {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"] \
276 [list "LTO 3b" \
277 "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" \
278 {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"] \
279 [list "LTO 3c" \
280 "-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" "" \
281 {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"] \
282 [list "LTO 5" \
283 "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" \
284 {dummy.c} "lto-5.exe" "lto-5.out" "" "c"] \
285 [list "LTO 11" \
286 "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" \
287 {dummy.c} "lto-11.exe" "lto-11.out" "" "c"] \
288 [list "LTO 12a" \
289 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" \
290 {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"] \
291 [list "LTO 12b" \
292 "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" \
293 {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"] \
294 [list "LTO 13" \
295 "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" \
296 {dummy.c} "lto-13.exe" "lto-13.out" "" "c"] \
297 [list "LTO 14" \
298 "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" \
299 {dummy.c} "lto-14.exe" "lto-14.out" "" "c"] \
300 [list "LTO 15" \
301 "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" \
302 {dummy.c} "lto-15.exe" "lto-15.out" "" "c"] \
303 [list "PR ld/13066" \
304 "-O2 -flto -fuse-linker-plugin" "" \
305 {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"] \
306 [list "PR ld/13201" \
307 "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" \
308 {dummy.c} "pr13201.exe" "pr13201.out" "" "c"] \
309 [list "PR ld/15323" \
310 "-O2 -flto -fuse-linker-plugin tmpdir/pr15323a.o" "" \
311 {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"] \
312 ]
313
314 if { [at_least_gcc_version 4 7] } {
315 set lto_run_tests [concat $lto_run_tests [list \
316 [list "PR ld/12942 (1)" \
317 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" \
318 {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"] \
319 [list "PR ld/12942 (2)" \
320 "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" \
321 {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"] \
322 ]]
323 }
324
325 # LTO run-time tests for ELF
326 set lto_run_elf_tests [list \
327 [list "LTO 7" \
328 "-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" "" \
329 {dummy.c} "lto-7.exe" "lto-7.out" "" "c"] \
330 [list "LTO 8" \
331 "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" \
332 {dummy.c} "lto-8.exe" "lto-8.out" "" "c"] \
333 [list "LTO TLS IE" \
334 "-O2 -flto -fuse-linker-plugin" "" \
335 {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"] \
336 ]
337
338 run_cc_link_tests $lto_link_tests
339
340 # Restrict these to ELF targets that support shared libs and PIC.
341 if { [is_elf_format] && [check_lto_shared_available] } {
342 run_cc_link_tests $lto_link_elf_tests
343 set testname "PR ld/15146 (2)"
344 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"]
345 if { [ regexp "undefined reference to symbol 'xxx'" $exec_output ] } {
346 pass $testname
347 } {
348 fail $testname
349 }
350 set testname "PR ld/16746 (3)"
351 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746b.o tmpdir/pr16746d.o"]
352 if { [ regexp "warning: foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
353 pass $testname
354 } {
355 fail $testname
356 }
357 set testname "PR ld/16746 (4)"
358 set exec_output [run_host_cmd "$CC" "-O2 -flto -fuse-linker-plugin tmpdir/pr16746d.o tmpdir/pr16746b.o"]
359 if { [ regexp "warning: foobar" $exec_output ] && ![ regexp "symbol from plugin" $exec_output ] } {
360 pass $testname
361 } {
362 fail $testname
363 }
364 }
365
366 set testname "Build liblto-11.a"
367 remote_file host delete "tmpdir/liblto-11.a"
368 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"]
369 if {![string match "" $catch_output]} {
370 unresolved $testname
371 restore_notify
372 return
373 }
374
375 if { [at_least_gcc_version 4 7] } {
376 # Check expected LTO linker errors.
377 set testname "PR ld/12942 (3)"
378 set exec_output [run_host_cmd "$CXX" "-O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"]
379 if { [ regexp "undefined reference to `link_error\\(\\)'" $exec_output ] } {
380 pass $testname
381 } {
382 fail $testname
383 }
384 }
385
386 # Run "ld -r" to generate inputs for complex LTO tests.
387 run_dump_test "lto-3r"
388 remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o"
389 run_dump_test "lto-5r"
390 remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o"
391
392 run_cc_link_tests $lto_link_symbol_tests
393
394 # The following tests require running the executable generated by ld.
395 if ![isnative] {
396 return
397 }
398
399 run_ld_link_exec_tests [] $lto_run_tests
400
401 if { [is_elf_format] } {
402 run_ld_link_exec_tests [] $lto_run_elf_tests
403 }
404
405 restore_notify
This page took 0.040912 seconds and 5 git commands to generate.