2004-10-19 H.J. Lu <hongjiu.lu@intel.com>
[deliverable/binutils-gdb.git] / ld / testsuite / ld-elf / exclude.exp
CommitLineData
b58f81ae
DJ
1# Expect script for --exclude-libs tests
2# Copyright 2004 Free Software Foundation, Inc.
3#
4# This file is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2 of the License, or
7# (at your option) any later version.
8#
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13#
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
18# Make sure that ld can hide symbols from libraries when building a shared
19# library.
20
21# This test can only be run on ELF platforms.
22if ![is_elf_format] {
23 return
24}
25
cad5e2c2
HPN
26# No shared lib support on these targets.
27if { [istarget "mcore-*-*"] || [istarget "cris-*-elf"] } {
b58f81ae
DJ
28 return
29}
30
31global ar
32global as
33global ld
34global nm
35global nm_output
36
37set test1 "ld link shared library"
38set test2 "ld export symbols from archive"
39set test3 "ld link shared library with --exclude-libs"
40set test4 "ld exclude symbols from archive - --exclude-libs libexclude"
41set test5 "ld exclude symbols from archive - --exclude-libs libexclude.a"
42set test6 "ld exclude symbols from archive - --exclude-libs ALL"
43set test7 "ld exclude symbols from archive - --exclude-libs foo:libexclude.a"
44set test8 "ld exclude symbols from archive - --exclude-libs foo,libexclude.a"
45set test9 "ld don't exclude symbols from archive - --exclude-libs foo:bar"
46
47if { ![ld_assemble $as $srcdir/$subdir/exclude1.s tmpdir/exclude1.o ]
48 || ![ld_assemble $as $srcdir/$subdir/exclude2.s tmpdir/exclude2.o] } {
49 unresolved $test1
50 return
51}
52
53catch "exec rm -f tmpdir/libexclude.a" catch_output
54catch "exec $ar cq tmpdir/libexclude.a tmpdir/exclude2.o" catch_output
55if {![string match "" $catch_output]} {
56 unresolved $test1
57 return
58}
59
60# Test that the symbol is normally exported.
61
62if { [ld_simple_link $ld tmpdir/exclude.so "--shared tmpdir/exclude1.o -Ltmpdir -lexclude"] } {
63 pass $test1
64} else {
65 if [string match "*shared not supported*" $link_output] {
66 unsupported "$test1 - -shared is not supported by this target"
67 } else {
68 fail $test1
69 }
70 return
71}
72
73if ![ld_nm $nm "-D" tmpdir/exclude.so] {
74 unresolved $test2
75} elseif { [info exists nm_output(exclude_sym)] } {
76 pass $test2
77} else {
78 fail $test2
79}
80
81# Test --exclude-libs libexclude
82
83if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs libexclude --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] } {
84 pass $test3
85} else {
86 fail $test3
87}
88
89if ![ld_nm $nm "-D" tmpdir/exclude.so] {
90 unresolved $test4
91} elseif { ! [info exists nm_output(exclude_sym)] } {
92 pass $test4
93} else {
94 fail $test4
95}
96
97# Test alternate spellings of --exclude-libs
98
99if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
100 && [ld_nm $nm "-D" tmpdir/exclude.so]
101 && ! [info exists nm_output(exclude_sym)] } {
102 pass $test5
103} else {
104 fail $test5
105}
106
107if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs ALL --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
108 && [ld_nm $nm "-D" tmpdir/exclude.so]
109 && ! [info exists nm_output(exclude_sym)] } {
110 pass $test6
111} else {
112 fail $test6
113}
114
115if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo:libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
116 && [ld_nm $nm "-D" tmpdir/exclude.so]
117 && ! [info exists nm_output(exclude_sym)] } {
118 pass $test7
119} else {
120 fail $test7
121}
122
123if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo,libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
124 && [ld_nm $nm "-D" tmpdir/exclude.so]
125 && ! [info exists nm_output(exclude_sym)] } {
126 pass $test8
127} else {
128 fail $test8
129}
130
131if { [ld_simple_link $ld tmpdir/exclude.so "--exclude-libs foo:bar --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
132 && [ld_nm $nm "-D" tmpdir/exclude.so]
133 && [info exists nm_output(exclude_sym)] } {
134 pass $test9
135} else {
136 fail $test9
137}
This page took 0.028114 seconds and 4 git commands to generate.