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