OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [binutils-2.20.1/] [ld/] [testsuite/] [ld-elfvsb/] [elfvsb.exp] - Blame information for rev 215

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 205 julius
# Expect script for ld-visibility tests
2
#   Copyright 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007
3
#   Free Software Foundation, Inc.
4
#
5
# This file is part of the GNU Binutils.
6
#
7
# This program is free software; you can redistribute it and/or modify
8
# it under the terms of the GNU General Public License as published by
9
# the Free Software Foundation; either version 3 of the License, or
10
# (at your option) any later version.
11
#
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.
16
#
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
19
# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20
# MA 02110-1301, USA.
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
 
28
# This test can only be run on a couple of ELF platforms.
29
# Square bracket expressions seem to confuse istarget.
30
if { ![istarget hppa*64*-*-hpux*] \
31
     && ![istarget hppa*-*-linux*] \
32
     && ![istarget i?86-*-linux*] \
33
     && ![istarget ia64-*-linux*] \
34
     && ![istarget m68k-*-linux*] \
35
     && ![istarget mips*-*-linux*] \
36
     && ![istarget powerpc*-*-linux*] \
37
     && ![istarget arm*-*-linux*] \
38
     && ![istarget alpha*-*-linux*] \
39
     && ![istarget sparc*-*-linux*] \
40
     && ![istarget s390*-*-linux*] \
41
     && ![istarget sh\[34\]*-*-linux*] \
42
     && ![istarget x86_64-*-linux*] } {
43
    return
44
}
45
 
46
if { [istarget *-*-linux*aout*] \
47
     || [istarget *-*-linux*oldld*] } {
48
    return
49
}
50
 
51
set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
52
foreach t $test_list {
53
    # We need to strip the ".d", but can leave the dirname.
54
    verbose [file rootname $t]
55
    run_dump_test [file rootname $t]
56
}
57
 
58
# The remaining tests can only be run if ld generates native executables.
59
if ![isnative] then {return}
60
 
61
set tmpdir tmpdir
62
set SHCFLAG ""
63
 
64
if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
65
 
66
    # AIX shared libraries do not seem to support useful features,
67
    # like overriding the shared library function or letting the
68
    # shared library refer to objects defined in the main program.  We
69
    # avoid testing those features.
70
    set SHCFLAG "-DXCOFF_TEST"
71
 
72
    # The AIX 3.2.5 loader appears to randomly fail when loading
73
    # shared libraries from NSF mounted partitions, so we avoid any
74
    # potential problems by using a local directory.
75
    catch {exec /bin/sh -c "echo $$"} pid
76
    set tmpdir /usr/tmp/ld.$pid
77
    catch "exec mkdir $tmpdir" exec_status
78
 
79
    # On AIX, we need to explicitly export the symbols the shared
80
    # library is going to provide, and need.
81
    set file [open $tmpdir/xcoff.exp w]
82
    puts $file shlibvar1
83
    puts $file shlibvar2
84
    puts $file shlib_shlibvar1
85
    puts $file shlib_shlibvar2
86
    puts $file shlib_shlibcall
87
    puts $file shlib_shlibcalled
88
    puts $file shlib_checkfunptr1
89
    puts $file shlib_getfunptr1
90
    puts $file shlib_check
91
    close $file
92
}
93
 
94
set support_protected "no"
95
 
96
if [istarget *-*-linux*] {
97
    if [ld_compile "$CC -g $CFLAGS -DPROTECTED_CHECK" $srcdir/$subdir/main.c $tmpdir/main.o] {
98
      if [ld_simple_link $CC $tmpdir/main "$tmpdir/main.o"] {
99
        catch "exec $tmpdir/main" support_protected
100
      }
101
    }
102
}
103
 
104
# The test procedure.
105
proc visibility_test { visibility progname testname main sh1 sh2 dat args } {
106
    global CC
107
    global srcdir
108
    global subdir
109
    global exec_output
110
    global link_output
111
    global host_triplet
112
    global tmpdir
113
 
114
    if [llength $args] { set shldflags [lindex $args 0] } else { set shldflags "" }
115
 
116
    # Build the shared library.
117
    # On AIX, we need to use an export file.
118
    set shared -shared
119
    if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
120
        set shared "-bM:SRE -bE:$tmpdir/xcoff.exp"
121
    }
