Stop the (optional) dialong control data from being aligned when parsing/writing...
[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#
2571583a 3# Copyright (C) 2009-2017 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
a43942db
MR
27# Exclude non-ELF targets.
28if { ![is_elf_format] } {
29 return
30}
31
32# Require STB_GNU_UNIQUE support with OSABI set to GNU.
33if { ![supports_gnu_unique] } {
f64b2e8d
NC
34 verbose "UNIQUE tests not run - target does not support UNIQUE"
35 return
36}
37
c3fbf828
MR
38run_dump_test "unique"
39
f64b2e8d
NC
40# We need a working compiler. (Strictly speaking this is
41# not true, we could use target specific assembler files).
42if { [which $CC] == 0 } {
c3fbf828 43 verbose "UNIQUE compiled tests not run - no compiler available"
f64b2e8d
NC
44 return
45}
46
47# A procedure to check the OS/ABI field in the ELF header of a binary file.
48proc check_osabi { binary_file expected_osabi } {
49 global READELF
50 global READELFFLAGS
51
52 catch "exec $READELF $READELFFLAGS --file-header $binary_file > readelf.out" got
53
54 if ![string match "" $got] then {
55 verbose "proc check_osabi: Readelf produced unexpected out processing $binary_file: $got"
56 return 0
57 }
58
59 if { ![regexp "\n\[ \]*OS/ABI:\[ \]*(.+)\n\[ \]*ABI" \
60 [file_contents readelf.out] nil osabi] } {
61 verbose "proc check_osabi: Readelf failed to extract an ELF header from $binary_file"
62 return 0
63 }
64
65 if { $osabi == $expected_osabi } {
66 return 1
67 }
68
69 verbose "Expected OSABI: $expected_osabi, Obtained osabi: $osabi"
70
71 return 0
72}
73
74# A procedure to confirm that a file contains the UNIQUE symbol.
75# Returns -1 upon error, 0 if the symbol was not found and 1 if it was found.
76proc contains_unique_symbol { binary_file } {
77 global READELF
78 global READELFFLAGS
79
80 catch "exec $READELF $READELFFLAGS --symbols $binary_file > readelf.out" got
81
82 if ![string match "" $got] then {
83 verbose "proc contains_unique_symbol: Readelf produced unexpected out processing $binary_file: $got"
84 return -1
85 }
86
87 # Look for a line like this:
88 # 54: 0000000000400474 4 OBJECT UNIQUE DEFAULT 13 a
89
90 if { ![regexp ".*\[ \]*OBJECT\[ \]+UNIQUE\[ \]+DEFAULT\[ \]+\[UND0-9\]+\[ \]+\[ab\]\n" [file_contents readelf.out]] } {
91 return 0
92 }
93
94 return 1
95}
96
97set fails 0
98
99# Create object file containing unique symbol.
100if ![ld_compile "$CC -c" "$srcdir/$subdir/unique.s" "tmpdir/unique.o"] {
101 fail "Could not create a unique object"
102 set fails [expr $fails + 1]
103}
104
105# Create object file NOT containing unique symbol.
106if ![ld_compile "$CC -c" "$srcdir/$subdir/unique_empty.s" "tmpdir/unique_empty.o"] {
107 fail "Could not create a non-unique object"
108 set fails [expr $fails + 1]
109}
110
111# Create pic object file containing unique symbol.
112if ![ld_compile "$CC -c -fPIC" "$srcdir/$subdir/unique_shared.s" "tmpdir/unique_shared.o"] {
113 fail "Could not create a pic unique object"
114 set fails [expr $fails + 1]
115}
116
117# Create executable containing unique symbol.
d9816402 118if ![ld_link $CC "tmpdir/unique_prog" "tmpdir/unique.o"] {
f64b2e8d
NC
119 fail "Could not link a unique executable"
120 set fails [expr $fails + 1]
121}
122
123# Create shared library containing unique symbol.
d9816402 124if ![ld_link $ld "tmpdir/libunique_shared.so" "-shared tmpdir/unique_shared.o"] {
f64b2e8d
NC
125 fail "Could not create a shared library containing an unique symbol"
126 set fails [expr $fails + 1]
127}
128
129# Create executable NOT containing unique symbol linked against library.
d9816402 130if ![ld_link $CC "tmpdir/unique_shared_prog" "-Ltmpdir tmpdir/unique_empty.o -Wl,-Bdynamic,-rpath=./tmpdir -lunique_shared"] {
f64b2e8d
NC
131 fail "Could not link a dynamic executable"
132 set fails [expr $fails + 1]
133}
134
35399224 135# Create shared library containing unique symbol with reference.
d9816402 136if ![ld_link $ld "tmpdir/libunique_shared_ref.so" "-shared tmpdir/unique_shared.o tmpdir/unique_empty.o"] {
35399224
L
137 fail "Could not create a shared library containing an unique symbol with reference"
138 set fails [expr $fails + 1]
139}
140
f64b2e8d
NC
141if { $fails != 0 } {
142 return
143}
144
145# Check the object file.
9c55345c
TS
146if {! [check_osabi tmpdir/unique.o {UNIX - GNU}]} {
147 fail "Object containing unique does not have an OS/ABI field of GNU"
f64b2e8d
NC
148 set fails [expr $fails + 1]
149}
150
151if {[contains_unique_symbol tmpdir/unique.o] != 1} {
152 fail "Object containing unique does not contain an UNIQUE symbol"
153 set fails [expr $fails + 1]
154}
155
156if { $fails == 0 } {
157 pass "Checking unique object"
158}
159
160# Check the executable.
9c55345c
TS
161if {! [check_osabi tmpdir/unique_prog {UNIX - GNU}]} {
162 fail "Executable containing unique does not have an OS/ABI field of GNU"
f64b2e8d
NC
163 set fails [expr $fails + 1]
164}
165
166if {[contains_unique_symbol tmpdir/unique_prog] != 1} {
167 fail "Executable containing unique does not contain an UNIQUE symbol"
168 set fails [expr $fails + 1]
169}
170
171if { $fails == 0 } {
172 pass "Checking unique executable"
173}
174
175# Check the empty object file.
d9816402
AM
176case $target_triplet in {
177 { hppa*-*-linux* } { set expected_none {UNIX - GNU} }
178 default { set expected_none {UNIX - System V} }
179}
180if {! [check_osabi tmpdir/unique_empty.o $expected_none]} {
181 fail "Object NOT containing unique does not have an OS/ABI field of $expected_none"
f64b2e8d
NC
182 set fails [expr $fails + 1]
183}
184
185if {[contains_unique_symbol tmpdir/unique_empty.o] == 1} {
186 fail "Object NOT containing unique does contain an UNIQUE symbol"
187 set fails [expr $fails + 1]
188}
189
190if { $fails == 0 } {
191 pass "Checking empty unique object"
192}
193
194# Check the unique PIC file.
9c55345c
TS
195if {! [check_osabi tmpdir/unique_shared.o {UNIX - GNU}]} {
196 fail "PIC Object containing unique does not have an OS/ABI field of GNU"
f64b2e8d
NC
197 set fails [expr $fails + 1]
198}
199
200if {[contains_unique_symbol tmpdir/unique_shared.o] != 1} {
201 fail "PIC Object containing unique does not contain an UNIQUE symbol"
202 set fails [expr $fails + 1]
203}
204
205if { $fails == 0 } {
206 pass "Checking unique PIC object"
207}
208
209# Check the unique shared library.
9c55345c
TS
210if {! [check_osabi tmpdir/libunique_shared.so {UNIX - GNU}]} {
211 fail "Shared library containing unique does not have an OS/ABI field of GNU"
f64b2e8d
NC
212 set fails [expr $fails + 1]
213}
214
215if {[contains_unique_symbol tmpdir/libunique_shared.so] != 1} {
216 fail "Shared library containing unique does not contain an UNIQUE symbol"
217 set fails [expr $fails + 1]
218}
219
35399224
L
220# Check the unique shared library with reference.
221if {! [check_osabi tmpdir/libunique_shared_ref.so {UNIX - GNU}]} {
222 fail "Shared library containing unique with reference does not have an OS/ABI field of GNU"
223 set fails [expr $fails + 1]
224}
225
226if {[contains_unique_symbol tmpdir/libunique_shared_ref.so] != 1} {
227 fail "Shared library containing unique with reference does not contain an UNIQUE symbol"
228 set fails [expr $fails + 1]
229}
230
f64b2e8d
NC
231if { $fails == 0 } {
232 pass "Checking unique PIC object"
233}
234
235# Check the empty executable linked against unique shared library.
d9816402
AM
236if {! [check_osabi tmpdir/unique_shared_prog $expected_none]} {
237 fail "Executable NOT containing unique does not have an OS/ABI field of $expected_none"
f64b2e8d
NC
238 set fails [expr $fails + 1]
239}
240
241if {[contains_unique_symbol tmpdir/unique_shared_prog] == 1} {
242 fail "Executable NOT containing unique does contain an UNIQUE symbol"
243 set fails [expr $fails + 1]
244}
245
246if { $fails == 0 } {
247 pass "Checking shared empty executable"
248}
This page took 0.308058 seconds and 4 git commands to generate.