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