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