[ARC] Add SYNTAX_NOP and SYNTAX_1OP for extension instructions
[deliverable/binutils-gdb.git] / ld / testsuite / ld-unique / unique.exp
CommitLineData
f64b2e8d
NC
1# Expect script for linker support of STB_GNU_UNIQUE symbols
2#
6f2750fe 3# Copyright (C) 2009-2016 Free Software Foundation, Inc.
f64b2e8d
NC
4# Contributed by Red Hat.
5#
6# This file is part of the GNU Binutils.
7#
8# This program is free software; you can redistribute it and/or modify
9# it under the terms of the GNU General Public License as published by
10# the Free Software Foundation; either version 3 of the License, or
11# (at your option) any later version.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License
19# along with this program; if not, write to the Free Software
20# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
21# MA 02110-1301, USA.
22#
23# Written by Nick Clifton <nickc@redhat.com>
24# Adapted for unique checking by Mark J. Wielaard <mjw@redhat.com>
25
26
27# STB_GNU_UNIQUE support has only been implemented for the ix86, x86_64,
6d6a648c 28# arm, mips, powerpc, and sparc so far.
f64b2e8d
NC
29if {!(([istarget "i?86-*-*"]
30 || [istarget "x86_64-*-*"]
62cf91a3 31 || [istarget "arm*-*-*"]
6d6a648c 32 || [istarget "mips*-*-*"]
f64b2e8d
NC
33 || [istarget "powerpc*-*-*"]
34 || [istarget "sparc*-*-*"])
35 && ([istarget "*-*-elf*"]
5a68afcf 36 || [istarget "*-*-nacl*"]
f64b2e8d
NC
37 || (([istarget "*-*-linux*"]
38 || [istarget "*-*-gnu*"])
39 && ![istarget "*-*-*aout*"]
40 && ![istarget "*-*-*oldld*"]))) } {
41 verbose "UNIQUE tests not run - target does not support UNIQUE"
42 return
43}
44
45# We need a native system. FIXME: Strictly speaking this
46# is not true, we just need to know how to create a fully
47# linked executable, including the C and Z libraries, using
48# the linker that is under test.
49if ![isnative] {
50 verbose "UNIQUE tests not run - not a native toolchain"
51 return
52}
53
54# We need a working compiler. (Strictly speaking this is
55# not true, we could use target specific assembler files).
56if { [which $CC] == 0 } {
57 verbose "UNIQUE tests not run - no compiler available"
58 return
59}
60
61# A procedure to check the OS/ABI field in the ELF header of a binary file.
62proc check_osabi { binary_file expected_osabi } {
63 global READELF
64 global READELFFLAGS
65
66 catch "exec $READELF $READELFFLAGS --file-header $binary_file > readelf.out" got
67
68 if ![string match "" $got] then {
69 verbose "proc check_osabi: Readelf produced unexpected out processing $binary_file: $got"
70 return 0
71 }
72
73 if { ![regexp "\n\[ \]*OS/ABI:\[ \]*(.+)\n\[ \]*ABI" \
74 [file_contents readelf.out] nil osabi] } {
75 verbose "proc check_osabi: Readelf failed to extract an ELF header from $binary_file"
76 return 0
77 }
78
79 if { $osabi == $expected_osabi } {
80 return 1
81 }
82
83 verbose "Expected OSABI: $expected_osabi, Obtained osabi: $osabi"
84
85 return 0
86}
87
88# A procedure to confirm that a file contains the UNIQUE symbol.
89# Returns -1 upon error, 0 if the symbol was not found and 1 if it was found.
90proc contains_unique_symbol { binary_file } {
91 global READELF
92 global READELFFLAGS
93
94 catch "exec $READELF $READELFFLAGS --symbols $binary_file > readelf.out" got
95
96 if ![string match "" $got] then {
97 verbose "proc contains_unique_symbol: Readelf produced unexpected out processing $binary_file: $got"
98 return -1
99 }
100
101 # Look for a line like this:
102 # 54: 0000000000400474 4 OBJECT UNIQUE DEFAULT 13 a
103
104 if { ![regexp ".*\[ \]*OBJECT\[ \]+UNIQUE\[ \]+DEFAULT\[ \]+\[UND0-9\]+\[ \]+\[ab\]\n" [file_contents readelf.out]] } {
105 return 0
106 }
107
108 return 1
109}
110
111set fails 0
112
113# Create object file containing unique symbol.
114if ![ld_compile "$CC -c" "$srcdir/$subdir/unique.s" "tmpdir/unique.o"] {
115 fail "Could not create a unique object"
116 set fails [expr $fails + 1]
117}
118
119# Create object file NOT containing unique symbol.
120if ![ld_compile "$CC -c" "$srcdir/$subdir/unique_empty.s" "tmpdir/unique_empty.o"] {
121 fail "Could not create a non-unique object"
122 set fails [expr $fails + 1]
123}
124
125# Create pic object file containing unique symbol.
126if ![ld_compile "$CC -c -fPIC" "$srcdir/$subdir/unique_shared.s" "tmpdir/unique_shared.o"] {
127 fail "Could not create a pic unique object"
128 set fails [expr $fails + 1]
129}
130
131# Create executable containing unique symbol.
132if ![default_ld_link $ld "tmpdir/unique_prog" "tmpdir/unique.o"] {
133 fail "Could not link a unique executable"
134 set fails [expr $fails + 1]
135}
136
137# Create shared library containing unique symbol.
138if ![ld_simple_link $ld "tmpdir/libunique_shared.so" "-shared tmpdir/unique_shared.o"] {
139 fail "Could not create a shared library containing an unique symbol"
140 set fails [expr $fails + 1]
141}
142
143# Create executable NOT containing unique symbol linked against library.
144if ![default_ld_link $ld "tmpdir/unique_shared_prog" "-Ltmpdir tmpdir/unique_empty.o -Bdynamic -lunique_shared -rpath ./tmpdir"] {
145 fail "Could not link a dynamic executable"
146 set fails [expr $fails + 1]
147}
148
35399224
L
149# Create shared library containing unique symbol with reference.
150if ![ld_simple_link $ld "tmpdir/libunique_shared_ref.so" "-shared tmpdir/unique_shared.o tmpdir/unique_empty.o"] {
151 fail "Could not create a shared library containing an unique symbol with reference"
152 set fails [expr $fails + 1]
153}
154
f64b2e8d
NC
155if { $fails != 0 } {
156 return
157}
158
159# Check the object file.
9c55345c
TS
160if {! [check_osabi tmpdir/unique.o {UNIX - GNU}]} {
161 fail "Object containing unique does not have an OS/ABI field of GNU"
f64b2e8d
NC
162 set fails [expr $fails + 1]
163}
164
165if {[contains_unique_symbol tmpdir/unique.o] != 1} {
166 fail "Object containing unique does not contain an UNIQUE symbol"
167 set fails [expr $fails + 1]
168}
169
170if { $fails == 0 } {
171 pass "Checking unique object"
172}
173
174# Check the executable.
9c55345c
TS
175if {! [check_osabi tmpdir/unique_prog {UNIX - GNU}]} {
176 fail "Executable containing unique does not have an OS/ABI field of GNU"
f64b2e8d
NC
177 set fails [expr $fails + 1]
178}
179
180if {[contains_unique_symbol tmpdir/unique_prog] != 1} {
181 fail "Executable containing unique does not contain an UNIQUE symbol"
182 set fails [expr $fails + 1]
183}
184
185if { $fails == 0 } {
186 pass "Checking unique executable"
187}
188
189# Check the empty object file.
190if {! [check_osabi tmpdir/unique_empty.o {UNIX - System V}]} {
191 fail "Object NOT containing unique does not have an OS/ABI field of System V"
192 set fails [expr $fails + 1]
193}
194
195if {[contains_unique_symbol tmpdir/unique_empty.o] == 1} {
196 fail "Object NOT containing unique does contain an UNIQUE symbol"
197 set fails [expr $fails + 1]
198}
199
200if { $fails == 0 } {
201 pass "Checking empty unique object"
202}
203
204# Check the unique PIC file.
9c55345c
TS
205if {! [check_osabi tmpdir/unique_shared.o {UNIX - GNU}]} {
206 fail "PIC Object containing unique does not have an OS/ABI field of GNU"
f64b2e8d
NC
207 set fails [expr $fails + 1]
208}
209
210if {[contains_unique_symbol tmpdir/unique_shared.o] != 1} {
211 fail "PIC Object containing unique does not contain an UNIQUE symbol"
212 set fails [expr $fails + 1]
213}
214
215if { $fails == 0 } {
216 pass "Checking unique PIC object"
217}
218
219# Check the unique shared library.
9c55345c
TS
220if {! [check_osabi tmpdir/libunique_shared.so {UNIX - GNU}]} {
221 fail "Shared library containing unique does not have an OS/ABI field of GNU"
f64b2e8d
NC
222 set fails [expr $fails + 1]
223}
224
225if {[contains_unique_symbol tmpdir/libunique_shared.so] != 1} {
226 fail "Shared library containing unique does not contain an UNIQUE symbol"
227 set fails [expr $fails + 1]
228}
229
35399224
L
230# Check the unique shared library with reference.
231if {! [check_osabi tmpdir/libunique_shared_ref.so {UNIX - GNU}]} {
232 fail "Shared library containing unique with reference does not have an OS/ABI field of GNU"
233 set fails [expr $fails + 1]
234}
235
236if {[contains_unique_symbol tmpdir/libunique_shared_ref.so] != 1} {
237 fail "Shared library containing unique with reference does not contain an UNIQUE symbol"
238 set fails [expr $fails + 1]
239}
240
f64b2e8d
NC
241if { $fails == 0 } {
242 pass "Checking unique PIC object"
243}
244
245# Check the empty executable linked against unique shared library.
246if {! [check_osabi tmpdir/unique_shared_prog {UNIX - System V}]} {
247 fail "Executable NOT containing unique does not have an OS/ABI field of System V"
248 set fails [expr $fails + 1]
249}
250
251if {[contains_unique_symbol tmpdir/unique_shared_prog] == 1} {
252 fail "Executable NOT containing unique does contain an UNIQUE symbol"
253 set fails [expr $fails + 1]
254}
255
256if { $fails == 0 } {
257 pass "Checking shared empty executable"
258}
259
260# Clean up, unless we are being verbose, in which case we leave the files available.
261if { $verbose < 1 } {
262 remote_file host delete "tmpdir/unique_empty.o"
263 remote_file host delete "tmpdir/unique.o"
264 remote_file host delete "tmpdir/unique_shared.o"
265 remote_file host delete "tmpdir/libunique_shared.so"
35399224 266 remote_file host delete "tmpdir/libunique_shared_ref.so"
f64b2e8d
NC
267 remote_file host delete "tmpdir/unique_prog"
268 remote_file host delete "tmpdir/unique_shared_prog"
269}
This page took 0.23649 seconds and 4 git commands to generate.