ld/testsuite/
[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
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
128 {"build 32-bit object with 33 locals" "-melf_x86_64 -e 0" "" "--32" {32bit.s} {{ ld incompatible.l }} "dummy" }
129 {"build 64-bit object" "-melf_x86_64 -e 0 --defsym foo=1" "" "--64" {64bit.s} {} "dummy" }
130 {"link mixed objects" "-melf_x86_64 -e 0 tmpdir/32bit.o tmpdir/64bit.o" "" "" {} { { ld incompatible.l } } "mixed"}
131 }
132
133 # So as to avoid rewriting every last test case here in a nacl variant,
134 # we use black magic to massage the generic cases into nacl-variant cases.
135 if [istarget "*-*-nacl*"] {
136 set emul elf_x86_64_nacl
137
138 set lhs {elf(32)?_(i386|x86_64)[[:>:]]}
139 set rhs {&_nacl}
140
141 # Change all the -melf_x86_64 to -melf_x86_64_nacl so linking can succeed.
142 regsub -all -- $lhs $x86_64tests $rhs x86_64tests
143
144 # Same, applied to all the run_dump_test cases.
145 set options_regsub(ld) [list $lhs $rhs]
146
147 # The section/segment layout differs too much for the vanilla
148 # readelf output files to match. So massage the cases so that
149 # they refer to a foo-nacl.rd file instead of a foo.rd file.
150 regsub -all -- {([a-z0-9]+)\.rd} $x86_64tests {\1-nacl.rd} x86_64tests
151
152 # Likewise for PLTs.
153 regsub -all -- {([a-z0-9]+)\.pd} $x86_64tests {\1-nacl.pd} x86_64tests
154 } else {
155 set emul elf_x86_64
156 }
157
158 run_ld_link_tests $x86_64tests
159
160 global link_output
161 global ld
162
163 set test_name "Mixed x86_64 and i386 input test 1"
164 set test mixed1
165 if { ![ld_simple_link $ld tmpdir/$test "-m$emul tmpdir/${test}a.o tmpdir/${test}b.o"] } {
166 if [string match "*i386 architecture of input file `tmpdir/${test}b.o' is incompatible with i386:x86-64 output*" $link_output] {
167 pass "$test_name"
168 } {
169 fail "$test_name"
170 }
171 }
172
173 set test_name "Mixed x86_64 and i386 input test 2"
174 set test mixed2
175 if { ![ld_simple_link $ld tmpdir/$test "-m$emul tmpdir/${test}a.o tmpdir/${test}b.o"] } {
176 if [string match "*i386 architecture of input file `tmpdir/${test}b.o' is incompatible with i386:x86-64 output*" $link_output] {
177 pass "$test_name"
178 } {
179 fail "$test_name"
180 }
181 }
182
183 run_dump_test "abs"
184 run_dump_test "abs-l1om"
185 run_dump_test "pcrel8"
186 run_dump_test "pcrel16"
187 run_dump_test "tlsgd2"
188 run_dump_test "tlsgd3"
189 run_dump_test "tlsie2"
190 run_dump_test "tlsie3"
191 run_dump_test "hidden1"
192 run_dump_test "hidden2"
193 run_dump_test "hidden3"
194 run_dump_test "protected1"
195 run_dump_test "protected2"
196 run_dump_test "protected2-l1om"
197 run_dump_test "protected3"
198 run_dump_test "protected3-l1om"
199 run_dump_test "protected4"
200 run_dump_test "protected5"
201 run_dump_test "tlsle1"
202 run_dump_test "tlspie1"
203 run_dump_test "unique1"
204 run_dump_test "nogot1"
205 run_dump_test "nogot2"
206 run_dump_test "discarded1"
207 run_dump_test "pr12718"
208 run_dump_test "pr12921"
209 run_dump_test "pr13947"
210 run_dump_test "pr12570a"
211 run_dump_test "pr12570b"
212 run_dump_test "pr14215"
213 run_dump_test "pr14207"
214
215 if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
216 return
217 }
218
219 if ![ld_assemble $as "--x32 $srcdir/$subdir/start.s" tmpdir/startx32.o] {
220 unresolved "Build ILP32 start.o"
221 return
222 }
223
224 if ![ld_assemble $as "--32 $srcdir/$subdir/start.s" tmpdir/start32.o] {
225 unresolved "Build ia32 start.o"
226 return
227 }
228
229 if ![ld_assemble $as "--64 $srcdir/$subdir/start.s" tmpdir/start64.o] {
230 unresolved "Build LP64 start.o"
231 return
232 }
233
234 if ![ld_assemble $as "--x32 $srcdir/$subdir/foo.s" tmpdir/foox32.o] {
235 unresolved "Build ILP32 foo.o"
236 return
237 }
238
239 if ![ld_assemble $as "--32 $srcdir/$subdir/foo.s" tmpdir/foo32.o] {
240 unresolved "Build ia32 foo.o"
241 return
242 }
243
244 if ![ld_assemble $as "--64 $srcdir/$subdir/foo.s" tmpdir/foo64.o] {
245 unresolved "Build LP64 foo.o"
246 return
247 }
248
249 run_dump_test "compressed1"
250 run_dump_test "ilp32-1"
251 run_dump_test "ilp32-2"
252 run_dump_test "ilp32-3"
253 run_dump_test "ilp32-4"
254 run_dump_test "ilp32-4-nacl"
255 run_dump_test "ilp32-5"
256 run_dump_test "ilp32-6"
257 run_dump_test "ilp32-7"
258 run_dump_test "ilp32-8"
259 run_dump_test "ilp32-9"
260 run_dump_test "ilp32-10"
261 run_dump_test "ilp32-11"
262 run_dump_test "ia32-1"
263 run_dump_test "ia32-2"
264 run_dump_test "ia32-3"
265 run_dump_test "lp64-1"
266 run_dump_test "lp64-2"
267 run_dump_test "lp64-3"
268 run_dump_test "pr13082-1a"
269 run_dump_test "pr13082-1b"
270 run_dump_test "pr13082-2a"
271 run_dump_test "pr13082-2b"
272 run_dump_test "pr13082-3a"
273 run_dump_test "pr13082-3b"
274 run_dump_test "pr13082-4a"
275 run_dump_test "pr13082-4b"
276 run_dump_test "pr13082-5a"
277 run_dump_test "pr13082-5b"
278 run_dump_test "pr13082-6a"
279 run_dump_test "pr13082-6b"
280 run_dump_test "lea1a"
281 run_dump_test "lea1b"
282 run_dump_test "lea1c"
283 run_dump_test "lea1d"
284 run_dump_test "lea1e"
285 run_dump_test "lea1f"
286 run_dump_test "lea1g"
287 run_dump_test "lea1h"
288 run_dump_test "lea1i"
289 run_dump_test "lea1j"
290 run_dump_test "lea1k"
291 run_dump_test "lea1l"
292 run_dump_test "mov1a"
293 run_dump_test "mov1b"
294 run_dump_test "mov1c"
295 run_dump_test "mov1d"
296
297 # Must be native with the C compiler
298 if { [isnative] && [which $CC] != 0 } {
299 run_cc_link_tests {
300 {"Helper X32 DSO from x86-64 object" "" "-m64 -fPIC -g"
301 {simple.c} {} "libsimple.a"}
302 }
303
304 set convertx32 "$objcopy -O elf32-x86-64 tmpdir/simple.o tmpdir/simple-x32.o"
305 send_log "$convertx32\n"
306 set got [remote_exec host "$convertx32"]
307 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
308 send_log "$got\n"
309 fail "Convert x86-64 object to x32"
310 return
311 }
312
313 run_ld_link_tests {
314 {"X32 DSO from x86-64 object"
315 "-shared -melf32_x86_64 tmpdir/simple-x32.o" "" "--x32"
316 {dummy.s} {{readelf {-s --wide} x86-64-x32.rd}} "x86-64-x32"}
317 }
318 }