Commit | Line | Data |
---|---|---|
b58f81ae | 1 | # Expect script for --exclude-libs tests |
b3adc24a | 2 | # Copyright (C) 2004-2020 Free Software Foundation, Inc. |
b58f81ae | 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 | |
b58f81ae | 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 |
b58f81ae | 9 | # (at your option) any later version. |
f96b4a7b | 10 | # |
b58f81ae DJ |
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 | # |
b58f81ae DJ |
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. | |
b58f81ae DJ |
20 | |
21 | # Make sure that ld can hide symbols from libraries when building a shared | |
22 | # library. | |
23 | ||
24 | # This test can only be run on ELF platforms. | |
25 | if ![is_elf_format] { | |
26 | return | |
27 | } | |
28 | ||
0e99ae0c L |
29 | # No shared lib support on this target. |
30 | if { [istarget "mcore-*-*"] } { | |
b58f81ae DJ |
31 | return |
32 | } | |
33 | ||
de1491f0 BS |
34 | set as_opt "" |
35 | ||
36 | # This target requires extra as options when building code for shared | |
37 | # libraries. | |
38 | if { [istarget "tic6x-*-*"] } { | |
39 | set as_opt "-mpic -mpid=near" | |
40 | } | |
41 | ||
b58f81ae DJ |
42 | set test1 "ld link shared library" |
43 | set test2 "ld export symbols from archive" | |
44 | set test3 "ld link shared library with --exclude-libs" | |
45 | set test4 "ld exclude symbols from archive - --exclude-libs libexclude" | |
46 | set test5 "ld exclude symbols from archive - --exclude-libs libexclude.a" | |
47 | set test6 "ld exclude symbols from archive - --exclude-libs ALL" | |
48 | set test7 "ld exclude symbols from archive - --exclude-libs foo:libexclude.a" | |
49 | set test8 "ld exclude symbols from archive - --exclude-libs foo,libexclude.a" | |
50 | set test9 "ld don't exclude symbols from archive - --exclude-libs foo:bar" | |
51 | ||
de1491f0 BS |
52 | if { ![ld_assemble_flags $as $as_opt $srcdir/$subdir/exclude1.s tmpdir/exclude1.o ] |
53 | || ![ld_assemble_flags $as $as_opt $srcdir/$subdir/exclude2.s tmpdir/exclude2.o] } { | |
b58f81ae DJ |
54 | unresolved $test1 |
55 | return | |
56 | } | |
57 | ||
7f6a71ff JM |
58 | remote_file host delete "tmpdir/libexclude.a" |
59 | set catch_output [run_host_cmd "$ar" "cq tmpdir/libexclude.a tmpdir/exclude2.o"] | |
b58f81ae DJ |
60 | if {![string match "" $catch_output]} { |
61 | unresolved $test1 | |
62 | return | |
63 | } | |
64 | ||
65 | # Test that the symbol is normally exported. | |
66 | ||
d9816402 | 67 | if { [ld_link $ld tmpdir/exclude.so "--shared tmpdir/exclude1.o -Ltmpdir -lexclude"] } { |
b58f81ae DJ |
68 | pass $test1 |
69 | } else { | |
70 | if [string match "*shared not supported*" $link_output] { | |
71 | unsupported "$test1 - -shared is not supported by this target" | |
72 | } else { | |
73 | fail $test1 | |
74 | } | |
75 | return | |
76 | } | |
77 | ||
78 | if ![ld_nm $nm "-D" tmpdir/exclude.so] { | |
79 | unresolved $test2 | |
a0d49154 L |
80 | } elseif { [info exists nm_output(exclude_common)] |
81 | && [info exists nm_output(exclude_sym)] } { | |
b58f81ae DJ |
82 | pass $test2 |
83 | } else { | |
84 | fail $test2 | |
85 | } | |
86 | ||
87 | # Test --exclude-libs libexclude | |
88 | ||
d9816402 | 89 | if { [ld_link $ld tmpdir/exclude.so "--exclude-libs libexclude --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] } { |
b58f81ae DJ |
90 | pass $test3 |
91 | } else { | |
92 | fail $test3 | |
93 | } | |
94 | ||
95 | if ![ld_nm $nm "-D" tmpdir/exclude.so] { | |
96 | unresolved $test4 | |
a0d49154 L |
97 | } elseif { ! [info exists nm_output(exclude_common)] |
98 | && ! [info exists nm_output(exclude_sym)] } { | |
b58f81ae DJ |
99 | pass $test4 |
100 | } else { | |
101 | fail $test4 | |
102 | } | |
103 | ||
104 | # Test alternate spellings of --exclude-libs | |
105 | ||
d9816402 | 106 | if { [ld_link $ld tmpdir/exclude.so "--exclude-libs libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] |
b58f81ae | 107 | && [ld_nm $nm "-D" tmpdir/exclude.so] |
a0d49154 | 108 | && ! [info exists nm_output(exclude_common)] |
b58f81ae DJ |
109 | && ! [info exists nm_output(exclude_sym)] } { |
110 | pass $test5 | |
111 | } else { | |
112 | fail $test5 | |
113 | } | |
114 | ||
d9816402 | 115 | if { [ld_link $ld tmpdir/exclude.so "--exclude-libs ALL --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] |
b58f81ae | 116 | && [ld_nm $nm "-D" tmpdir/exclude.so] |
a0d49154 | 117 | && ! [info exists nm_output(exclude_common)] |
b58f81ae DJ |
118 | && ! [info exists nm_output(exclude_sym)] } { |
119 | pass $test6 | |
120 | } else { | |
121 | fail $test6 | |
122 | } | |
123 | ||
d9816402 | 124 | if { [ld_link $ld tmpdir/exclude.so "--exclude-libs foo:libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] |
b58f81ae | 125 | && [ld_nm $nm "-D" tmpdir/exclude.so] |
a0d49154 | 126 | && ! [info exists nm_output(exclude_common)] |
b58f81ae DJ |
127 | && ! [info exists nm_output(exclude_sym)] } { |
128 | pass $test7 | |
129 | } else { | |
130 | fail $test7 | |
131 | } | |
132 | ||
d9816402 | 133 | if { [ld_link $ld tmpdir/exclude.so "--exclude-libs foo,libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] |
b58f81ae | 134 | && [ld_nm $nm "-D" tmpdir/exclude.so] |
a0d49154 | 135 | && ! [info exists nm_output(exclude_common)] |
b58f81ae DJ |
136 | && ! [info exists nm_output(exclude_sym)] } { |
137 | pass $test8 | |
138 | } else { | |
139 | fail $test8 | |
140 | } | |
141 | ||
d9816402 | 142 | if { [ld_link $ld tmpdir/exclude.so "--exclude-libs foo:bar --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] |
b58f81ae | 143 | && [ld_nm $nm "-D" tmpdir/exclude.so] |
a0d49154 | 144 | && [info exists nm_output(exclude_common)] |
b58f81ae DJ |
145 | && [info exists nm_output(exclude_sym)] } { |
146 | pass $test9 | |
147 | } else { | |
148 | fail $test9 | |
149 | } |