122
    if {![ld_simple_link $CC $tmpdir/$progname.so "$shared $shldflags $tmpdir/$sh1 $tmpdir/$sh2"]} {
123
        if { [ string match $visibility "hidden_undef" ]
124
             && [regexp "undefined reference to \`\.?visibility\'" $link_output]
125
             && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
126
            pass "$testname"
127
        } else { if { [ string match $visibility "protected_undef" ]
128
             && [regexp "undefined reference to \`\.?visibility\'" $link_output]
129
             && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
130
            pass "$testname"
131
        } else {
132
            fail "$testname"
133
        }}
134
        return
135
    }
136
 
137
    # Link against the shared library.  Use -rpath so that the
138
    # dynamic linker can locate the shared library at runtime.
139
    # On AIX, we must include /lib in -rpath, as otherwise the loader
140
    # can not find -lc.
141
    set rpath $tmpdir
142
    if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
143
        set rpath /lib:$tmpdir
144
    }
145
    if ![ld_simple_link $CC $tmpdir/$progname "-Wl,-rpath,$rpath $tmpdir/$main $tmpdir/$progname.so"] {
146
        if { [ string match $visibility "hidden" ]
147
             && [regexp "undefined reference to \`\.?visibility\'" $link_output]
148
             && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
149
            pass "$testname"
150
        } else { if { [ string match $visibility "hidden_undef_def" ]
151
             && [regexp "undefined reference to \`\.?visibility\'" $link_output]
152
             && [regexp "undefined reference to \`visibility_def\'" $link_output]
153
             && [regexp "undefined reference to \`\.?visibility_func\'" $link_output]
154
             && [regexp "undefined reference to \`visibility_var\'" $link_output] } {
155
            pass "$testname"
156
        } else {
157
            fail "$testname"
158
        }}
159
        return
160
    }
161
 
162
    if { [ string match $visibility "hidden" ]
163
         || [ string match $visibility "hidden_undef" ]
164
         || [ string match $visibility "protected_undef" ] } {
165
        fail "$testname"
166
    }
167
 
168
    # Run the resulting program
169
    send_log "$tmpdir/$progname >$tmpdir/$progname.out\n"
170
    verbose "$tmpdir/$progname >$tmpdir/$progname.out"
171
    catch "exec $tmpdir/$progname >$tmpdir/$progname.out" exec_output
172
    if ![string match "" $exec_output] then {
173
        send_log "$exec_output\n"
174
        verbose "$exec_output"
175
        fail "$testname"
176
        return
177
    }
178
 
179
    send_log "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat\n"
180
    verbose "diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat"
181
    catch "exec diff $tmpdir/$progname.out $srcdir/$subdir/$dat.dat" exec_output
182
    set exec_output [prune_warnings $exec_output]
183
 
184
    if {![string match "" $exec_output]} then {
185
        send_log "$exec_output\n"
186
        verbose "$exec_output"
187
        fail "$testname"
188
        return
189
    }
190
 
191
    pass "$testname"
192
}
193
 
