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