1# Expect script for --exclude-libs tests
2#   Copyright (C) 2004-2020 Free Software Foundation, Inc.
3#
4# This file is part of the GNU Binutils.
5#
6# This program is free software; you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation; either version 3 of the License, or
9# (at your option) any later version.
10#
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.
15#
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
18# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19# MA 02110-1301, USA.
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
29# No shared lib support on this target.
30if { [istarget "mcore-*-*"] } {
31    return
32}
33
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
42set test1 "ld link shared library"
43set test2 "ld export symbols from archive"
44set test3 "ld link shared library with --exclude-libs"
45set test4 "ld exclude symbols from archive - --exclude-libs libexclude"
46set test5 "ld exclude symbols from archive - --exclude-libs libexclude.a"
47set test6 "ld exclude symbols from archive - --exclude-libs ALL"
48set test7 "ld exclude symbols from archive - --exclude-libs foo:libexclude.a"
49set test8 "ld exclude symbols from archive - --exclude-libs foo,libexclude.a"
50set test9 "ld don't exclude symbols from archive - --exclude-libs foo:bar"
51
52if { ![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] } {
54    unresolved $test1
55    return
56}
57
58remote_file host delete "tmpdir/libexclude.a"
59set catch_output [run_host_cmd "$ar" "cq tmpdir/libexclude.a tmpdir/exclude2.o"]
60if {![string match "" $catch_output]} {
61    unresolved $test1
62    return
63}
64
65# Test that the symbol is normally exported.
66
67if { [ld_link $ld tmpdir/exclude.so "--shared tmpdir/exclude1.o -Ltmpdir -lexclude"] } {
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
78if { [ld_nm $nm "-D" tmpdir/exclude.so]
79     && [info exists nm_output(exclude_common)]
80     && [info exists nm_output(exclude_sym)] } {
81    pass $test2
82} else {
83    fail $test2
84}
85
86# Test --exclude-libs libexclude
87
88if { [ld_link $ld tmpdir/exclude.so "--exclude-libs libexclude --shared tmpdir/exclude1.o -Ltmpdir -lexclude"] } {
89    pass $test3
90} else {
91    fail $test3
92}
93
94if { [ld_nm $nm "-D" tmpdir/exclude.so]
95     && ! [info exists nm_output(exclude_common)]
96     &&  ! [info exists nm_output(exclude_sym)] } {
97    pass $test4
98} else {
99    fail $test4
100}
101
102# Test alternate spellings of --exclude-libs
103
104if { [ld_link $ld tmpdir/exclude.so "--exclude-libs libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
105     && [ld_nm $nm "-D" tmpdir/exclude.so]
106     && ! [info exists nm_output(exclude_common)]
107     && ! [info exists nm_output(exclude_sym)] } {
108    pass $test5
109} else {
110    fail $test5
111}
112
113if { [ld_link $ld tmpdir/exclude.so "--exclude-libs ALL --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
114     && [ld_nm $nm "-D" tmpdir/exclude.so]
115     && ! [info exists nm_output(exclude_common)]
116     && ! [info exists nm_output(exclude_sym)] } {
117    pass $test6
118} else {
119    fail $test6
120}
121
122if { [ld_link $ld tmpdir/exclude.so "--exclude-libs foo:libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
123     && [ld_nm $nm "-D" tmpdir/exclude.so]
124     && ! [info exists nm_output(exclude_common)]
125     && ! [info exists nm_output(exclude_sym)] } {
126    pass $test7
127} else {
128    fail $test7
129}
130
131if { [ld_link $ld tmpdir/exclude.so "--exclude-libs foo,libexclude.a --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
132     && [ld_nm $nm "-D" tmpdir/exclude.so]
133     && ! [info exists nm_output(exclude_common)]
134     && ! [info exists nm_output(exclude_sym)] } {
135    pass $test8
136} else {
137    fail $test8
138}
139
140if { [ld_link $ld tmpdir/exclude.so "--exclude-libs foo:bar --shared tmpdir/exclude1.o -Ltmpdir -lexclude"]
141     && [ld_nm $nm "-D" tmpdir/exclude.so]
142     && [info exists nm_output(exclude_common)]
143     && [info exists nm_output(exclude_sym)] } {
144    pass $test9
145} else {
146    fail $test9
147}
148