194
proc visibility_run {visibility} {
195
    global CC
196
    global CFLAGS
197
    global SHCFLAG
198
    global srcdir
199
    global subdir
200
    global tmpdir
201
    global picflag
202
    global target_triplet
203
    global support_protected
204
 
205
    if [ string match $visibility "hidden" ] {
206
        set VSBCFLAG "-DHIDDEN_TEST"
207
    } else { if [ string match $visibility "hidden_normal" ] {
208
        set VSBCFLAG "-DHIDDEN_NORMAL_TEST"
209
    } else { if [ string match $visibility "hidden_undef" ] {
210
        set VSBCFLAG "-DHIDDEN_UNDEF_TEST"
211
    } else { if [ string match $visibility "hidden_undef_def" ] {
212
        set VSBCFLAG "-DHIDDEN_UNDEF_TEST -DDSO_DEFINE_TEST"
213
    } else { if [ string match $visibility "hidden_weak" ] {
214
        set VSBCFLAG "-DHIDDEN_WEAK_TEST"
215
    } else { if [ string match $visibility "protected" ] {
216
        set VSBCFLAG "-DPROTECTED_TEST"
217
    } else { if [ string match $visibility "protected_undef" ] {
218
        set VSBCFLAG "-DPROTECTED_UNDEF_TEST"
219
    } else { if [ string match $visibility "protected_undef_def" ] {
220
        set VSBCFLAG "-DPROTECTED_UNDEF_TEST -DDSO_DEFINE_TEST"
221
    } else { if [ string match $visibility "protected_weak" ] {
222
        set VSBCFLAG "-DPROTECTED_WEAK_TEST"
223
    } else {
224
        set VSBCFLAG ""
225
    }}}}}}}}}
226
 
227
    # Compile the main program.
228
    if ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/main.c $tmpdir/mainnp.o] {
229
        unresolved "visibility ($visibility) (non PIC)"
230
        unresolved "visibility ($visibility)"
231
    } else {
232
        # The shared library is composed of two files.  First compile them
233
        # without using -fpic.  That should work on an ELF system,
234
        # although it will be less efficient because the dynamic linker
235
        # will need to do more relocation work.  However, note that not
236
        # using -fpic will cause some of the tests to return different
237
        # results.
238
        if { ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh1.c $tmpdir/sh1np.o]
239
             || ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG" $srcdir/$subdir/sh2.c $tmpdir/sh2np.o] } {
240
            unresolved "visibility ($visibility) (non PIC)"
241
        } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
242
            visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o xcoff
243
        } else {
244
            # SunOS non PIC shared libraries don't permit some cases of
245
            # overriding.
246
            if { [ string match $visibility "protected" ]
247
                 || [ string match $visibility "protected_undef_def" ] } {
248
                if [ string match $support_protected "no" ] {
249
                    setup_xfail $target_triplet
250
                }
251
            } else {
252
                setup_xfail "*-*-sunos4*"
253
            }
254
 
255
            # Non-pic code uses name binding rules for applications to
256
            # reference variables by gp-relative relocs, which can't be
257
            # used with overridable symbols.
258
            if { ![ string match $visibility "hidden_undef" ]
259
                 && ![ string match $visibility "protected_undef" ] } {
260
                setup_xfail "ia64-*-linux*"
261
                setup_xfail "alpha*-*-linux*"
262
            }
263
            if { ![ string match $visibility "hidden" ]
264
                 && ![ string match $visibility "hidden_undef" ]
265
                 && ![ string match $visibility "hidden_undef_def" ]
266
                 && ![ string match $visibility "protected_undef" ] } {
267
                setup_xfail "s390x-*-linux*"
268
                if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
269
                    setup_xfail "sparc*-*-linux*"
270
                }
271
            }
272
            setup_xfail "x86_64-*-linux*"
273
            if { ![istarget hppa*64*-*-linux*] } {
274
                setup_xfail "hppa*-*-linux*"
275
            }
276
 
277
            visibility_test $visibility vnp "visibility ($visibility) (non PIC)" mainnp.o sh1np.o sh2np.o elfvsb
278
 
279
            # Test ELF shared library relocations with a non-zero load
280
            # address for the library.  Near as I can tell, the R_*_RELATIVE
281
            # relocations for various targets are broken in the case where
282
            # the load address is not zero (which is the default).
283
            if { [ string match $visibility "protected" ]
284
                 || [ string match $visibility "protected_undef_def" ] } {
285
                if [ string match $support_protected "no" ] {
286
                    setup_xfail $target_triplet
287
                }
288
            } else {
289
                setup_xfail "*-*-sunos4*"
290
                setup_xfail "*-*-linux*libc1"
291
            }
