]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - ld/testsuite/ld-x86-64/x86-64.exp
Set CPU type in BFD backend for x86_64-nacl* and i?86-nacl* targets
[thirdparty/binutils-gdb.git] / ld / testsuite / ld-x86-64 / x86-64.exp
1 # Expect script for ld-x86_64 tests
2 # Copyright (C) 2002, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013
3 # Free Software Foundation
4 #
5 # This file is part of the GNU Binutils.
6 #
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20 # MA 02110-1301, USA.
21 #
22
23 # Test x86_64 linking; all types of relocs. This tests the assembler and
24 # tools like objdump as well as the linker.
25
26 if { !([istarget "x86_64-*-elf*"]
27 || [istarget "x86_64-*-nacl*"]
28 || [istarget "x86_64-*-linux*"]) } {
29 return
30 }
31
32 if [istarget "*-*-nacl*"] {
33 set emul "elf_x86_64_nacl"
34 } else {
35 set emul "elf_x86_64"
36 }
37
38 # List contains test-items with 3 items followed by 2 lists:
39 # 0:name 1:ld early options 2:ld late options 3:assembler options
40 # 4:filenames of assembler files 5: action and options. 6: name of output file
41
42 # Actions:
43 # objdump: Apply objdump options on result. Compare with regex (last arg).
44 # nm: Apply nm options on result. Compare with regex (last arg).
45 # readelf: Apply readelf options on result. Compare with regex (last arg).
46
47 set x86_64tests {
48 {"Helper shared library (basic PLT test)"
49 "-shared -melf_x86_64" "" "--64" {pltlib.s} {} "libpltlib.so"}
50 {"basic PLT generation"
51 "-melf_x86_64 tmpdir/libpltlib.so" "" "--64" {plt.s}
52 {{objdump -drj.plt plt.pd}} "plt"}
53 {"TLS -fpic -shared transitions"
54 "-shared -melf_x86_64 --no-ld-generated-unwind-info" ""
55 "--64" {tlspic1.s tlspic2.s}
56 {{readelf -WSsrl tlspic.rd} {objdump -drj.text tlspic.dd}
57 {objdump -sj.got tlspic.sd} {objdump -sj.tdata tlspic.td}}
58 "libtlspic.so"}
59 {"TLS descriptor -fpic -shared transitions"
60 "-shared -melf_x86_64 --no-ld-generated-unwind-info" ""
61 "--64" {tlsdesc.s tlspic2.s}
62 {{readelf -WSsrld tlsdesc.rd} {objdump -drj.text tlsdesc.dd}
63 {objdump "-s -j.got -j.got.plt" tlsdesc.sd} {objdump -sj.tdata tlsdesc.td}
64 {objdump -drj.plt tlsdesc.pd}} "libtlsdesc.so"}
65 {"Helper shared library" "-shared -melf_x86_64" ""
66 "--64" {tlslib.s} {} "libtlslib.so"}
67 {"TLS -fpic and -fno-pic exec transitions"
68 "-melf_x86_64 tmpdir/libtlslib.so --no-ld-generated-unwind-info" ""
69 "--64" {tlsbinpic.s tlsbin.s}
70 {{readelf -WSsrl tlsbin.rd} {objdump -drj.text tlsbin.dd}
71 {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}}
72 "tlsbin"}
73 {"TLS descriptor -fpic and -fno-pic exec transitions"
74 "-melf_x86_64 tmpdir/libtlslib.so --no-ld-generated-unwind-info" ""
75 "--64" {tlsbindesc.s tlsbin.s}
76 {{readelf -WSsrl tlsbindesc.rd} {objdump -drj.text tlsbindesc.dd}
77 {objdump -sj.got tlsbindesc.sd} {objdump -sj.tdata tlsbindesc.td}}
78 "tlsbindesc"}
79 {"TLS with global dynamic and descriptors"
80 "-shared -melf_x86_64 --no-ld-generated-unwind-info" ""
81 "--64" {tlsgdesc.s}
82 {{readelf -WSsrl tlsgdesc.rd} {objdump -drj.text tlsgdesc.dd}}
83 "libtlsgdesc.so"}
84 {"TLS in debug sections" "-melf_x86_64" ""
85 "--64" {tlsg.s}
86 {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
87 {"TLS GD->LE transition" "-melf_x86_64" ""
88 "--64" {tlsgd1.s}
89 {{objdump -dwr tlsgd1.dd}} "tlsgd1"}
90 {"TLS LD->LE transition" "-melf_x86_64" ""
91 "--64" {tlsld1.s}
92 {{objdump -dwr tlsld1.dd}} "tlsld1"}
93 {"TLS IE->LE transition" "-melf_x86_64" ""
94 "--64" {tlsie1.s}
95 {{objdump -dwr tlsie1.dd}} "tlsie1"}
96 {"Helper 64bit object 1" "-r -melf_x86_64" ""
97 "--64" {mixed1a.s} {} "libmixe1a.o"}
98 {"Helper 32bit object 1" "-r -melf_i386" ""
99 "--32" {mixed1b.s} {} "libmixe1b.o"}
100 {"Helper 64bit object 2" "-r -melf_x86_64" ""
101 "--64" {mixed2a.s} {} "libmixe2a.o"}
102 {"Helper 32bit object 2" "-r -melf_i386" ""
103 "--32" {mixed2b.s} {} "libmixe2b.o"}
104 {"Split by file with 'l' flag on section."
105 "-split-by-file -r -melf_x86_64" ""
106 "--64" {split-by-file1.s split-by-file2.s}
107 {{readelf -SW split-by-file.rd}} "split-by-file.o"}
108 {"TLS X32 IE->LE transition" "-melf32_x86_64" ""
109 "--x32" {tlsie4.s}
110 {{objdump -dwr tlsie4.dd}} "tlsie4"}
111 {"TLS X32 GD->LE transition" "-melf32_x86_64" ""
112 "--x32" {tlsgd4.s}
113 {{objdump -dwr tlsgd4.dd}} "tlsgd4"}
114 {"Helper TLS GD->IE transition DSO" "-shared -melf_x86_64" ""
115 "--64" {tlsgd5b.s} {} "libtlsgd5.so"}
116 {"TLS GD->IE transition" "-melf_x86_64 tmpdir/libtlsgd5.so" ""
117 "--64" {tlsgd5a.s}
118 {{objdump -dwr tlsgd5.dd}} "tlsgd5"}
119 {"Helper TLS X32 GD->IE transition DSO" "-shared -melf32_x86_64" ""
120 "--x32" {tlsgd6b.s} {} "libtlsgd6.so"}
121 {"TLS X32 GD->IE transition" "-melf32_x86_64 tmpdir/libtlsgd6.so" ""
122 "--x32" {tlsgd6a.s}
123 {{objdump -dwr tlsgd6.dd}} "tlsgd6"}
124 {"TLS X32 LD->LE transition" "-melf32_x86_64" ""
125 "--x32" {tlsld2.s}
126 {{objdump -dwr tlsld2.dd}} "tlsld2"}
127 {"TLS -mcmodel=large GD->LE transition" "-melf_x86_64" ""
128 "--64" {tlsgd7.s}
129 {{objdump -dwr tlsgd7.dd}} "tlsgd7"}
130 {"TLS -mcmodel=large LD->LE transition" "-melf_x86_64" ""
131 "--64" {tlsld3.s}
132 {{objdump -dwr tlsld3.dd}} "tlsld3"}
133 {"TLS -mcmodel=large GD->IE transition" "-melf_x86_64 tmpdir/libtlsgd5.so" ""
134 "--64" {tlsgd8.s}
135 {{objdump -dwrj.text tlsgd8.dd}} "tlsgd8"}
136
137 {"build 32-bit object with 33 locals" "-melf_x86_64 -e 0" "" "--32" {32bit.s} {{ ld incompatible.l }} "dummy" }
138 {"build 64-bit object" "-melf_x86_64 -e 0 --defsym foo=1" "" "--64" {64bit.s} {} "dummy" }
139 {"link mixed objects" "-melf_x86_64 -e 0 tmpdir/32bit.o tmpdir/64bit.o" "" "" {} { { ld incompatible.l } } "mixed"}
140 }
141
142 # So as to avoid rewriting every last test case here in a nacl variant,
143 # we use black magic to massage the generic cases into nacl-variant cases.
144 if [istarget "*-*-nacl*"] {
145 set emul elf_x86_64_nacl
146
147 set lhs {elf(32)?_(i386|x86_64)[[:>:]]}
148 set rhs {&_nacl}
149
150 # Change all the -melf_x86_64 to -melf_x86_64_nacl so linking can succeed.
151 regsub -all -- $lhs $x86_64tests $rhs x86_64tests
152
153 # Same, applied to all the run_dump_test cases.
154 set options_regsub(ld) [list $lhs $rhs]
155
156 # The section/segment layout differs too much for the vanilla
157 # readelf output files to match. So massage the cases so that
158 # they refer to a foo-nacl.rd file instead of a foo.rd file.
159 regsub -all -- {([a-z0-9]+)\.rd} $x86_64tests {\1-nacl.rd} x86_64tests
160
161 # Likewise for PLTs.
162 regsub -all -- {([a-z0-9]+)\.pd} $x86_64tests {\1-nacl.pd} x86_64tests
163 } else {
164 set emul elf_x86_64
165 }
166
167 run_ld_link_tests $x86_64tests
168
169 global link_output
170 global ld
171
172 set test_name "Mixed x86_64 and i386 input test 1"
173 set test mixed1
174 if { ![ld_simple_link $ld tmpdir/$test "-m$emul tmpdir/${test}a.o tmpdir/${test}b.o"] } {
175 if [string match "*i386* architecture of input file `tmpdir/${test}b.o' is incompatible with i386:x86-64* output*" $link_output] {
176 pass "$test_name"
177 } {
178 fail "$test_name"
179 }
180 }
181
182 set test_name "Mixed x86_64 and i386 input test 2"
183 set test mixed2
184 if { ![ld_simple_link $ld tmpdir/$test "-m$emul tmpdir/${test}a.o tmpdir/${test}b.o"] } {
185 if [string match "*i386* architecture of input file `tmpdir/${test}b.o' is incompatible with i386:x86-64* output*" $link_output] {
186 pass "$test_name"
187 } {
188 fail "$test_name"
189 }
190 }
191
192 run_dump_test "abs"
193 run_dump_test "abs-l1om"
194 run_dump_test "pcrel8"
195 run_dump_test "pcrel16"
196 run_dump_test "tlsgd2"
197 run_dump_test "tlsgd3"
198 run_dump_test "tlsie2"
199 run_dump_test "tlsie3"
200 run_dump_test "hidden1"
201 run_dump_test "hidden2"
202 run_dump_test "hidden3"
203 run_dump_test "protected1"
204 run_dump_test "protected2"
205 run_dump_test "protected2-l1om"
206 run_dump_test "protected3"
207 run_dump_test "protected3-l1om"
208 run_dump_test "protected4"
209 run_dump_test "protected5"
210 run_dump_test "tlsle1"
211 run_dump_test "tlspie1"
212 run_dump_test "unique1"
213 run_dump_test "nogot1"
214 run_dump_test "nogot2"
215 run_dump_test "discarded1"
216 run_dump_test "pr12718"
217 run_dump_test "pr12921"
218 run_dump_test "pr13947"
219 run_dump_test "pr12570a"
220 run_dump_test "pr12570b"
221 run_dump_test "pr14215"
222 run_dump_test "pr14207"
223
224 if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
225 return
226 }
227
228 if ![ld_assemble $as "--x32 $srcdir/$subdir/start.s" tmpdir/startx32.o] {
229 unresolved "Build ILP32 start.o"
230 return
231 }
232
233 if ![ld_assemble $as "--32 $srcdir/$subdir/start.s" tmpdir/start32.o] {
234 unresolved "Build ia32 start.o"
235 return
236 }
237
238 if ![ld_assemble $as "--64 $srcdir/$subdir/start.s" tmpdir/start64.o] {
239 unresolved "Build LP64 start.o"
240 return
241 }
242
243 if ![ld_assemble $as "--x32 $srcdir/$subdir/foo.s" tmpdir/foox32.o] {
244 unresolved "Build ILP32 foo.o"
245 return
246 }
247
248 if ![ld_assemble $as "--32 $srcdir/$subdir/foo.s" tmpdir/foo32.o] {
249 unresolved "Build ia32 foo.o"
250 return
251 }
252
253 if ![ld_assemble $as "--64 $srcdir/$subdir/foo.s" tmpdir/foo64.o] {
254 unresolved "Build LP64 foo.o"
255 return
256 }
257
258 run_dump_test "compressed1"
259 run_dump_test "ilp32-1"
260 run_dump_test "ilp32-2"
261 run_dump_test "ilp32-3"
262 run_dump_test "ilp32-4"
263 run_dump_test "ilp32-4-nacl"
264 run_dump_test "ilp32-5"
265 run_dump_test "ilp32-6"
266 run_dump_test "ilp32-7"
267 run_dump_test "ilp32-8"
268 run_dump_test "ilp32-9"
269 run_dump_test "ilp32-10"
270 run_dump_test "ilp32-11"
271 run_dump_test "ia32-1"
272 run_dump_test "ia32-2"
273 run_dump_test "ia32-3"
274 run_dump_test "lp64-1"
275 run_dump_test "lp64-2"
276 run_dump_test "lp64-3"
277 run_dump_test "pr13082-1a"
278 run_dump_test "pr13082-1b"
279 run_dump_test "pr13082-2a"
280 run_dump_test "pr13082-2b"
281 run_dump_test "pr13082-3a"
282 run_dump_test "pr13082-3b"
283 run_dump_test "pr13082-4a"
284 run_dump_test "pr13082-4b"
285 run_dump_test "pr13082-5a"
286 run_dump_test "pr13082-5b"
287 run_dump_test "pr13082-6a"
288 run_dump_test "pr13082-6b"
289 run_dump_test "lea1a"
290 run_dump_test "lea1b"
291 run_dump_test "lea1c"
292 run_dump_test "lea1d"
293 run_dump_test "lea1e"
294 run_dump_test "lea1f"
295 run_dump_test "lea1g"
296 run_dump_test "lea1h"
297 run_dump_test "lea1i"
298 run_dump_test "lea1j"
299 run_dump_test "lea1k"
300 run_dump_test "lea1l"
301 run_dump_test "mov1a"
302 run_dump_test "mov1b"
303 run_dump_test "mov1c"
304 run_dump_test "mov1d"
305
306 # Must be native with the C compiler
307 if { [isnative] && [which $CC] != 0 } {
308 run_cc_link_tests {
309 {"Helper X32 DSO from x86-64 object" "" "-m64 -fPIC -g"
310 {simple.c} {} "libsimple.a"}
311 }
312
313 set convertx32 "$objcopy -O elf32-x86-64 tmpdir/simple.o tmpdir/simple-x32.o"
314 send_log "$convertx32\n"
315 set got [remote_exec host "$convertx32"]
316 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
317 send_log "$got\n"
318 fail "Convert x86-64 object to x32"
319 return
320 }
321
322 run_ld_link_tests {
323 {"X32 DSO from x86-64 object"
324 "-shared -melf32_x86_64 tmpdir/simple-x32.o" "" "--x32"
325 {dummy.s} {{readelf {-s --wide} x86-64-x32.rd}} "x86-64-x32"}
326 }
327 }