1 # Expect script
for linker support of STB_GNU_UNIQUE symbols
3 # Copyright
2009, 2010, 2011 Free Software Foundation
, Inc.
4 # Contributed by Red Hat.
6 # This file is part of the GNU Binutils.
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.
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.
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
,
23 # Written by Nick Clifton
<nickc@redhat.com
>
24 # Adapted
for unique checking by Mark J. Wielaard
<mjw@redhat.com
>
27 # STB_GNU_UNIQUE support has only been implemented
for the ix86
, x86_64
,
28 # arm
, powerpc
, and sparc so far.
29 if {!(([istarget
"i?86-*-*"]
30 ||
[istarget
"x86_64-*-*"]
31 ||
[istarget
"arm-*-*"]
32 ||
[istarget
"powerpc*-*-*"]
33 ||
[istarget
"sparc*-*-*"])
34 && ([istarget
"*-*-elf*"]
35 ||
(([istarget
"*-*-linux*"]
36 ||
[istarget
"*-*-gnu*"])
37 && ![istarget
"*-*-*aout*"]
38 && ![istarget
"*-*-*oldld*"]))) } {
39 verbose
"UNIQUE tests not run - target does not support UNIQUE"
43 # We need a native
system. FIXME
: Strictly speaking this
44 # is not true
, we just need to know how to create a fully
45 # linked executable
, including the C and Z libraries
, using
46 # the linker that is under test.
48 verbose
"UNIQUE tests not run - not a native toolchain"
52 # We need a working compiler.
(Strictly speaking this is
53 # not true
, we could use target specific assembler files
).
54 if { [which $CC
] == 0 } {
55 verbose
"UNIQUE tests not run - no compiler available"
59 # A procedure to check the OS
/ABI field in the ELF header of a binary file.
60 proc check_osabi
{ binary_file expected_osabi
} {
64 catch
"exec $READELF $READELFFLAGS --file-header $binary_file > readelf.out" got
66 if ![string match
"" $got] then {
67 verbose
"proc check_osabi: Readelf produced unexpected out processing $binary_file: $got"
71 if { ![regexp
"\n\[ \]*OS/ABI:\[ \]*(.+)\n\[ \]*ABI" \
72 [file_contents readelf.out
] nil osabi
] } {
73 verbose
"proc check_osabi: Readelf failed to extract an ELF header from $binary_file"
77 if { $osabi
== $expected_osabi
} {
81 verbose
"Expected OSABI: $expected_osabi, Obtained osabi: $osabi"
86 # A procedure to confirm that a file contains the UNIQUE symbol.
87 # Returns
-1 upon error
, 0 if the symbol was not found and
1 if it was found.
88 proc contains_unique_symbol
{ binary_file
} {
92 catch
"exec $READELF $READELFFLAGS --symbols $binary_file > readelf.out" got
94 if ![string match
"" $got] then {
95 verbose
"proc contains_unique_symbol: Readelf produced unexpected out processing $binary_file: $got"
99 # Look
for a line like this
:
100 #
54: 0000000000400474 4 OBJECT UNIQUE DEFAULT
13 a
102 if { ![regexp
".*\[ \]*OBJECT\[ \]+UNIQUE\[ \]+DEFAULT\[ \]+\[UND0-9\]+\[ \]+\[ab\]\n" [file_contents readelf.out]] } {
111 # Create object file containing unique symbol.
112 if ![ld_compile
"$CC -c" "$srcdir/$subdir/unique.s" "tmpdir/unique.o"] {
113 fail
"Could not create a unique object"
114 set fails
[expr $fails
+ 1]
117 # Create object file NOT containing unique symbol.
118 if ![ld_compile
"$CC -c" "$srcdir/$subdir/unique_empty.s" "tmpdir/unique_empty.o"] {
119 fail
"Could not create a non-unique object"
120 set fails
[expr $fails
+ 1]
123 # Create pic object file containing unique symbol.
124 if ![ld_compile
"$CC -c -fPIC" "$srcdir/$subdir/unique_shared.s" "tmpdir/unique_shared.o"] {
125 fail
"Could not create a pic unique object"
126 set fails
[expr $fails
+ 1]
129 # Create executable containing unique symbol.
130 if ![default_ld_link $
ld "tmpdir/unique_prog" "tmpdir/unique.o"] {
131 fail
"Could not link a unique executable"
132 set fails
[expr $fails
+ 1]
135 # Create shared library containing unique symbol.
136 if ![ld_simple_link $
ld "tmpdir/libunique_shared.so" "-shared tmpdir/unique_shared.o"] {
137 fail
"Could not create a shared library containing an unique symbol"
138 set fails
[expr $fails
+ 1]
141 # Create executable NOT containing unique symbol linked against library.
142 if ![default_ld_link $
ld "tmpdir/unique_shared_prog" "-Ltmpdir tmpdir/unique_empty.o -Bdynamic -lunique_shared -rpath ./tmpdir"] {
143 fail
"Could not link a dynamic executable"
144 set fails
[expr $fails
+ 1]
151 # Check the object file.
152 if {! [check_osabi tmpdir
/unique.o
{UNIX
- GNU
}]} {
153 fail
"Object containing unique does not have an OS/ABI field of GNU"
154 set fails
[expr $fails
+ 1]
157 if {[contains_unique_symbol tmpdir
/unique.o
] != 1} {
158 fail
"Object containing unique does not contain an UNIQUE symbol"
159 set fails
[expr $fails
+ 1]
163 pass
"Checking unique object"
166 # Check the executable.
167 if {! [check_osabi tmpdir
/unique_prog
{UNIX
- GNU
}]} {
168 fail
"Executable containing unique does not have an OS/ABI field of GNU"
169 set fails
[expr $fails
+ 1]
172 if {[contains_unique_symbol tmpdir
/unique_prog
] != 1} {
173 fail
"Executable containing unique does not contain an UNIQUE symbol"
174 set fails
[expr $fails
+ 1]
178 pass
"Checking unique executable"
181 # Check the empty object file.
182 if {! [check_osabi tmpdir
/unique_empty.o
{UNIX
- System V
}]} {
183 fail
"Object NOT containing unique does not have an OS/ABI field of System V"
184 set fails
[expr $fails
+ 1]
187 if {[contains_unique_symbol tmpdir
/unique_empty.o
] == 1} {
188 fail
"Object NOT containing unique does contain an UNIQUE symbol"
189 set fails
[expr $fails
+ 1]
193 pass
"Checking empty unique object"
196 # Check the unique PIC file.
197 if {! [check_osabi tmpdir
/unique_shared.o
{UNIX
- GNU
}]} {
198 fail
"PIC Object containing unique does not have an OS/ABI field of GNU"
199 set fails
[expr $fails
+ 1]
202 if {[contains_unique_symbol tmpdir
/unique_shared.o
] != 1} {
203 fail
"PIC Object containing unique does not contain an UNIQUE symbol"
204 set fails
[expr $fails
+ 1]
208 pass
"Checking unique PIC object"
211 # Check the unique shared library.
212 if {! [check_osabi tmpdir
/libunique_shared.so
{UNIX
- GNU
}]} {
213 fail
"Shared library containing unique does not have an OS/ABI field of GNU"
214 set fails
[expr $fails
+ 1]
217 if {[contains_unique_symbol tmpdir
/libunique_shared.so
] != 1} {
218 fail
"Shared library containing unique does not contain an UNIQUE symbol"
219 set fails
[expr $fails
+ 1]
223 pass
"Checking unique PIC object"
226 # Check the empty executable linked against unique shared library.
227 if {! [check_osabi tmpdir
/unique_shared_prog
{UNIX
- System V
}]} {
228 fail
"Executable NOT containing unique does not have an OS/ABI field of System V"
229 set fails
[expr $fails
+ 1]
232 if {[contains_unique_symbol tmpdir
/unique_shared_prog
] == 1} {
233 fail
"Executable NOT containing unique does contain an UNIQUE symbol"
234 set fails
[expr $fails
+ 1]
238 pass
"Checking shared empty executable"
241 # Clean up
, unless we are being verbose
, in which case we leave the files available.
242 if { $verbose
< 1 } {
243 remote_file host
delete "tmpdir/unique_empty.o"
244 remote_file host
delete "tmpdir/unique.o"
245 remote_file host
delete "tmpdir/unique_shared.o"
246 remote_file host
delete "tmpdir/libunique_shared.so"
247 remote_file host
delete "tmpdir/unique_prog"
248 remote_file host
delete "tmpdir/unique_shared_prog"