292
            if { [ string match $visibility "hidden_normal" ]
293
                 || [ string match $visibility "hidden_weak" ]
294
                 || [ string match $visibility "protected" ]
295
                 || [ string match $visibility "protected_undef_def" ]
296
                 || [ string match $visibility "protected_weak" ]
297
                 || [ string match $visibility "normal" ] } {
298
                setup_xfail "powerpc-*-linux*"
299
                setup_xfail "s390x-*-linux*"
300
                if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainnp.o] } {
301
                    setup_xfail "sparc*-*-linux*"
302
                }
303
            }
304
            if { ![ string match $visibility "hidden_undef" ]
305
                 && ![ string match $visibility "protected_undef" ] } {
306
                setup_xfail "ia64-*-linux*"
307
                setup_xfail "alpha*-*-linux*"
308
                setup_xfail "mips*-*-linux*"
309
            }
310
            setup_xfail "x86_64-*-linux*"
311
            if { ![istarget hppa*64*-*-linux*] } {
312
                setup_xfail "hppa*-*-linux*"
313
            }
314
 
315
            visibility_test $visibility vnp "visibility ($visibility) (non PIC, load offset)" \
316
                mainnp.o sh1np.o sh2np.o elfvsb \
317
                "-T $srcdir/$subdir/elf-offset.ld"
318
        } }
319
 
320
        # Now compile the code using -fpic.
321
 
322
        if { ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG -DSHARED $picflag" $srcdir/$subdir/sh1.c $tmpdir/sh1p.o]
323
            || ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG -DSHARED $picflag" $srcdir/$subdir/sh2.c $tmpdir/sh2p.o] } {
324
            unresolved "visibility ($visibility)"
325
        } else {
326
            if { [ string match $visibility "protected" ]
327
                 || [ string match $visibility "protected_undef_def" ] } {
328
                if [ string match $support_protected "no" ] {
329
                    setup_xfail $target_triplet
330
                }
331
            }
332
            # SunOS can not compare function pointers correctly
333
            if [istarget "*-*-sunos4*"] {
334
                visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o sun4
335
            } else { if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
336
                visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o xcoff
337
            } else {
338
                visibility_test $visibility vp "visibility ($visibility)" mainnp.o sh1p.o sh2p.o elfvsb
339
            } }
340
        }
341
    }
342
 
343
    # Now do the same tests again, but this time compile main.c PIC.
344
    if ![ld_compile "$CC -g $CFLAGS $SHCFLAG $VSBCFLAG -DSHARED $picflag" $srcdir/$subdir/main.c $tmpdir/mainp.o] {
345
        unresolved "visibility ($visibility) (PIC main, non PIC so)"
346
        unresolved "visibility ($visibility) (PIC main)"
347
    } else {
348
        if { [file exists $tmpdir/sh1np.o ] && [ file exists $tmpdir/sh2np.o ] } {
349
            if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
350
                visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o xcoff
351
            } else {
352
                # SunOS non PIC shared libraries don't permit some cases of
353
                # overriding.
354
                if { [ string match $visibility "protected" ]
355
                     || [ string match $visibility "protected_undef_def" ] } {
356
                    if [ string match $support_protected "no" ] {
357
                        setup_xfail $target_triplet
358
                    }
359
                } else {
360
                    setup_xfail "*-*-sunos4*"
361
                }
362
                if { ![ string match $visibility "hidden_undef" ]
363
                     && ![ string match $visibility "protected_undef" ] } {
364
                    setup_xfail "ia64-*-linux*"
365
                    setup_xfail "alpha*-*-linux*"
366
                }
367
                if { ![ string match $visibility "hidden" ]
368
                     && ![ string match $visibility "hidden_undef" ]
369
                     && ![ string match $visibility "hidden_undef_def" ]
370
                     && ![ string match $visibility "protected_undef" ] } {
371
                    setup_xfail "s390x-*-linux*"
372
                    if { [istarget sparc*-*-linux*] && [is_elf64 $tmpdir/mainp.o] } {
373
                        setup_xfail "sparc*-*-linux*"
374
                    }
375
                }
376
                setup_xfail "x86_64-*-linux*"
377
                if { ![istarget hppa*64*-*-linux*] } {
378
                    setup_xfail "hppa*-*-linux*"
379
                }
380
 
381
                visibility_test $visibility vmpnp "visibility ($visibility) (PIC main, non PIC so)" mainp.o sh1np.o sh2np.o elfvsb
382
            }
383
        } else {
384
            unresolved "visibility (PIC main, non PIC so)"
385
        }
