Commit | Line | Data |
---|---|---|
6fc49d28 | 1 | # Expect script for ld-visibility tests |
b3adc24a | 2 | # Copyright (C) 2000-2020 Free Software Foundation, Inc. |
6fc49d28 | 3 | # |
f96b4a7b NC |
4 | # This file is part of the GNU Binutils. |
5 | # | |
6 | # This program is free software; you can redistribute it and/or modify | |
6fc49d28 | 7 | # it under the terms of the GNU General Public License as published by |
f96b4a7b | 8 | # the Free Software Foundation; either version 3 of the License, or |
6fc49d28 | 9 | # (at your option) any later version. |
f96b4a7b | 10 | # |
6fc49d28 L |
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. | |
f96b4a7b | 15 | # |
6fc49d28 L |
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 | |
f96b4a7b NC |
18 | # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
19 | # MA 02110-1301, USA. | |
6fc49d28 L |
20 | # |
21 | # Written by Ian Lance Taylor (ian@cygnus.com) | |
22 | # and H.J. Lu (hjl@gnu.org) | |
23 | # | |
24 | ||
25 | # Make sure that ld can generate ELF shared libraries with visibility. | |
26 | ||
d9816402 | 27 | # Check to see if the C compiler works |
44ed8092 | 28 | if { ![check_compiler_available] } { |
d9816402 AM |
29 | return |
30 | } | |
31 | ||
6fc49d28 L |
32 | # This test can only be run on a couple of ELF platforms. |
33 | # Square bracket expressions seem to confuse istarget. | |
19c7c582 AM |
34 | if { ![istarget hppa*64*-*-hpux*] \ |
35 | && ![istarget hppa*-*-linux*] \ | |
36 | && ![istarget i?86-*-linux*] \ | |
5940a93c | 37 | && ![istarget i?86-*-gnu*] \ |
5a68afcf | 38 | && ![istarget *-*-nacl*] \ |
ad995491 | 39 | && ![istarget ia64-*-linux*] \ |
6fc49d28 | 40 | && ![istarget m68k-*-linux*] \ |
66517a2f | 41 | && ![istarget mips*-*-linux*] \ |
81cacc15 | 42 | && ![istarget powerpc*-*-linux*] \ |
4f38fc1c | 43 | && ![istarget arm*-*-linux*] \ |
2ffd68ef | 44 | && ![istarget alpha*-*-linux*] \ |
9147e853 JJ |
45 | && ![istarget sparc*-*-linux*] \ |
46 | && ![istarget s390*-*-linux*] \ | |
59758b1c | 47 | && ![istarget sh\[34\]*-*-linux*] \ |
9147e853 | 48 | && ![istarget x86_64-*-linux*] } { |
6fc49d28 L |
49 | return |
50 | } | |
51 | ||
04827a14 L |
52 | set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]] |
53 | foreach t $test_list { | |
54 | # We need to strip the ".d", but can leave the dirname. | |
55 | verbose [file rootname $t] | |
56 | run_dump_test [file rootname $t] | |
57 | } | |
58 | ||
6fc49d28 L |
59 | set tmpdir tmpdir |
60 | set SHCFLAG "" | |
a9f844b1 | 61 | set shared_needs_pic "no" |
91f8bf69 | 62 | set COMPRESS_LDFLAG "-Wl,--compress-debug-sections=zlib-gabi" |
6fc49d28 L |
63 | |
64 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
65 | ||
66 | # AIX shared libraries do not seem to support useful features, | |
67 | # like overriding the shared library function or letting the | |
68 | # shared library refer to objects defined in the main program. We | |
69 | # avoid testing those features. | |
70 | set SHCFLAG "-DXCOFF_TEST" | |
71 | ||
72 | # The AIX 3.2.5 loader appears to randomly fail when loading | |
73 | # shared libraries from NSF mounted partitions, so we avoid any | |
74 | # potential problems by using a local directory. | |
75 | catch {exec /bin/sh -c "echo $$"} pid | |
76 | set tmpdir /usr/tmp/ld.$pid | |
77 | catch "exec mkdir $tmpdir" exec_status | |
78 | ||
79 | # On AIX, we need to explicitly export the symbols the shared | |
80 | # library is going to provide, and need. | |
81 | set file [open $tmpdir/xcoff.exp w] | |
82 | puts $file shlibvar1 | |
83 | puts $file shlibvar2 | |
84 | puts $file shlib_shlibvar1 | |
85 | puts $file shlib_shlibvar2 | |
86 | puts $file shlib_shlibcall | |
87 | puts $file shlib_shlibcalled | |
88 | puts $file shlib_checkfunptr1 | |
89 | puts $file shlib_getfunptr1 | |
90 | puts $file shlib_check | |
91 | close $file | |
92 | } | |
93 | ||
a9f844b1 NC |
94 | if [istarget arm*-*-linux*] { |
95 | # On ARM section anchors can change the symbol pre-emptability for | |
5a68afcf | 96 | # non-PIC shared libraries, causing these tests to fail. Turn section |
a9f844b1 NC |
97 | # anchors off. |
98 | set SHCFLAG "-fno-section-anchors" | |
99 | ||
5a68afcf | 100 | # On targets that have MOVW the compiler will emit relocations which |
a9f844b1 | 101 | # the linker doesn't support when compiling -shared without -fpic. The |
5a68afcf | 102 | # test to find out whether we want to XFAIL the non-PIC tests requires |
a9f844b1 | 103 | # a compile - so we pre-calculate it here. We also note that this can |
0085488a WN |
104 | # only affect arm*-*-*eabi* targets as the old ABI doesn't support v7. |
105 | if [istarget arm*-*-*eabi*] { | |
a9f844b1 NC |
106 | set file [open $tmpdir/movw-detect.c w] |
107 | puts $file "void foo(void) { __asm (\"movw r0, #0\"); }" | |
108 | close $file | |
109 | if [run_host_cmd_yesno "$CC" "$CFLAGS -c $tmpdir/movw-detect.c -o $tmpdir/movw-detect.o"] { | |
110 | set shared_needs_pic "yes" | |
111 | } | |
112 | } | |
113 | } | |
114 | ||
08c44e65 L |
115 | set support_protected "no" |
116 | ||
5940a93c | 117 | if { [istarget *-*-linux*] |
5a68afcf | 118 | || [istarget *-*-nacl*] |
5940a93c | 119 | || [istarget *-*-gnu*] } { |
360e9586 | 120 | if [ld_compile "$CC -g $CFLAGS -DPROTECTED_CHECK" $srcdir/$subdir/main.c $tmpdir/main.o] { |
d9816402 | 121 | if [ld_link $CC $tmpdir/main "$tmpdir/main.o"] { |
08c44e65 L |
122 | catch "exec $tmpdir/main" support_protected |
123 | } | |
124 | } | |
125 | } | |
126 | ||
6fc49d28 L |
127 | # The test procedure. |
128 | proc visibility_test { visibility progname testname main sh1 sh2 dat args } { | |
b765d4e3 | 129 | global CC |
6fc49d28 L |
130 | global srcdir |
131 | global subdir | |
132 | global exec_output | |
133 | global link_output | |
134 | global host_triplet | |
135 | global tmpdir | |
136 | ||
137 | if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" } | |
138 | ||
139 | # Build the shared library. | |
140 | # On AIX, we need to use an export file. | |
141 | set shared -shared | |
142 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
143 | set shared "-bM:SRE -bE:$tmpdir/xcoff.exp" | |
144 | } | |
af2c48d8 L |
145 | if { [is_elf_format] && [check_shared_lib_support] } { |
146 | append shared " -Wl,-z,notext" | |
147 | } | |
d9816402 | 148 | if {![ld_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} { |
7cda33a1 | 149 | if { [ string match $visibility "hidden_undef" ] |
1ba54ee0 AM |
150 | && [regexp "undefined reference to \`\.?visibility\'" $link_output] |
151 | && [regexp "undefined reference to \`visibility_var\'" $link_output] } { | |
7cda33a1 L |
152 | pass "$testname" |
153 | } else { if { [ string match $visibility "protected_undef" ] | |
1ba54ee0 AM |
154 | && [regexp "undefined reference to \`\.?visibility\'" $link_output] |
155 | && [regexp "undefined reference to \`visibility_var\'" $link_output] } { | |
7cda33a1 L |
156 | pass "$testname" |
157 | } else { | |
158 | fail "$testname" | |
159 | }} | |
6fc49d28 L |
160 | return |
161 | } | |
162 | ||
163 | # Link against the shared library. Use -rpath so that the | |
164 | # dynamic linker can locate the shared library at runtime. | |
165 | # On AIX, we must include /lib in -rpath, as otherwise the loader | |
166 | # can not find -lc. | |
167 | set rpath $tmpdir | |
168 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
169 | set rpath /lib:$tmpdir | |
170 | } | |
d9816402 | 171 | if ![ld_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] { |
6fc49d28 | 172 | if { [ string match $visibility "hidden" ] |
1ba54ee0 AM |
173 | && [regexp "undefined reference to \`\.?visibility\'" $link_output] |
174 | && [regexp "undefined reference to \`visibility_var\'" $link_output] } { | |
7cda33a1 L |
175 | pass "$testname" |
176 | } else { if { [ string match $visibility "hidden_undef_def" ] | |
1ba54ee0 AM |
177 | && [regexp "undefined reference to \`\.?visibility\'" $link_output] |
178 | && [regexp "undefined reference to \`visibility_def\'" $link_output] | |
179 | && [regexp "undefined reference to \`\.?visibility_func\'" $link_output] | |
180 | && [regexp "undefined reference to \`visibility_var\'" $link_output] } { | |
6fc49d28 L |
181 | pass "$testname" |
182 | } else { | |
183 | fail "$testname" | |
7cda33a1 | 184 | }} |
6fc49d28 L |
185 | return |
186 | } | |
187 | ||
7cda33a1 L |
188 | if { [ string match $visibility "hidden" ] |
189 | || [ string match $visibility "hidden_undef" ] | |
190 | || [ string match $visibility "protected_undef" ] } { | |
6fc49d28 L |
191 | fail "$testname" |
192 | } | |
193 | ||
d9816402 AM |
194 | if ![isnative] { |
195 | unsupported "$testname" | |
196 | return | |
197 | } | |
198 | ||
6fc49d28 L |
199 | # Run the resulting program |
200 | send_log "$tmpdir/$progname >$tmpdir/$progname.out\n" | |
201 | verbose "$tmpdir/$progname >$tmpdir/$progname.out" | |
202 | catch "exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output | |
203 | if ![string match "" $exec_output] then { | |
204 | send_log "$exec_output\n" | |
205 | verbose "$exec_output" | |
206 | fail "$testname" | |
207 | return | |
208 | } | |
209 | ||
210 | send_log "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n" | |
211 | verbose "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" | |
212 | catch "exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output | |
213 | set exec_output [prune_warnings $exec_output] | |
214 | ||
215 | if {![string match "" $exec_output]} then { | |
216 | send_log "$exec_output\n" | |
217 | verbose "$exec_output" | |
218 | fail "$testname" | |
219 | return | |
220 | } | |
221 | ||
222 | pass "$testname" | |
223 | } | |
224 | ||
225 | proc visibility_run {visibility} { | |
226 | global CC | |
227 | global CFLAGS | |
228 | global SHCFLAG | |
229 | global srcdir | |
230 | global subdir | |
231 | global tmpdir | |
232 | global picflag | |
233 | global target_triplet | |
08c44e65 | 234 | global support_protected |
a9f844b1 | 235 | global shared_needs_pic |
faebca03 | 236 | global PLT_CFLAGS |
922109c7 | 237 | global NOPIE_CFLAGS |
91f8bf69 | 238 | global COMPRESS_LDFLAG |
6fc49d28 L |
239 | |
240 | if [ string match $visibility "hidden" ] { | |
241 | set VSBCFLAG "-DHIDDEN_TEST" | |
242 | } else { if [ string match $visibility "hidden_normal" ] { | |
243 | set VSBCFLAG "-DHIDDEN_NORMAL_TEST" | |
7cda33a1 L |
244 | } else { if [ string match $visibility "hidden_undef" ] { |
245 | set VSBCFLAG "-DHIDDEN_UNDEF_TEST" | |
246 | } else { if [ string match $visibility "hidden_undef_def" ] { | |
247 | set VSBCFLAG "-DHIDDEN_UNDEF_TEST -DDSO_DEFINE_TEST" | |
248 | } else { if [ string match $visibility "hidden_weak" ] { | |
249 | set VSBCFLAG "-DHIDDEN_WEAK_TEST" | |
6fc49d28 L |
250 | } else { if [ string match $visibility "protected" ] { |
251 | set VSBCFLAG "-DPROTECTED_TEST" | |
7cda33a1 L |
252 | } else { if [ string match $visibility "protected_undef" ] { |
253 | set VSBCFLAG "-DPROTECTED_UNDEF_TEST" | |
254 | } else { if [ string match $visibility "protected_undef_def" ] { | |
255 | set VSBCFLAG "-DPROTECTED_UNDEF_TEST -DDSO_DEFINE_TEST" | |
256 | } else { if [ string match $visibility "protected_weak" ] { | |
257 | set VSBCFLAG "-DPROTECTED_WEAK_TEST" | |
6fc49d28 L |
258 | } else { |
259 | set VSBCFLAG "" | |
7cda33a1 | 260 | }}}}}}}}} |
6fc49d28 | 261 | |
37095d07 AM |
262 | # Ensure we always start with a clean slate, for the "file exists" |
263 | # tests below. | |
264 | remote_file host delete $tmpdir/sh1p.o $tmpdir/sh2p.o $tmpdir/sh1np.o $tmpdir/sh2np.o | |
265 | ||
fb35d3d8 DD |
266 | if { [istarget powerpc*-*-linux*] \ |
267 | || ( [istarget mips*-*-linux*] && [at_least_gcc_version 4 3] )} { | |
2893311c AM |
268 | # Testing non-PIC libraries is a waste of effort on any target. |
269 | # If you don't pass -fpic or -fPIC to gcc, gcc will assume quite | |
270 | # reasonably that you are not compiling for a shared library. | |
271 | # It can then make optimisations that result in shared library | |
272 | # functions and variables not being overridable. Newer versions | |
273 | # of gcc are more likely to do this. | |
274 | } else { | |
faebca03 L |
275 | # Compile the main program. Make sure that PLT is used since PLT |
276 | # is expected. | |
277 | if ![ld_compile "$CC -g $PLT_CFLAGS $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] { | |
6fc49d28 L |
278 | unresolved "visibility ($visibility) (non PIC)" |
279 | unresolved "visibility ($visibility)" | |
280 | } else { | |
281 | # The shared library is composed of two files. First compile them | |
282 | # without using -fpic. That should work on an ELF system, | |
283 | # although it will be less efficient because the dynamic linker | |
284 | # will need to do more relocation work. However, note that not | |
285 | # using -fpic will cause some of the tests to return different | |
faebca03 | 286 | # results. Make sure that PLT is used since PLT is expected. |
922109c7 L |
287 | if { ![ld_compile "$CC -g $NOPIE_CFLAGS $PLT_CFLAGS $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o] |
288 | || ![ld_compile "$CC -g $NOPIE_CFLAGS $PLT_CFLAGS $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } { | |
6fc49d28 L |
289 | unresolved "visibility ($visibility) (non PIC)" |
290 | } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
ad995491 | 291 | visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o xcoff |
6fc49d28 L |
292 | } else { |
293 | # SunOS non PIC shared libraries don't permit some cases of | |
294 | # overriding. | |
1345a0c0 L |
295 | if { [ string match $visibility "protected" ] |
296 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
297 | if [ string match $support_protected "no" ] { |
298 | setup_xfail $target_triplet | |
299 | } | |
6fc49d28 | 300 | } |
212a6b8e RH |
301 | |
302 | # Non-pic code uses name binding rules for applications to | |
303 | # reference variables by gp-relative relocs, which can't be | |
304 | # used with overridable symbols. | |
ad995491 L |
305 | if { ![ string match $visibility "hidden_undef" ] |
306 | && ![ string match $visibility "protected_undef" ] } { | |
307 | setup_xfail "ia64-*-linux*" | |
212a6b8e | 308 | setup_xfail "alpha*-*-linux*" |
ad995491 | 309 | } |
4648dfcf MS |
310 | if { ![ string match $visibility "hidden" ] |
311 | && ![ string match $visibility "hidden_undef" ] | |
312 | && ![ string match $visibility "hidden_undef_def" ] | |
313 | && ![ string match $visibility "protected_undef" ] } { | |
314 | setup_xfail "s390x-*-linux*" | |
4dc570c2 JJ |
315 | if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } { |
316 | setup_xfail "sparc*-*-linux*" | |
317 | } | |
4648dfcf | 318 | } |
8b778942 L |
319 | if { [is_elf64 $tmpdir/mainnp.o] } { |
320 | setup_xfail "x86_64-*-linux*" | |
321 | } | |
3c995545 | 322 | setup_xfail "x86_64-*-linux-gnux32" |
c0d48c0b DA |
323 | if { ![istarget hppa*64*-*-linux*] } { |
324 | setup_xfail "hppa*-*-linux*" | |
325 | } | |
a9f844b1 NC |
326 | if [ string match $shared_needs_pic "yes" ] { |
327 | setup_xfail "arm*-*-linux*" | |
328 | } | |
212a6b8e | 329 | |
6fc49d28 L |
330 | visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o elfvsb |
331 | ||
332 | # Test ELF shared library relocations with a non-zero load | |
333 | # address for the library. Near as I can tell, the R_*_RELATIVE | |
334 | # relocations for various targets are broken in the case where | |
335 | # the load address is not zero (which is the default). | |
1345a0c0 L |
336 | if { [ string match $visibility "protected" ] |
337 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
338 | if [ string match $support_protected "no" ] { |
339 | setup_xfail $target_triplet | |
340 | } | |
6fc49d28 | 341 | } |
d1d8dddf L |
342 | if { [ string match $visibility "hidden_normal" ] |
343 | || [ string match $visibility "hidden_weak" ] | |
344 | || [ string match $visibility "protected" ] | |
345 | || [ string match $visibility "protected_undef_def" ] | |
346 | || [ string match $visibility "protected_weak" ] | |
347 | || [ string match $visibility "normal" ] } { | |
348 | setup_xfail "powerpc-*-linux*" | |
8c37241b | 349 | setup_xfail "s390x-*-linux*" |
4dc570c2 JJ |
350 | if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } { |
351 | setup_xfail "sparc*-*-linux*" | |
352 | } | |
d1d8dddf | 353 | } |
ad995491 L |
354 | if { ![ string match $visibility "hidden_undef" ] |
355 | && ![ string match $visibility "protected_undef" ] } { | |
356 | setup_xfail "ia64-*-linux*" | |
212a6b8e | 357 | setup_xfail "alpha*-*-linux*" |
66517a2f | 358 | setup_xfail "mips*-*-linux*" |
ad995491 | 359 | } |
8b778942 L |
360 | if { [is_elf64 $tmpdir/mainnp.o] } { |
361 | setup_xfail "x86_64-*-linux*" | |
362 | } | |
3c995545 | 363 | setup_xfail "x86_64-*-linux-gnux32" |
c0d48c0b DA |
364 | if { ![istarget hppa*64*-*-linux*] } { |
365 | setup_xfail "hppa*-*-linux*" | |
366 | } | |
a9f844b1 NC |
367 | if [ string match $shared_needs_pic "yes" ] { |
368 | setup_xfail "arm*-*-linux*" | |
369 | } | |
c0d48c0b | 370 | |
6fc49d28 L |
371 | visibility_test $visibility vnp "visibility ($visibility) (non PIC, load offset)" \ |
372 | mainnp.o sh1np.o sh2np.o elfvsb \ | |
bab55c05 | 373 | "-Wl,-T,$srcdir/$subdir/elf-offset.ld,--hash-style=sysv" |
6fc49d28 L |
374 | } } |
375 | ||
376 | # Now compile the code using -fpic. | |
377 | ||
5a68afcf | 378 | if { ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG -DSHARED $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o] |
125c6493 | 379 | || ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG -DSHARED $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } { |
6fc49d28 L |
380 | unresolved "visibility ($visibility)" |
381 | } else { | |
1345a0c0 L |
382 | if { [ string match $visibility "protected" ] |
383 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
384 | if [ string match $support_protected "no" ] { |
385 | setup_xfail $target_triplet | |
386 | } | |
6fc49d28 | 387 | } |
c9098af4 | 388 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { |
6fc49d28 L |
389 | visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o xcoff |
390 | } else { | |
91f8bf69 | 391 | visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o elfvsb $COMPRESS_LDFLAG |
c9098af4 | 392 | } |
6fc49d28 | 393 | } |
2893311c | 394 | }} |
6fc49d28 | 395 | |
2893311c AM |
396 | if { [istarget powerpc*-*-linux*] } { |
397 | # Don't bother. | |
398 | } else { | |
6fc49d28 | 399 | # Now do the same tests again, but this time compile main.c PIC. |
125c6493 | 400 | if ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG -DSHARED $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] { |
6fc49d28 L |
401 | unresolved "visibility ($visibility) (PIC main, non PIC so)" |
402 | unresolved "visibility ($visibility) (PIC main)" | |
403 | } else { | |
37095d07 AM |
404 | if { [ remote_file host exists $tmpdir/sh1np.o ] |
405 | && [ remote_file host exists $tmpdir/sh2np.o ] } { | |
6fc49d28 L |
406 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { |
407 | visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff | |
408 | } else { | |
409 | # SunOS non PIC shared libraries don't permit some cases of | |
410 | # overriding. | |
1345a0c0 L |
411 | if { [ string match $visibility "protected" ] |
412 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
413 | if [ string match $support_protected "no" ] { |
414 | setup_xfail $target_triplet | |
415 | } | |
6fc49d28 | 416 | } |
ad995491 L |
417 | if { ![ string match $visibility "hidden_undef" ] |
418 | && ![ string match $visibility "protected_undef" ] } { | |
419 | setup_xfail "ia64-*-linux*" | |
212a6b8e | 420 | setup_xfail "alpha*-*-linux*" |
ad995491 | 421 | } |
4648dfcf MS |
422 | if { ![ string match $visibility "hidden" ] |
423 | && ![ string match $visibility "hidden_undef" ] | |
424 | && ![ string match $visibility "hidden_undef_def" ] | |
425 | && ![ string match $visibility "protected_undef" ] } { | |
426 | setup_xfail "s390x-*-linux*" | |
4dc570c2 JJ |
427 | if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainp.o] } { |
428 | setup_xfail "sparc*-*-linux*" | |
429 | } | |
4648dfcf | 430 | } |
8b778942 L |
431 | if { [is_elf64 $tmpdir/mainp.o] } { |
432 | setup_xfail "x86_64-*-linux*" | |
433 | } | |
3c995545 | 434 | setup_xfail "x86_64-*-linux-gnux32" |
c0d48c0b DA |
435 | if { ![istarget hppa*64*-*-linux*] } { |
436 | setup_xfail "hppa*-*-linux*" | |
437 | } | |
a9f844b1 NC |
438 | if [ string match $shared_needs_pic "yes" ] { |
439 | setup_xfail "arm*-*-linux*" | |
440 | } | |
c0d48c0b | 441 | |
6fc49d28 L |
442 | visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o elfvsb |
443 | } | |
444 | } else { | |
445 | unresolved "visibility (PIC main, non PIC so)" | |
446 | } | |
447 | ||
37095d07 AM |
448 | if { [ remote_file host exists $tmpdir/sh1p.o ] |
449 | && [ remote_file host exists $tmpdir/sh2p.o ] } { | |
1345a0c0 L |
450 | if { [ string match $visibility "protected" ] |
451 | || [ string match $visibility "protected_undef_def" ] } { | |
08c44e65 L |
452 | if [ string match $support_protected "no" ] { |
453 | setup_xfail $target_triplet | |
454 | } | |
6fc49d28 L |
455 | } |
456 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { | |
457 | visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o xcoff | |
458 | } else { | |
459 | visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o elfvsb | |
460 | } | |
461 | } else { | |
462 | unresolved "visibility ($visibility) (PIC main)" | |
463 | } | |
2893311c | 464 | }} |
6fc49d28 L |
465 | } |
466 | ||
fb35d3d8 DD |
467 | # Old version of GCC for MIPS default to enabling -fpic |
468 | # and get confused if it is used on the command line. | |
469 | if { [istarget mips*-*-*] && ! [at_least_gcc_version 4 3] } then { | |
6fc49d28 L |
470 | set picflag "" |
471 | } else { | |
472 | # Unfortunately, the gcc argument is -fpic and the cc argument is | |
473 | # -KPIC. We have to try both. | |
474 | set picflag "-fpic" | |
475 | send_log "$CC $picflag\n" | |
476 | verbose "$CC $picflag" | |
477 | catch "exec $CC $picflag" exec_output | |
478 | send_log "$exec_output\n" | |
479 | verbose "--" "$exec_output" | |
480 | if { [string match "*illegal option*" $exec_output] \ | |
481 | || [string match "*option ignored*" $exec_output] \ | |
482 | || [string match "*unrecognized option*" $exec_output] \ | |
483 | || [string match "*passed to ld*" $exec_output] } { | |
c9098af4 | 484 | set picflag "-KPIC" |
6fc49d28 L |
485 | } |
486 | } | |
487 | verbose "Using $picflag to compile PIC code" | |
488 | ||
489 | visibility_run hidden | |
490 | visibility_run hidden_normal | |
7cda33a1 L |
491 | visibility_run hidden_undef |
492 | visibility_run hidden_undef_def | |
493 | visibility_run hidden_weak | |
6fc49d28 | 494 | visibility_run protected |
7cda33a1 L |
495 | visibility_run protected_undef |
496 | visibility_run protected_undef_def | |
497 | visibility_run protected_weak | |
6fc49d28 L |
498 | visibility_run normal |
499 | ||
22d5e339 L |
500 | if { ![ld_compile "$CC -g $CFLAGS" $srcdir/$subdir/common.c tmpdir/common.o] } { |
501 | unresolved "common hidden symbol" | |
502 | } else { | |
d9816402 | 503 | if ![ld_link $ld tmpdir/common "tmpdir/common.o"] { |
22d5e339 L |
504 | fail "common hidden symbol" |
505 | } else { | |
506 | pass "common hidden symbol" | |
507 | } | |
508 | } | |
509 | ||
510 | if { ![ld_compile "$CC -g $CFLAGS" $srcdir/$subdir/test.c tmpdir/test.o] } { | |
511 | unresolved "weak hidden symbol" | |
512 | } else { | |
125c6493 | 513 | if { ![ld_compile "$CC -g $CFLAGS -DSHARED $picflag" $srcdir/$subdir/sh3.c tmpdir/sh3.o] } { |
22d5e339 L |
514 | unresolved "weak hidden symbol" |
515 | } else { | |
d9816402 | 516 | if ![ld_link $ld tmpdir/sh3.so "-shared tmpdir/sh3.o"] { |
22d5e339 L |
517 | fail "weak hidden symbol" |
518 | } else { | |
d9816402 | 519 | if ![ld_link $ld tmpdir/weak "tmpdir/test.o tmpdir/sh3.o"] { |
22d5e339 L |
520 | fail "weak hidden symbol DSO last" |
521 | } else { | |
522 | pass "weak hidden symbol DSO last" | |
523 | } | |
d9816402 | 524 | if ![ld_link $ld tmpdir/weak "tmpdir/sh3.so tmpdir/test.o"] { |
22d5e339 L |
525 | fail "weak hidden symbol DSO first" |
526 | } else { | |
527 | pass "weak hidden symbol DSO first" | |
528 | } | |
529 | } | |
530 | } | |
531 | } | |
532 | ||
6fc49d28 L |
533 | if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } { |
534 | # Remove the temporary directory. | |
535 | catch "exec rm -rf $tmpdir" exec_status | |
536 | } |