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