386
 
387
        if { [file exists $tmpdir/sh1p.o ] && [ file exists $tmpdir/sh2p.o ] } {
388
            if { [ string match $visibility "protected" ]
389
                 || [ string match $visibility "protected_undef_def" ] } {
390
                if [ string match $support_protected "no" ] {
391
                    setup_xfail $target_triplet
392
                }
393
            }
394
            if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
395
                visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o xcoff
396
            } else {
397
                visibility_test $visibility vmpp "visibility ($visibility) (PIC main)" mainp.o sh1p.o sh2p.o elfvsb
398
            }
399
        } else {
400
            unresolved "visibility ($visibility) (PIC main)"
401
        }
402
    }
403
}
404
 
405
if [istarget mips*-*-*] {
406
    set picflag ""
407
} else {
408
    # Unfortunately, the gcc argument is -fpic and the cc argument is
409
    # -KPIC.  We have to try both.
410
    set picflag "-fpic"
411
    send_log "$CC $picflag\n"
412
    verbose "$CC $picflag"
413
    catch "exec $CC $picflag" exec_output
414
    send_log "$exec_output\n"
415
    verbose "--" "$exec_output"
416
    if { [string match "*illegal option*" $exec_output] \
417
         || [string match "*option ignored*" $exec_output] \
418
         || [string match "*unrecognized option*" $exec_output] \
419
         || [string match "*passed to ld*" $exec_output] } {
420
        if [istarget *-*-sunos4*] {
421
            set picflag "-pic"
422
        } else {
423
            set picflag "-KPIC"
424
        }
425
    }
426
}
427
verbose "Using $picflag to compile PIC code"
428
 
429
visibility_run hidden
430
visibility_run hidden_normal
431
visibility_run hidden_undef
432
visibility_run hidden_undef_def
433
visibility_run hidden_weak
434
visibility_run protected
435
visibility_run protected_undef
436
visibility_run protected_undef_def
437
visibility_run protected_weak
438
visibility_run normal
439
 
440
if { ![ld_compile "$CC -g $CFLAGS" $srcdir/$subdir/common.c tmpdir/common.o] } {
441
    unresolved "common hidden symbol"
442
} else {
443
    if ![ld_simple_link $ld tmpdir/common "tmpdir/common.o"] {
444
        fail "common hidden symbol"
445
    } else {
446
        pass "common hidden symbol"
447
    }
448
}
449
 
450
if { ![ld_compile "$CC -g $CFLAGS" $srcdir/$subdir/test.c tmpdir/test.o] } {
451
    unresolved "weak hidden symbol"
452
} else {
453
   if { ![ld_compile "$CC -g $CFLAGS -DSHARED $picflag" $srcdir/$subdir/sh3.c tmpdir/sh3.o] } {
454
        unresolved "weak hidden symbol"
455
    } else {
456
        if ![ld_simple_link $ld tmpdir/sh3.so "-shared tmpdir/sh3.o"] {
457
            fail "weak hidden symbol"
458
        } else {
459
            if ![ld_simple_link $ld tmpdir/weak "tmpdir/test.o tmpdir/sh3.o"] {
460
                fail "weak hidden symbol DSO last"
461
            } else {
462
                pass "weak hidden symbol DSO last"
463
            }
464
            if ![ld_simple_link $ld tmpdir/weak "tmpdir/sh3.so tmpdir/test.o"] {
465
                fail "weak hidden symbol DSO first"
466
            } else {
467
                pass "weak hidden symbol DSO first"
468
            }
469
        }
470
    }
471
}
472
 
473
if { [istarget rs6000*-*-aix*] || [istarget powerpc*-*-aix*] } {
474
    # Remove the temporary directory.
475
    catch "exec rm -rf $tmpdir" exec_status
476
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.