Commit | Line | Data |
---|---|---|
af55061b | 1 | # Expect script for ld-plugin LTO tests |
61315175 | 2 | # Copyright 2011, 2012, 2013 |
af55061b L |
3 | # Free Software Foundation, Inc. |
4 | # | |
5 | # This file is part of the GNU Binutils. | |
6 | # | |
7 | # This program is free software; you can redistribute it and/or modify | |
8 | # it under the terms of the GNU General Public License as published by | |
9 | # the Free Software Foundation; either version 3 of the License, or | |
10 | # (at your option) any later version. | |
11 | # | |
12 | # This program is distributed in the hope that it will be useful, | |
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | # GNU General Public License for more details. | |
16 | # | |
17 | # You should have received a copy of the GNU General Public License | |
18 | # along with this program; if not, write to the Free Software | |
19 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, | |
20 | # MA 02110-1301, USA. | |
21 | ||
22 | # These tests require plugin and LTO. | |
23 | if { ![check_plugin_api_available] | |
24 | || ![check_lto_available] } { | |
25 | return | |
26 | } | |
27 | ||
28 | global CFLAGS | |
29 | global CXXFLAGS | |
30 | set saved_CFLAGS "$CFLAGS" | |
31 | set saved_CXXFLAGS "$CXXFLAGS" | |
32 | regsub -all "\\-Wp,-D_FORTIFY_SOURCE=\[0-9\]+" $CFLAGS "" CFLAGS | |
33 | regsub -all "\\-Wp,-D_FORTIFY_SOURCE=\[0-9\]+" $CXXFLAGS "" CXXFLAGS | |
34 | ||
35 | proc restore_notify { } { | |
36 | global saved_CFLAGS | |
37 | global saved_CXXFLAGS | |
38 | set CFLAGS "$saved_CFLAGS" | |
39 | set CXXFLAGS "$saved_CXXFLAGS" | |
40 | } | |
41 | ||
42 | # Simple LTO tests and generate input files for complex LTO tests. | |
43 | set lto_link_tests { | |
44 | {"LTO 1" | |
45 | "-O2 -flto -fuse-linker-plugin" "-flto -fuse-linker-plugin" | |
46 | {lto-1a.c lto-1b.c} {} "lto-1.exe"} | |
47 | {"Build libdummy.a 2" | |
48 | "" "-O2 -flto -fuse-linker-plugin" | |
49 | {lto-2.c} {} "libdummy.a"} | |
50 | {"LTO 2" | |
51 | "-static -O2 -flto -fuse-linker-plugin tmpdir/lto-2.o -lm" "" | |
52 | {dummy.c} {} "lto-2.exe"} | |
53 | {"Build libdummy.a 3a" | |
54 | "" "-flto" | |
55 | {lto-3a.c} {} "libdummy.a"} | |
56 | {"Build libdummy.a 3c" | |
57 | "" "-O2" | |
58 | {lto-3c.c} {} "libdummy.a"} | |
59 | {"Build liblto-3.a" | |
60 | "" "-flto" | |
61 | {lto-3b.c} {} "liblto-3.a"} | |
62 | {"Build libdummy.a 5a" | |
63 | "" "-flto" | |
64 | {lto-5a.c} {} "libdummy.a"} | |
65 | {"Build libdummy.a 5b" | |
66 | "" "-flto" | |
67 | {lto-5b.c} {} "libdummy.a"} | |
68 | {"LTO 6" | |
69 | "-O2 -flto -fuse-linker-plugin" "" | |
70 | {lto-6.c} {} "lto-6.exe" "c"} | |
71 | {"Build libdummy.a 9" | |
1178606e | 72 | "" "-O2 -finline -flto" |
af55061b L |
73 | {lto-9.cc} {} "libdummy.a"} |
74 | {"Build libdummy.a 11a" | |
75 | "" "-O -flto" | |
76 | {lto-11a.c} {} "libdummy.a"} | |
77 | {"Build libdummy.a 11b" | |
78 | "" "-O -flto" | |
79 | {lto-11b.c} {} "libdummy.a"} | |
80 | {"Build libdummy.a 11c" | |
81 | "" "-O" | |
82 | {lto-11c.c} {} "libdummy.a"} | |
83 | {"Build liblto-12.a" | |
84 | "" "-O2 -flto" | |
85 | {lto-12c.c} {} "liblto-12.a"} | |
86 | {"Build libdummy.a 12" | |
87 | "" "-O2 -flto" | |
88 | {lto-12a.c lto-12b.c} {} "libdummy.a"} | |
89 | {"Build libdummy.a 13" | |
90 | "" "-O2 -flto" | |
91 | {lto-13a.c lto-13b.c} {} "libdummy.a"} | |
92 | {"Build liblto-13.a" | |
93 | "" "-O2" | |
94 | {lto-13c.c} {} "liblto-13.a"} | |
95 | {"Build libdummy.a 14a" | |
96 | "" "-flto" | |
97 | {lto-14a.c lto-14b.c} {} "libdummy.a"} | |
98 | {"Build liblto-14.a" | |
99 | "" "-flto" | |
100 | {lto-14c.c} {} "liblto-14.a"} | |
101 | {"Build libdummy.a 15a" | |
102 | "" "-flto" | |
103 | {lto-15a.c} {} "libdummy.a"} | |
104 | {"Build liblto-15.a" | |
105 | "" "-flto" | |
106 | {lto-15b.c} {} "liblto-15.a"} | |
107 | {"PR ld/12696" | |
108 | "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" | |
109 | {pr12696-1.cc} {} "pr12696-1r.o" "c"} | |
110 | {"Build libdummy.a PR ld/12758" | |
111 | "" "" | |
112 | {pr12758a.s} {} "libdummy.a"} | |
113 | {"Build libpr12758.a" | |
114 | "" "-flto -O2" | |
115 | {pr12758b.c} {} "libpr12758.a"} | |
116 | {"PR ld/12758" | |
117 | "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12758a.o -Wl,--start-group tmpdir/libpr12758.a -Wl,--end-group" "" | |
118 | {dummy.c} {} "pr12758.exe"} | |
119 | {"Build libdummy.a PR ld/12760" | |
120 | "" "" | |
121 | {pr12760a.c} {} "libdummy.a"} | |
122 | {"Build libpr12760.a" | |
123 | "" "-flto -O2" | |
124 | {pr12760b.c} {} "libpr12760.a"} | |
125 | {"PR ld/12760" | |
126 | "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin tmpdir/pr12760a.o -Wl,--start-group tmpdir/libpr12760.a -Wl,--end-group" "" | |
127 | {dummy.c} {} "pr12760.exe" "c" "warning: Bad bar"} | |
128 | {"Build libdummy.a PR ld/12942 (1)" | |
129 | "" "-flto -O2" | |
130 | {pr12942a.cc pr12942c.cc} {} "libdummy.a" "c++"} | |
131 | {"Build libdummy.a PR ld/12942 (2)" | |
132 | "" "-O0" | |
133 | {pr12942b.cc} {} "libdummy.a" "c++"} | |
134 | {"Build libpr13183.a" | |
135 | "-T" "-flto -O2" | |
136 | {pr13183a.c} {} "libpr13183.a"} | |
137 | {"Build libdummy.a PR ld/13183" | |
138 | "" "-flto -O2" | |
139 | {pr13183b.c} {} "libdummy.a"} | |
140 | {"Build libdummy.a PR ld/13201" | |
141 | "" "-flto -O2" | |
142 | {pr13201.c} {} "libdummy.a"} | |
143 | {"PR ld/13287" | |
144 | "-flto -fuse-linker-plugin -Wl,--as-needed" "-flto" | |
145 | {pr13287.cc} {} "pr13287.exe" "c++"} | |
61315175 L |
146 | {"PR ld/15323" |
147 | "-O2 -flto -fuse-linker-plugin -r -nostdlib" "-O2 -flto" | |
148 | {pr15323a.c} {} "pr15323a-r.o" "c"} | |
af55061b L |
149 | } |
150 | ||
151 | # Generate input files for complex LTO tests for ELF. | |
152 | set lto_link_elf_tests { | |
153 | {"Build libdummy.a 7" | |
154 | "" "-flto -O2" | |
155 | {lto-7a.c lto-7b.c lto-7c.c} {} "libdummy.a"} | |
156 | {"Build liblto-7.so" | |
157 | "-shared" "-O2 -fpic" | |
158 | {lto-7d.c} {} "liblto-7.so" "c"} | |
159 | {"Build libdummy.a 8a" | |
160 | "" "-O2" | |
161 | {lto-8a.c} {} "libdummy.a"} | |
162 | {"Build libdummy.a 8b" | |
163 | "" "-flto -O2" | |
164 | {lto-8b.c} {} "libdummy.a"} | |
165 | {"Build liblto-17a.so" | |
166 | "-shared -O2 -fpic -flto -fuse-linker-plugin" "-O2 -fpic -flto" | |
167 | {lto-17a.c} {{"nm" {} "lto-17a.d"}} "liblto-17a.so" "c"} | |
168 | {"Build liblto-17b.so 1" | |
169 | "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" | |
170 | {lto-17b.c} {{"nm" {} "lto-17b-1.d"}} "liblto-17b.so"} | |
171 | {"Build liblto-17b.so 2" | |
172 | "-shared -O2 -fpic -flto -fuse-linker-plugin tmpdir/lto-17a.o" "-O2 -fpic -flto" | |
173 | {lto-17b.c} {{"nm" {} "lto-17b-2.d"}} "liblto-17b.so"} | |
174 | {"PR ld/12982" | |
175 | "-O2 -flto -fuse-linker-plugin" "-O2 -flto" | |
176 | {pr12982.c} {{"readelf" {-l --wide} "pr12982.d"}} "pr12982.exe"} | |
177 | {"PR ld/12975" | |
178 | "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib -Wl,-version-script,pr12975.t" "-O2 -flto" | |
179 | {pr12975.c} {{"readelf" {-s --wide} "pr12975.d"}} "pr12975.so" "c"} | |
180 | {"PR ld/13229" | |
1178606e | 181 | "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -finline -fno-early-inlining -flto" |
af55061b L |
182 | {pr13229.cc} {{"readelf" {-s --wide} "pr13229.d"}} "pr13229.so" "c++"} |
183 | {"PR ld/13244" | |
184 | "-shared -O2 -fPIC -flto -fuse-linker-plugin -nostdlib" "-O2 -fno-early-inlining -flto" | |
185 | {pr13244.c} {{"readelf" {-s --wide} "pr13244.d"}} "pr13244.so" "c"} | |
3d5bef4c L |
186 | {"Build libpr15146a.a" |
187 | "" "-flto -O2" | |
188 | {pr15146a.c} {} "lib15146a.a"} | |
189 | {"Build pr15146b.so" | |
190 | "-shared" "-O2 -fpic" | |
191 | {pr15146b.c} {} "pr15146b.so" "c"} | |
192 | {"Build pr15146c.so" | |
53c3509d | 193 | "-shared -Wl,--no-as-needed tmpdir/pr15146b.so" "-O2 -fpic" |
3d5bef4c L |
194 | {pr15146c.c} {} "pr15146c.so" "c"} |
195 | {"PR ld/15146 (1)" | |
53c3509d | 196 | "-O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146a.o tmpdir/pr15146c.so" "" |
3d5bef4c L |
197 | {dummy.c} {{"readelf" {-d} "pr15146.d"}} "pr15146a.exe"} |
198 | {"Build libpr15146d.a" | |
199 | "" "-flto -O2" | |
200 | {pr15146d.c} {} "lib15146d.a"} | |
201 | {"Build libpr15146d.a" | |
202 | "" "-flto -O2" | |
203 | {pr15146d.c} {} "lib15146d.a"} | |
af55061b L |
204 | } |
205 | ||
206 | # Check final symbols in executables. | |
207 | set lto_link_symbol_tests { | |
208 | {"LTO 3 symbol" | |
209 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" | |
210 | {dummy.c} {{"nm" {} "lto-3.d"}} "lto-3.exe" "c"} | |
211 | {"LTO 5 symbol" | |
212 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" | |
213 | {dummy.c} {{"nm" {} "lto-5.d"}} "lto-5.exe" "c"} | |
214 | {"LTO 9 symbol" | |
215 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-9.o" "" | |
216 | {dummy.c} {{"nm" {-C} "lto-9.d"}} "lto-9.exe" "c++"} | |
217 | {"LTO 16a symbol" | |
218 | "-O2 -Wl,-e,foo -nostdlib -flto -fuse-linker-plugin" "-flto" | |
219 | {lto-16a.c} {{"nm" {} "lto-16a.d"}} "lto-16.exe" "c"} | |
220 | {"LTO 16b symbol" | |
221 | "-O2 -Wl,-e,foo -u bar -nostdlib -flto -fuse-linker-plugin" "-flto" | |
222 | {lto-16a.c lto-16b.c} {{"nm" {} "lto-16b.d"}} "lto-16b.exe" "c"} | |
223 | {"PR ld/13183" | |
224 | "-O2 -flto -fuse-linker-plugin tmpdir/pr13183b.o tmpdir/libpr13183.a" "" | |
225 | {dummy.c} {{"nm" {} "pr13183.d"}} "pr13183.exe" "c"} | |
226 | } | |
227 | ||
228 | # LTO run-time tests. | |
229 | set lto_run_tests { | |
230 | {"LTO 3a" | |
231 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/liblto-3.a" "" | |
232 | {dummy.c} "lto-3b.exe" "lto-3.out" "" "c"} | |
233 | {"LTO 3b" | |
234 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-3a.o tmpdir/lto-3c.o tmpdir/lto-3.o" "" | |
235 | {dummy.c} "lto-3c.exe" "lto-3.out" "" "c"} | |
236 | {"LTO 3c" | |
237 | "-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" "" | |
238 | {dummy.c} "lto-3d.exe" "lto-3.out" "" "c"} | |
239 | {"LTO 5" | |
240 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-5.o" "" | |
241 | {dummy.c} "lto-5.exe" "lto-5.out" "" "c"} | |
242 | {"LTO 11" | |
243 | "-O -flto -fuse-linker-plugin tmpdir/liblto-11.a" "" | |
244 | {dummy.c} "lto-11.exe" "lto-11.out" "" "c"} | |
245 | {"LTO 12a" | |
246 | "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/liblto-12.a tmpdir/lto-12b.o" "" | |
247 | {dummy.c} "lto-12a.exe" "lto-12.out" "" "c"} | |
248 | {"LTO 12b" | |
249 | "-O -flto -fuse-linker-plugin tmpdir/lto-12a.o tmpdir/lto-12b.o tmpdir/liblto-12.a" "" | |
250 | {dummy.c} "lto-12b.exe" "lto-12.out" "" "c"} | |
251 | {"LTO 13" | |
252 | "-O -flto -fuse-linker-plugin tmpdir/lto-13a.o tmpdir/liblto-13.a tmpdir/lto-13b.o" "" | |
253 | {dummy.c} "lto-13.exe" "lto-13.out" "" "c"} | |
254 | {"LTO 14" | |
255 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-14a.o -Wl,--whole-archive tmpdir/liblto-14.a -Wl,--no-whole-archive tmpdir/lto-14b.o" "" | |
256 | {dummy.c} "lto-14.exe" "lto-14.out" "" "c"} | |
257 | {"LTO 15" | |
258 | "-O2 -flto -fuse-linker-plugin -Wl,--start-group tmpdir/liblto-15.a tmpdir/lto-15a.o -Wl,--end-group" "" | |
259 | {dummy.c} "lto-15.exe" "lto-15.out" "" "c"} | |
260 | {"PR ld/12942 (1)" | |
261 | "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942b.o" "" | |
262 | {dummy.c} "pr12942a.exe" "pr12942.out" "" "c++"} | |
263 | {"PR ld/12942 (2)" | |
264 | "-O2 -flto -fuse-linker-plugin tmpdir/pr12942a.o tmpdir/pr12942c.o" "" | |
265 | {dummy.c} "pr12942c.exe" "pr12942.out" "" "c++"} | |
266 | {"PR ld/13066" | |
267 | "-O2 -flto -fuse-linker-plugin" "" | |
268 | {pr13066.cc} "pr13066.exe" "pr13066.out" "" "c++"} | |
269 | {"PR ld/13201" | |
270 | "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr13201.o -lm" "" | |
271 | {dummy.c} "pr13201.exe" "pr13201.out" "" "c"} | |
61315175 L |
272 | {"PR ld/15323" |
273 | "-O2 -flto -fuse-linker-plugin -Wl,--as-needed tmpdir/pr15323a-r.o" "" | |
274 | {pr15323b.c} "pr15323.exe" "pr15323.out" "-flto -O2" "c"} | |
af55061b L |
275 | } |
276 | ||
277 | # LTO run-time tests for ELF | |
278 | set lto_run_elf_tests { | |
279 | {"LTO 7" | |
53c3509d | 280 | "-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" "" |
af55061b L |
281 | {dummy.c} "lto-7.exe" "lto-7.out" "" "c"} |
282 | {"LTO 8" | |
283 | "-O2 -flto -fuse-linker-plugin tmpdir/lto-8b.o tmpdir/lto-8a.o" "" | |
284 | {dummy.c} "lto-8.exe" "lto-8.out" "" "c"} | |
285 | {"LTO TLS IE" | |
286 | "-O2 -flto -fuse-linker-plugin" "" | |
287 | {run-ie.c} "run-ie.exe" "run-ie.out" "" "c"} | |
288 | } | |
289 | ||
290 | run_cc_link_tests $lto_link_tests | |
291 | ||
36591ba1 SL |
292 | # Restrict these to ELF targets that support shared libs and PIC. |
293 | if { [is_elf_format] | |
294 | && [run_host_cmd_yesno $CC "-shared -fPIC $srcdir/$subdir/dummy.c -o tmpdir/t.so"] } { | |
af55061b | 295 | run_cc_link_tests $lto_link_elf_tests |
3d5bef4c | 296 | set testname "PR ld/15146 (2)" |
53c3509d | 297 | set exec_output [run_host_cmd "$CC" "$gcc_gas_flag $gcc_ld_flag -O2 -flto -fuse-linker-plugin -Wl,-rpath-link,. -Wl,--no-copy-dt-needed-entries -Wl,--no-as-needed tmpdir/pr15146d.o tmpdir/pr15146c.so"] |
3d5bef4c L |
298 | if { [ regexp "ltrans.o: undefined reference to symbol 'xxx'" $exec_output ] } { |
299 | pass $testname | |
300 | } { | |
301 | fail $testname | |
302 | } | |
af55061b L |
303 | } |
304 | ||
305 | set testname "Build liblto-11.a" | |
306 | remote_file host delete "tmpdir/liblto-11.a" | |
307 | set catch_output [run_host_cmd "$ar" "rc tmpdir/liblto-11.a tmpdir/lto-11a.o tmpdir/lto-11b.o tmpdir/lto-11c.o"] | |
308 | if {![string match "" $catch_output]} { | |
309 | unresolved $testname | |
310 | restore_notify | |
311 | return | |
312 | } | |
313 | ||
314 | # Check expected LTO linker errors. | |
315 | set testname "PR ld/12942 (3)" | |
316 | set exec_output [run_host_cmd "$CXX" "$gcc_gas_flag $gcc_ld_flag -O2 -flto -fuse-linker-plugin tmpdir/pr12942b.o tmpdir/pr12942a.o"] | |
317 | if { [ regexp "pr12942a.h:7: undefined reference to `link_error\\(\\)'" $exec_output ] } { | |
318 | pass $testname | |
319 | } { | |
320 | fail $testname | |
321 | } | |
322 | ||
323 | # Run "ld -r" to generate inputs for complex LTO tests. | |
324 | run_dump_test "lto-3r" | |
325 | remote_exec host "mv" "tmpdir/dump tmpdir/lto-3.o" | |
326 | run_dump_test "lto-5r" | |
327 | remote_exec host "mv" "tmpdir/dump tmpdir/lto-5.o" | |
328 | ||
329 | run_cc_link_tests $lto_link_symbol_tests | |
330 | ||
36591ba1 SL |
331 | # The following tests require running the executable generated by ld. |
332 | if ![isnative] { | |
333 | return | |
334 | } | |
335 | ||
af55061b L |
336 | run_ld_link_exec_tests [] $lto_run_tests |
337 | ||
338 | if { [is_elf_format] } { | |
339 | run_ld_link_exec_tests [] $lto_run_elf_tests | |
340 | } | |
341 | ||
342 | restore_notify |