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