PR ld/20828: LD/testsuite: Correct indentation
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / shared.exp
1 # Expect script for various ELF tests.
2 # Copyright (C) 2006-2017 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
22 # Exclude non-ELF targets.
23
24 if ![is_elf_format] {
25 return
26 }
27
28 # Skip targets where -shared is not supported
29
30 if ![check_shared_lib_support] {
31 return
32 }
33
34 # This target requires extra GAS options when building code for shared
35 # libraries.
36 set AFLAGS_PIC ""
37 if [istarget "tic6x-*-*"] {
38 append AFLAGS_PIC " -mpic -mpid=near"
39 }
40 # This target requires a non-default emulation for successful shared
41 # library/executable builds.
42 set LFLAGS ""
43 if [istarget "tic6x-*-*"] {
44 append LFLAGS " -melf32_tic6x_le"
45 }
46
47 # PR ld/20828 check for correct dynamic symbol table entries where:
48 # - symbols have been defined with a linker script,
49 # - the same symbols have been seen in shared library used in the link,
50 # - the shared library symbols have been swept in section garbage collection.
51 # Verify that the symbols are global rather than local and that a version
52 # script adjusts them accordingly.
53 if { [check_gc_sections_available] } {
54 run_ld_link_tests [list \
55 [list \
56 "PR ld/20828 dynamic symbols with section GC\
57 (auxiliary shared library)" \
58 "$LFLAGS -shared --gc-sections -T pr20828.ld" "" "$AFLAGS_PIC" \
59 {pr20828.s} \
60 {{readelf --dyn-syms pr20828-a.sd} \
61 {readelf --dyn-syms pr20828-b.sd}} \
62 "libpr20828.so"] \
63 [list \
64 "PR ld/20828 dynamic symbols with section GC (plain)" \
65 "$LFLAGS -shared --gc-sections -T pr20828.ld" \
66 "tmpdir/libpr20828.so" "$AFLAGS_PIC" \
67 {pr20828.s} \
68 {{readelf --dyn-syms pr20828-a.sd} \
69 {readelf --dyn-syms pr20828-b.sd}} \
70 "pr20828-1.so"] \
71 [list \
72 "PR ld/20828 dynamic symbols with section GC (version script)" \
73 "$LFLAGS -shared --gc-sections -T pr20828.ld\
74 --version-script=pr20828.ver" \
75 "tmpdir/libpr20828.so" \
76 "$AFLAGS_PIC" \
77 {pr20828.s} \
78 {{readelf --dyn-syms pr20828-b.sd} \
79 {readelf --dyn-syms pr20828-c.sd}} \
80 "pr20828-2.so"]]
81 }
82
83 # Check to see if the C compiler works
84 if { [which $CC] == 0 } {
85 return
86 }
87
88 # Add -ldl to extralibs if needed
89 set extralibs ""
90 if { ![istarget *-*-freebsd*]} {
91 set extralibs "-ldl"
92 }
93
94 set build_tests {
95 {"Build libfoo.so"
96 "-shared" "-fPIC"
97 {foo.c} {} "libfoo.so"}
98 {"Build versioned libfoo.so"
99 "-shared -Wl,--version-script=foo.map" "-fPIC"
100 {foo.c} {} "libfoov.so"}
101 {"Build libbar.so"
102 "-shared" "-fPIC"
103 {begin.c end.c} {} "libbar.so"}
104 {"Build warn libbar.so"
105 "-shared" "-fPIC"
106 {beginwarn.c end.c} {{readelf {-S --wide} libbarw.rd}} "libbarw.so"
107 "c" {^.*\): warning: function foo is deprecated$} }
108 {"Build hidden libbar.so"
109 "-shared" "-fPIC"
110 {begin.c endhidden.c} {} "libbarh.so"}
111 {"Build protected libbar.so"
112 "-shared" "-fPIC"
113 {begin.c endprotected.c} {} "libbarp.so"}
114 {"Build libbar.so with libfoo.so"
115 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
116 {end.c} {} "libbarfoo.so"}
117 {"Build libar.so with versioned libfoo.so"
118 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
119 {end.c} {} "libbarfoov.so"}
120 {"Build hidden libbar.so with libfoo.so"
121 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
122 {endhidden.c} {} "libbarhfoo.so"}
123 {"Build hidden libar.so with versioned libfoo.so"
124 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
125 {endhidden.c} {} "libbarhfoov.so"}
126 {"Build protected libbar.so with libfoo.so"
127 "-shared tmpdir/begin.o tmpdir/libfoo.so" "-fPIC"
128 {endprotected.c} {} "libbarpfoo.so"}
129 {"Build protected libbar.so with versioned libfoo.so"
130 "-shared tmpdir/begin.o tmpdir/libfoov.so" "-fPIC"
131 {endprotected.c} {} "libbarpfoov.so"}
132 {"Build libdl1.so"
133 "-shared" "-fPIC"
134 {dl1.c} {} "libdl1.so"}
135 {"Build libdl2a.so with --dynamic-list=dl2.list"
136 "-shared -Wl,--dynamic-list=dl2.list" "-fPIC"
137 {dl2.c dl2xxx.c} {} "libdl2a.so"}
138 {"Build libdl2a.so with --dynamic-list=dl2a.list"
139 "-shared -Wl,--dynamic-list=dl2a.list" "-fPIC"
140 {dl2.c dl2xxx.c} {} "libdl2a.so"}
141 {"Build libdl2a.so with --dynamic-list-data"
142 "-shared -Wl,--dynamic-list-data" "-fPIC"
143 {dl2.c dl2xxx.c} {} "libdl2a.so"}
144 {"Build libdl2b.so with --dynamic-list=dl2.list and dl2xxx.list"
145 "-shared -Wl,--dynamic-list=dl2.list,--dynamic-list=dl2xxx.list" "-fPIC"
146 {dl2.c dl2xxx.c} {} "libdl2b.so"}
147 {"Build libdl2c.so with --dynamic-list-data and dl2xxx.list"
148 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl2xxx.list" "-fPIC"
149 {dl2.c dl2xxx.c} {} "libdl2c.so"}
150 {"Build libdl4a.so with --dynamic-list=dl4.list"
151 "-shared -Wl,--dynamic-list=dl4.list" "-fPIC"
152 {dl4.c dl4xxx.c} {} "libdl4a.so"}
153 {"Build libdl4b.so with --dynamic-list-data"
154 "-shared -Wl,--dynamic-list-data" "-fPIC"
155 {dl4.c dl4xxx.c} {} "libdl4b.so"}
156 {"Build libdl4c.so with --dynamic-list=dl4.list and dl4xxx.list"
157 "-shared -Wl,--dynamic-list=dl4.list,--dynamic-list=dl4xxx.list" "-fPIC"
158 {dl4.c dl4xxx.c} {} "libdl4c.so"}
159 {"Build libdl4d.so with --dynamic-list-data and dl4xxx.list"
160 "-shared -Wl,--dynamic-list-data,--dynamic-list=dl4xxx.list" "-fPIC"
161 {dl4.c dl4xxx.c} {} "libdl4d.so"}
162 {"Build libdl4e.so with -Bsymbolic-functions --dynamic-list-cpp-new"
163 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
164 {dl4.c dl4xxx.c} {} "libdl4e.so"}
165 {"Build libdl4f.so with --dynamic-list-cpp-new -Bsymbolic-functions"
166 "-shared -Wl,--dynamic-list-cpp-new,-Bsymbolic-functions" "-fPIC"
167 {dl4.c dl4xxx.c} {} "libdl4f.so"}
168 {"Build libdl6a.so"
169 "-shared" "-fPIC"
170 {dl6.c} {} "libdl6a.so"}
171 {"Build libdl6b.so with -Bsymbolic --dynamic-list-data"
172 "-shared -Wl,-Bsymbolic,--dynamic-list-data" "-fPIC"
173 {dl6.c} {} "libdl6b.so"}
174 {"Build libdl6c.so with -Bsymbolic"
175 "-shared -Wl,-Bsymbolic" "-fPIC"
176 {dl6.c} {} "libdl6c.so"}
177 {"Build libdl6d.so with --dynamic-list-data -Bsymbolic"
178 "-shared -Wl,--dynamic-list-data,-Bsymbolic" "-fPIC"
179 {dl6.c} {} "libdl6d.so"}
180 {"Build libdata1.so"
181 "-shared" "-fPIC"
182 {data1.c} {} "libdata1.so"}
183 {"Build libdata2.so"
184 "-shared" "-fPIC"
185 {data2.c} {} "libdata2.so"}
186 {"Build libcomm1.o"
187 "-r -nostdlib" ""
188 {comm1.c} {} "libcomm1.o"}
189 {"Build libfunc1.so"
190 "-shared" "-fPIC"
191 {func1.c} {} "libfunc1.so"}
192 {"Build libpr9676-1.a"
193 "" "-fPIC"
194 {pr9676-1.c} {} "libpr9676-1.a"}
195 {"Build libpr9676-2.a"
196 "" "-fPIC"
197 {pr9676-2.c} {} "libpr9676-2.a"}
198 {"Build libpr9676-3.so"
199 "-shared" "-fPIC"
200 {pr9676-3.c} {} "libpr9676-3.so"}
201 {"Build libpr9676-4.so"
202 "-shared" "-fPIC"
203 {pr9676-4.c} {} "libpr9676-4.so"}
204 {"Build libpr9676-4a.so"
205 "-shared tmpdir/pr9676-4.o -Ltmpdir -lpr9676-3 -Wl,--start-group -lpr9676-1 -lpr9676-2 -Wl,--end-group"
206 "-fPIC"
207 {dummy.c} {{readelf {-s} pr9676.rd}} "libpr9676-4a.so"}
208 {"Build libpr9679.so"
209 "-shared" "-fPIC -O0"
210 {pr9679-1.c pr9679-2.c} {{readelf {-s} pr9679.rd}} "libpr9679.so"}
211 {"Build libpr11138-1.so"
212 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
213 {pr11138-1.c} {} "libpr11138-1.so"}
214 {"Build libpr11138-2.o"
215 "-r -nostdlib" ""
216 {pr11138-2.c} {} "libpr11138-2.o"}
217 {"Build pr13250-1.so"
218 "-shared" "-fPIC"
219 {pr13250-1.c} {} "libpr13250-1.so"}
220 {"Build pr13250-2.so with libpr13250-1.so"
221 "-shared -Wl,--no-as-needed tmpdir/libpr13250-1.so" "-fPIC"
222 {pr13250-2.c} {} "libpr13250-2.so"}
223 {"Build libpr13250-3.o"
224 "-r -nostdlib" ""
225 {pr13250-3.c} {} "libpr13250-3.o"}
226 {"Build libpr14323-2.so"
227 "-shared" "-fPIC"
228 {pr14323-2.c} {} "libpr14323-2.so"}
229 {"Build pr14862-1.o"
230 "-r -nostdlib" ""
231 {pr14862-1.c} {} "libpr14862-1.o"}
232 {"Build libpr14862.so"
233 "-shared -Wl,--version-script=pr11138-1.map" "-fPIC"
234 {pr14862-2.c} {} "libpr14862.so"}
235 {"Build libneeded1b.so"
236 "-shared" "-fPIC"
237 {needed1b.c} {} "libneeded1b.so"}
238 {"Build libneeded1a.so"
239 "-shared -Wl,--add-needed,--no-as-needed -Ltmpdir -lneeded1b" "-fPIC"
240 {needed1a.c} {} "libneeded1a.so"}
241 {"Build libneeded1c.o"
242 "-r -nostdlib" ""
243 {needed1c.c} {} "libneeded1c.o"}
244 {"Build libneeded1pic.o"
245 "-r -nostdlib" "-fPIC"
246 {needed1c.c} {} "libneeded1pic.o"}
247 {"Build needed1a.so with --add-needed"
248 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
249 {dummy.c} {} "needed1a.so"}
250 {"Build needed1b.so with --copy-dt-needed-entries"
251 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir,-z,defs -Ltmpdir -lneeded1a" ""
252 {dummy.c} {} "needed1b.so"}
253 {"Build needed1a.so with --no-add-needed"
254 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-add-needed -Ltmpdir -lneeded1a" ""
255 {dummy.c} {} "needed1c.so"}
256 {"Build needed1b.so with --no-copy-dt-needed-entries"
257 "-shared tmpdir/libneeded1pic.o -Wl,--no-as-needed,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" ""
258 {dummy.c} {} "needed1d.so"}
259 {"Build librel.so"
260 "-shared" "-fPIC"
261 {rel.c} {} "librel.so"}
262 {"Build libneeded2a.so"
263 "-shared" "-fPIC"
264 {needed2a.c} {} "libneeded2a.so"}
265 {"Build libneeded2b.so"
266 "-shared -Wl,--version-script,needed2.ver" "-fPIC"
267 {needed2b.c} {} "libneeded2b.so"}
268 {"Build libneeded2c.o"
269 "-r -nostdlib" ""
270 {needed2c.c} {} "libneeded2c.o"}
271 {"Build needed2"
272 "tmpdir/libneeded2c.o -Wl,--as-needed tmpdir/libneeded2a.so tmpdir/libneeded2b.so" ""
273 {dummy.c} {} "needed2"}
274 {"Build libneeded3a.so"
275 "-shared -Wl,--no-add-needed" "-fPIC"
276 {needed1a.c} {} "libneeded3a.so"}
277 {"Build libneeded3b.so"
278 "-shared -Wl,--no-as-needed,--add-needed -Ltmpdir -lneeded1b" "-fPIC"
279 {dummy.c} {} "libneeded3b.so"}
280 {"Build needed3.o"
281 "-r -nostdlib" ""
282 {needed3.c} {} "libneeded3.so"}
283 {"Build needed3"
284 "tmpdir/needed3.o -Wl,--as-needed -Ltmpdir -lneeded3a -lneeded3b -lneeded1b" ""
285 {dummy.c} {} "needed3"}
286 {"Build libpr2404a.so"
287 "-shared" "-fPIC"
288 {pr2404a.c} {} "libpr2404a.so"}
289 {"Build libpr2404b.a"
290 "" ""
291 {pr2404b.c} {} "libpr2404b.a"}
292 {"Build rdynamic-1"
293 "-rdynamic -Wl,--gc-sections" "-ffunction-sections"
294 {rdynamic-1.c} {{readelf {-s} rdynamic-1.rd}} "rdynamic-1"}
295 {"Build dynamic-1"
296 "-Wl,--dynamic-list,dynamic-1.syms -Wl,--gc-sections" "-ffunction-sections"
297 {dynamic-1.c} {{readelf {-s} dynamic-1.rd}} "dynamic-1"}
298 {"Build libpr16496a.so"
299 "-shared -Wl,--version-script=pr16496a.map" "-fPIC"
300 {pr16496a.c} {} "libpr16496a.so"}
301 {"Build libpr16496b.a"
302 "" "-fPIC"
303 {pr16496b.c} {} "libpr16496b.a"}
304 {"Build libpr16496b.so"
305 "-shared -Wl,--no-as-needed tmpdir/pr16496b.o tmpdir/libpr16496a.so" ""
306 {dummy.c} {{objdump {-R} pr16496b.od}} "libpr16496b.so"}
307 {"Build libpr16452a.so"
308 "-shared -Wl,-soname,libpr16452a.so,--version-script=pr16452.map" "-fPIC"
309 {pr16452a.c} {} "libpr16452a.so"}
310 {"Build libpr16452b.so"
311 "-shared -Wl,-soname,libpr16452b.so,--no-as-needed tmpdir/libpr16452a.so" "-fPIC"
312 {dummy.c} {} "libpr16452b.so"}
313 {"Build pr16452"
314 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
315 {pr16452b.c} {{objdump {-p} pr16452.od}} "pr16452"}
316 {"Build pr16457"
317 "-Wl,--no-as-needed,-rpath=tmpdir,-rpath-link=tmpdir tmpdir/libpr16452b.so" ""
318 {pr16452b.c} {{objdump {-p} pr16457.od}} "pr16457"}
319 {"Build libpr18458a.so"
320 "-shared -Wl,-z,now" "-fPIC"
321 {pr18458a.c} {} "libpr18458a.so"}
322 {"Build libpr18458b.so"
323 "-shared -Wl,-z,now tmpdir/libpr18458a.so" "-fPIC"
324 {pr18458b.c} {} "libpr18458b.so"}
325 {"Build pr19073a.o"
326 "-r -nostdlib" ""
327 {pr19073.s} {} "pr19073a.o"}
328 {"Build libpr19073.so"
329 "-shared -Wl,--version-script=pr19073.map tmpdir/pr19073a.o" "-fPIC"
330 {dummy.c} {{readelf {--dyn-syms --wide} pr19073.rd}} "libpr19073.so"}
331 }
332
333 run_cc_link_tests $build_tests
334
335 set run_tests [list \
336 [list "Run normal with libfoo.so" \
337 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/end.o" "" \
338 {main.c} "normal" "normal.out" ] \
339 [list "Run protected with libfoo.so" \
340 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endprotected.o" "" \
341 {main.c} "protected" "normal.out" ] \
342 [list "Run hidden with libfoo.so" \
343 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoo.so tmpdir/endhidden.o" "" \
344 {main.c} "hidden" "hidden.out" ] \
345 [list "Run normal with versioned libfoo.so" \
346 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/end.o" "" \
347 {main.c} "normalv" "normal.out" ] \
348 [list "Run warn with versioned libfoo.so" \
349 "-Wl,--no-as-needed tmpdir/beginwarn.o tmpdir/libfoov.so" "" \
350 {main.c} "warn" "warn.out" \
351 "" "c" {^.*\): warning: function foo is deprecated$} ] \
352 [list "Run protected with versioned libfoo.so" \
353 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endprotected.o" "" \
354 {main.c} "protected" "normal.out" ] \
355 [list "Run hidden with versioned libfoo.so" \
356 "-Wl,--no-as-needed tmpdir/begin.o tmpdir/libfoov.so tmpdir/endhidden.o" "" \
357 {main.c} "hiddenv" "hidden.out" ] \
358 [list "Run normal libbar.so with libfoo.so" \
359 "-Wl,--no-as-needed tmpdir/libbarfoo.so tmpdir/libfoo.so" "" \
360 {main.c} "normal" "normal.out" ] \
361 [list "Run protected libbar.so with libfoo.so" \
362 "-Wl,--no-as-needed tmpdir/libbarpfoo.so tmpdir/libfoo.so" "" \
363 {main.c} "protected" "normal.out" ] \
364 [list "Run hidden libbar.so with libfoo.so" \
365 "-Wl,--no-as-needed tmpdir/libbarhfoo.so tmpdir/libfoo.so" "" \
366 {main.c} "hidden" "hidden.out" ] \
367 [list "Run normal libbar.so with versioned libfoo.so" \
368 "-Wl,--no-as-needed tmpdir/libbarfoov.so tmpdir/libfoov.so" "" \
369 {main.c} "normal" "normal.out" ] \
370 [list "Run protected libbar.so with versioned libfoo.so" \
371 "-Wl,--no-as-needed tmpdir/libbarpfoov.so tmpdir/libfoov.so" "" \
372 {main.c} "protected" "normal.out" ] \
373 [list "Run hidden libbar.so with versioned libfoo.so" \
374 "-Wl,--no-as-needed tmpdir/libbarhfoov.so tmpdir/libfoov.so" "" \
375 {main.c} "hidden" "hidden.out" ] \
376 [list "Run dl1a with --dynamic-list=dl1.list and dlopen on libdl1.so" \
377 "-Wl,--no-as-needed,--dynamic-list=dl1.list $extralibs" "" \
378 {dl1main.c} "dl1a" "dl1.out" ] \
379 [list "Run dl1b with --dynamic-list-data and dlopen on libdl1.so" \
380 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
381 {dl1main.c} "dl1b" "dl1.out" ] \
382 [list "Run with libdl2a.so" \
383 "-Wl,--no-as-needed tmpdir/libdl2a.so" "" \
384 {dl2main.c} "dl2a" "dl2a.out" ] \
385 [list "Run with libdl2b.so" \
386 "-Wl,--no-as-needed tmpdir/libdl2b.so" "" \
387 {dl2main.c} "dl2b" "dl2b.out" ] \
388 [list "Run with libdl2c.so" \
389 "-Wl,--no-as-needed tmpdir/libdl2c.so" "" \
390 {dl2main.c} "dl2c" "dl2b.out" ] \
391 [list "Run with libdl4a.so" \
392 "-Wl,--no-as-needed tmpdir/libdl4a.so" "" \
393 {dl4main.c} "dl4a" "dl4a.out" ] \
394 [list "Run with libdl4b.so" \
395 "-Wl,--no-as-needed tmpdir/libdl4b.so" "" \
396 {dl4main.c} "dl4b" "dl4a.out" ] \
397 [list "Run with libdl4c.so" \
398 "-Wl,--no-as-needed tmpdir/libdl4c.so" "" \
399 {dl4main.c} "dl4c" "dl4b.out" ] \
400 [list "Run with libdl4d.so" \
401 "-Wl,--no-as-needed tmpdir/libdl4d.so" "" \
402 {dl4main.c} "dl4d" "dl4b.out" ] \
403 [list "Run with libdl4e.so" \
404 "-Wl,--no-as-needed tmpdir/libdl4e.so" "" \
405 {dl4main.c} "dl4e" "dl4a.out" ] \
406 [list "Run with libdl4f.so" \
407 "-Wl,--no-as-needed tmpdir/libdl4f.so" "" \
408 {dl4main.c} "dl4f" "dl4a.out" ] \
409 [list "Run dl6a1 with --dynamic-list-data and dlopen on libdl6a.so" \
410 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
411 {dl6amain.c} "dl6a1" "dl6a.out" ] \
412 [list "Run dl6a2 with -Bsymbolic-functions and dlopen on libdl6a.so" \
413 "-Wl,--no-as-needed,-Bsymbolic-functions $extralibs" "" \
414 {dl6amain.c} "dl6a2" "dl6b.out" ] \
415 [list "Run dl6a3 with -Bsymbolic and dlopen on libdl6a.so" \
416 "-Wl,--no-as-needed,-Bsymbolic $extralibs" "" \
417 {dl6amain.c} "dl6a3" "dl6b.out" ] \
418 [list "Run dl6a4 with -Bsymbolic --dynamic-list-data and dlopen on libdl6a.so" \
419 "-Wl,--no-as-needed,-Bsymbolic,--dynamic-list-data $extralibs" "" \
420 {dl6amain.c} "dl6a4" "dl6a.out" ] \
421 [list "Run dl6a5 with -Bsymbolic-functions --dynamic-list-cpp-new and dlopen on libdl6a.so" \
422 "-Wl,--no-as-needed,-Bsymbolic-functions,--dynamic-list-cpp-new $extralibs" "" \
423 {dl6amain.c} "dl6a5" "dl6b.out" ] \
424 [list "Run dl6a6 with --dynamic-list-cpp-new -Bsymbolic-functions and dlopen on libdl6a.so" \
425 "-Wl,--no-as-needed,--dynamic-list-cpp-new,-Bsymbolic-functions $extralibs" "" \
426 {dl6amain.c} "dl6a6" "dl6b.out" ] \
427 [list "Run dl6a7 with --dynamic-list-data -Bsymbolic and dlopen on libdl6a.so" \
428 "-Wl,--no-as-needed,--dynamic-list-data,-Bsymbolic $extralibs" "" \
429 {dl6amain.c} "dl6a7" "dl6a.out" ] \
430 [list "Run dl6b1 with --dynamic-list-data and dlopen on libdl6b.so" \
431 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
432 {dl6bmain.c} "dl6b1" "dl6a.out" ] \
433 [list "Run dl6b2 with dlopen on libdl6b.so" \
434 "-Wl,--no-as-needed $extralibs" "" \
435 {dl6bmain.c} "dl6b2" "dl6b.out" ] \
436 [list "Run dl6c1 with --dynamic-list-data and dlopen on libdl6c.so" \
437 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
438 {dl6cmain.c} "dl6c1" "dl6b.out" ] \
439 [list "Run dl6d1 with --dynamic-list-data and dlopen on libdl6d.so" \
440 "-Wl,--no-as-needed,--dynamic-list-data $extralibs" "" \
441 {dl6dmain.c} "dl6d1" "dl6b.out" ] \
442 [list "Run with libdata1.so" \
443 "-Wl,--no-as-needed tmpdir/libdata1.so" "" \
444 {dynbss1.c} "dynbss1" "pass.out" ] \
445 [list "Run with libdata2.so" \
446 "-Wl,--no-as-needed tmpdir/libdata2.so" "" \
447 {weakdef1.c} "weakdef1" "pass.out" ] \
448 [list "Run with libfunc1.so comm1.o" \
449 "-Wl,--no-as-needed tmpdir/libfunc1.so tmpdir/comm1.o" "" \
450 {dummy.c} "comm1" "pass.out" ] \
451 [list "Run with comm1.o libfunc1.so" \
452 "-Wl,--no-as-needed tmpdir/comm1.o tmpdir/libfunc1.so" "" \
453 {dummy.c} "comm1" "pass.out" ] \
454 [list "Run with pr11138-2.c libpr11138-1.so" \
455 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/pr11138-2.o tmpdir/libpr11138-1.so" "" \
456 {dummy.c} "pr11138a" "pr11138.out" ] \
457 [list "Run with libpr11138-1.so pr11138-2.c" \
458 "-Wl,--no-as-needed,--version-script=pr11138-2.map tmpdir/libpr11138-1.so tmpdir/pr11138-2.o" "" \
459 {dummy.c} "pr11138b" "pr11138.out" ] \
460 [list "Run with pr13250-3.c, libpr13250-1.so and libpr13250-2.so" \
461 "-Wl,--as-needed tmpdir/pr13250-3.o tmpdir/libpr13250-1.so tmpdir/libpr13250-2.so" "" \
462 {dummy.c} "pr13250" "pass.out" ] \
463 [list "Run with pr14323-1.c pr14323-2.so" \
464 "-Wl,--no-as-needed tmpdir/libpr14323-2.so" "" \
465 {pr14323-1.c} "pr14323" "pass.out" ] \
466 [list "Run with pr14862-1.c libpr14862.so" \
467 "-Wl,--as-needed tmpdir/libpr14862-1.o tmpdir/libpr14862.so" "" \
468 {dummy.c} "pr14862" "pr14862.out" ] \
469 [list "Link with --add-needed" \
470 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--add-needed,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
471 {dummy.c} "needed1a" "needed1.out" ] \
472 [list "Link with --copy-dt-needed-entries" \
473 "tmpdir/libneeded1c.o -Wl,--no-as-needed,--copy-dt-needed-entries,-rpath=tmpdir,-rpath-link=tmpdir -Ltmpdir -lneeded1a" "" \
474 {dummy.c} "needed1b" "needed1.out" ] \
475 [list "Run relmain" \
476 "-Wl,--no-as-needed,-rpath=tmpdir -Ltmpdir -lrel" "" \
477 {relmain.c} "relmain" "relmain.out" ] \
478 [list "Run pr2404" \
479 "-Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" "" \
480 {dummy.c} "pr2404" "pr2404.out" ] \
481 [list "Run pr18458" \
482 "-Wl,--no-as-needed,-z,now tmpdir/libpr18458a.so tmpdir/libpr18458b.so" "" \
483 {pr18458c.c} "pr18458" "pass.out" ] \
484 ]
485
486 # NetBSD ELF systems do not currently support the .*_array sections.
487 run_ld_link_exec_tests $run_tests "*-*-netbsdelf*"
488
489 # Check --no-add-needed and --no-copy-dt-needed-entries
490 set testname "--no-add-needed"
491 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-add-needed,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
492 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
493 pass $testname
494 } {
495 fail $testname
496 }
497 set testname "--no-copy-dt-needed-entries"
498 set exec_output [run_host_cmd "$CC" "tmpdir/libneeded1c.o -Wl,--no-copy-dt-needed-entries,-rpath-link=tmpdir -Ltmpdir -lneeded1a"]
499 if { [ regexp "tmpdir/libneeded1b.so: .*: DSO missing" $exec_output ] } {
500 pass $testname
501 } {
502 fail $testname
503 }
504 set testname "--no-add-needed -shared"
505 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-add-needed,-z,defs -Ltmpdir -lneeded1a"]
506 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
507 pass $testname
508 } {
509 fail $testname
510 }
511 set testname "--no-copy-dt-needed-entries -shared"
512 set exec_output [run_host_cmd "$CC" "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries,-z,defs -Ltmpdir -lneeded1a"]
513 if { [ regexp "undefined reference to `\.?bar'" $exec_output ] } {
514 pass $testname
515 } {
516 fail $testname
517 }
518
519 # Check to see if the C++ compiler works
520 if { [which $CXX] == 0 } {
521 return
522 }
523
524 set build_cxx_tests {
525 {"Build libdl3a.so with --dynamic-list=dl3.list"
526 "-shared -Wl,--dynamic-list=dl3.list" "-fPIC"
527 {dl3.cc} {} "libdl3a.so" "c++"}
528 {"Build libdl3b.so with -Bsymbolic"
529 "-shared -Wl,-Bsymbolic" "-fPIC"
530 {dl3.cc} {} "libdl3b.so" "c++"}
531 {"Build libdl3a.so with --dynamic-list-cpp-typeinfo"
532 "-shared -Wl,--dynamic-list-cpp-typeinfo" "-fPIC"
533 {dl3.cc} {} "libdl3c.so" "c++"}
534 {"Build libdnew1a.so with --Bsymbolic-functions --dynamic-list-cpp-new"
535 "-shared -Wl,-Bsymbolic-functions,--dynamic-list-cpp-new" "-fPIC"
536 {del.cc new.cc} {} "libnew1a.so" "c++"}
537 {"Build libdnew1b.so with --dynamic-list-data --dynamic-list-cpp-new"
538 "-shared -Wl,--dynamic-list-data,--dynamic-list-cpp-new" "-fPIC"
539 {del.cc new.cc} {} "libnew1b.so" "c++"}
540 }
541
542 # "-shared -Bsymbolic" only works with gcc 4.5.0 and newer.
543 # {"Run with libdl3b.so"
544 # "tmpdir/libdl3b.so" ""
545 # {dl3main.cc} "dl3b" "dl3b.out" "" "c++"}
546 set run_cxx_tests {
547 {"Run with libdl3a.so"
548 "-Wl,--no-as-needed tmpdir/libdl3a.so" ""
549 {dl3main.cc} "dl3a" "dl3a.out" "" "c++"}
550 {"Run with libdl3c.so"
551 "-Wl,--no-as-needed tmpdir/libdl3c.so" ""
552 {dl3main.cc} "dl3c" "dl3a.out" "" "c++"}
553 {"Run with libnew1a.so"
554 "-Wl,--no-as-needed tmpdir/libnew1a.so" ""
555 {dl5.cc} "dl5a" "dl5.out" "" "c++"}
556 {"Run with libnew1b.so"
557 "-Wl,--no-as-needed tmpdir/libnew1b.so" ""
558 {dl5.cc} "dl5b" "dl5.out" "" "c++"}
559 }
560
561 run_cc_link_tests $build_cxx_tests
562 run_ld_link_exec_tests $run_cxx_tests
563
564 if { [istarget *-*-linux*]
565 || [istarget *-*-nacl*]
566 || [istarget *-*-gnu*] } {
567 run_cc_link_tests [list \
568 [list \
569 "Build libpr2404b.a with PIE" \
570 "" \
571 "-fPIE" \
572 { pr2404b.c } \
573 {} \
574 "libpr2404b.a" \
575 ] \
576 [list \
577 "Build pr19579a.o" \
578 "" "-fPIE" \
579 {pr19579a.c} \
580 {} \
581 "libpr19579a.a" \
582 ] \
583 [list \
584 "Build libpr19579.so" \
585 "-shared" \
586 "-fPIC" \
587 {pr19579b.c} \
588 {} \
589 "libpr19579.so" \
590 ] \
591 ]
592 run_ld_link_exec_tests [list \
593 [list \
594 "Run pr2404 with PIE" \
595 "-pie -Wl,--no-as-needed tmpdir/pr2404b.o tmpdir/libpr2404a.so" \
596 "" \
597 { dummy.c } \
598 "pr2404pie" \
599 "pr2404.out" \
600 "-fPIE" \
601 ] \
602 [list \
603 "Run pr18718" \
604 "" \
605 "" \
606 { pr18718.c check-ptr-eq.c } \
607 "pr18718" \
608 "pass.out" \
609 "-O2 -I../bfd" \
610 ] \
611 [list \
612 "Run pr18718 with PIE (1)" \
613 "-pie" \
614 "" \
615 { pr18718.c check-ptr-eq.c } \
616 "pr18718pie1" \
617 "pass.out" \
618 "-O2 -fPIE -I../bfd" \
619 ] \
620 [list \
621 "Run pr18718 with PIE (2)" \
622 "" \
623 "" \
624 { pr18718.c check-ptr-eq.c } \
625 "pr18718pie2" \
626 "pass.out" \
627 "-O2 -fPIE -I../bfd" \
628 ] \
629 [list \
630 "Run pr18718 with PIC (1)" \
631 "" \
632 "" \
633 { pr18718.c check-ptr-eq.c } \
634 "pr18718pic1" \
635 "pass.out" \
636 "-O2 -fPIC -I../bfd" \
637 ] \
638 [list \
639 "Run pr18718 with PIC (2)" \
640 "-pie" \
641 "" \
642 { pr18718.c check-ptr-eq.c } \
643 "pr18718pic2" \
644 "pass.out" \
645 "-O2 -fPIC -I../bfd" \
646 ] \
647 [list \
648 "Run pr19579" \
649 "-pie -Wl,--no-as-needed,-z,text tmpdir/pr19579a.o tmpdir/libpr19579.so" \
650 "" \
651 {dummy.c} \
652 "pr19579" \
653 "pass.out" \
654 "-fPIE" \
655 ] \
656 ]
657 }
658
659 proc mix_pic_and_non_pic {xfails cflags ldflags exe} {
660 run_cc_link_tests [list \
661 [list \
662 "Build libpr19719a.so" \
663 "-shared -Wl,-soname,libpr19719.so" \
664 "-fPIC" \
665 { pr19719d.c } \
666 {} \
667 "libpr19719a.so" \
668 ] \
669 [list \
670 "Build libpr19719b.so" \
671 "-shared -Wl,-soname,libpr19719.so" \
672 "-fPIC" \
673 { dummy.c } \
674 {} \
675 "libpr19719b.so" \
676 ] \
677 [list \
678 "Build libpr19719b.o" \
679 "-r -nostdlib" \
680 "-fPIC" \
681 { pr19719b.c } \
682 {} \
683 "libpr19719b.o" \
684 ] \
685 ]
686
687 send_log "cp tmpdir/libpr19719b.so tmpdir/libpr19719.so\n"
688 exec cp tmpdir/libpr19719b.so tmpdir/libpr19719.so
689
690 run_ld_link_exec_tests [list \
691 [list \
692 "Run $exe fun defined" \
693 "-Wl,--no-as-needed,-rpath,tmpdir $ldflags tmpdir/libpr19719b.o tmpdir/libpr19719.so" \
694 "" \
695 { pr19719a.c pr19719c.c } \
696 $exe \
697 "pass.out" \
698 "$cflags" \
699 ] \
700 ]
701
702 send_log "cp tmpdir/libpr19719a.so tmpdir/libpr19719.so\n"
703 exec cp tmpdir/libpr19719a.so tmpdir/libpr19719.so
704
705 foreach targ $xfails {
706 setup_xfail $targ
707 }
708
709 if ![isnative] {
710 unsupported "Run $exe fun undefined"
711 return
712 }
713
714 set exec_output [run_host_cmd "tmpdir/$exe" ""]
715 if {![string match "PASS" $exec_output]} {
716 fail "Run $exe fun undefined"
717 } else {
718 pass "Run $exe fun undefined"
719 }
720 }
721
722 mix_pic_and_non_pic [list "arm*-*-*" "aarch64*-*-*"] "" "" "pr19719"
723 mix_pic_and_non_pic [] "-fPIE" "-pie" "pr19719pie"
This page took 0.066815 seconds and 5 git commands to generate.