Provide __executable_start for PIE
[deliverable/binutils-gdb.git] / ld / testsuite / ld-x86-64 / x86-64.exp
CommitLineData
bffbf940 1# Expect script for ld-x86_64 tests
5a68afcf 2# Copyright (C) 2002, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012
889a4d3e 3# Free Software Foundation
bffbf940 4#
f96b4a7b
NC
5# This file is part of the GNU Binutils.
6#
7# This program is free software; you can redistribute it and/or modify
bffbf940 8# it under the terms of the GNU General Public License as published by
f96b4a7b 9# the Free Software Foundation; either version 3 of the License, or
bffbf940
JJ
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
f96b4a7b
NC
19# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
20# MA 02110-1301, USA.
bffbf940
JJ
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
26if { !([istarget "x86_64-*-elf*"]
5a68afcf 27 || [istarget "x86_64-*-nacl*"]
bffbf940
JJ
28 || [istarget "x86_64-*-linux*"]) } {
29 return
30}
31
5a68afcf
RM
32if [istarget "*-*-nacl*"] {
33 set emul "elf_x86_64_nacl"
34} else {
35 set emul "elf_x86_64"
36}
37
bffbf940
JJ
38# List contains test-items with 3 items followed by 2 lists:
39# 0:name 1:ld options 2:assembler options
40# 3:filenames of assembler files 4: action and options. 5: 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
47set x86_64tests {
5a68afcf
RM
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"}
e41b3a13
JJ
53 {"TLS -fpic -shared transitions"
54 "-shared -melf_x86_64 --no-ld-generated-unwind-info"
bffbf940
JJ
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"}
e41b3a13
JJ
59 {"TLS descriptor -fpic -shared transitions"
60 "-shared -melf_x86_64 --no-ld-generated-unwind-info"
67a4f2b7
AO
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"}
bffbf940
JJ
65 {"Helper shared library" "-shared -melf_x86_64"
66 "--64" {tlslib.s} {} "libtlslib.so"}
67 {"TLS -fpic and -fno-pic exec transitions"
e41b3a13
JJ
68 "-melf_x86_64 tmpdir/libtlslib.so --no-ld-generated-unwind-info"
69 "--64" {tlsbinpic.s tlsbin.s}
bffbf940
JJ
70 {{readelf -WSsrl tlsbin.rd} {objdump -drj.text tlsbin.dd}
71 {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}}
72 "tlsbin"}
67a4f2b7 73 {"TLS descriptor -fpic and -fno-pic exec transitions"
e41b3a13
JJ
74 "-melf_x86_64 tmpdir/libtlslib.so --no-ld-generated-unwind-info"
75 "--64" {tlsbindesc.s tlsbin.s}
67a4f2b7
AO
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"
e41b3a13
JJ
80 "-shared -melf_x86_64 --no-ld-generated-unwind-info"
81 "--64" {tlsgdesc.s}
67a4f2b7
AO
82 {{readelf -WSsrl tlsgdesc.rd} {objdump -drj.text tlsgdesc.dd}}
83 "libtlsgdesc.so"}
a45bb67d
JJ
84 {"TLS in debug sections" "-melf_x86_64"
85 "--64" {tlsg.s}
86 {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
a3fadc9a
L
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"}
dd1093aa
L
93 {"TLS IE->LE transition" "-melf_x86_64"
94 "--64" {tlsie1.s}
95 {{objdump -dwr tlsie1.dd}} "tlsie1"}
39334f3a
L
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"}
8b778942 104 {"Split by file with 'l' flag on section." "-split-by-file -r -melf_x86_64"
3dbcc61d
NC
105 "--64" {split-by-file1.s split-by-file2.s}
106 {{readelf -SW split-by-file.rd}} "split-by-file.o"}
4a4c5f25
L
107 {"TLS X32 IE->LE transition" "-melf32_x86_64"
108 "--x32" {tlsie4.s}
109 {{objdump -dwr tlsie4.dd}} "tlsie4"}
52bc799a
L
110 {"TLS X32 GD->LE transition" "-melf32_x86_64"
111 "--x32" {tlsgd4.s}
112 {{objdump -dwr tlsgd4.dd}} "tlsgd4"}
113 {"Helper TLS GD->IE transition DSO" "-shared -melf_x86_64"
114 "--64" {tlsgd5b.s} {} "libtlsgd5.so"}
115 {"TLS GD->IE transition" "-melf_x86_64 tmpdir/libtlsgd5.so"
116 "--64" {tlsgd5a.s}
117 {{objdump -dwr tlsgd5.dd}} "tlsgd5"}
118 {"Helper TLS X32 GD->IE transition DSO" "-shared -melf32_x86_64"
119 "--x32" {tlsgd6b.s} {} "libtlsgd6.so"}
120 {"TLS X32 GD->IE transition" "-melf32_x86_64 tmpdir/libtlsgd6.so"
121 "--x32" {tlsgd6a.s}
122 {{objdump -dwr tlsgd6.dd}} "tlsgd6"}
123 {"TLS X32 LD->LE transition" "-melf32_x86_64"
124 "--x32" {tlsld2.s}
125 {{objdump -dwr tlsld2.dd}} "tlsld2"}
5a68afcf
RM
126
127 {"build 32-bit object with 33 locals" "-melf_x86_64 -e 0" "--32" {32bit.s} {{ ld incompatible.l }} "dummy" }
128 {"build 64-bit object" "-melf_x86_64 -e 0 --defsym foo=1" "--64" {64bit.s} {} "dummy" }
129 {"link mixed objects" "-melf_x86_64 -e 0 tmpdir/32bit.o tmpdir/64bit.o" "" {} { { ld incompatible.l } } "mixed"}
130}
131
132# So as to avoid rewriting every last test case here in a nacl variant,
133# we use black magic to massage the generic cases into nacl-variant cases.
134if [istarget "*-*-nacl*"] {
135 set emul elf_x86_64_nacl
136
137 set lhs {elf(32)?_(i386|x86_64)[[:>:]]}
138 set rhs {&_nacl}
139
140 # Change all the -melf_x86_64 to -melf_x86_64_nacl so linking can succeed.
141 regsub -all -- $lhs $x86_64tests $rhs x86_64tests
142
143 # Same, applied to all the run_dump_test cases.
144 set options_regsub(ld) [list $lhs $rhs]
145
146 # The section/segment layout differs too much for the vanilla
147 # readelf output files to match. So massage the cases so that
148 # they refer to a foo-nacl.rd file instead of a foo.rd file.
149 regsub -all -- {([a-z0-9]+)\.rd} $x86_64tests {\1-nacl.rd} x86_64tests
150
151 # Likewise for PLTs.
152 regsub -all -- {([a-z0-9]+)\.pd} $x86_64tests {\1-nacl.pd} x86_64tests
153} else {
154 set emul elf_x86_64
bffbf940
JJ
155}
156
157run_ld_link_tests $x86_64tests
ac2aa337 158
39334f3a
L
159global link_output
160global ld
161
b51176f1 162set test_name "Mixed x86_64 and i386 input test 1"
39334f3a 163set test mixed1
5a68afcf 164if { ![ld_simple_link $ld tmpdir/$test "-m$emul tmpdir/${test}a.o tmpdir/${test}b.o"] } {
39334f3a 165 if [string match "*i386 architecture of input file `tmpdir/${test}b.o' is incompatible with i386:x86-64 output*" $link_output] {
5a68afcf 166 pass "$test_name"
39334f3a 167 } {
5a68afcf 168 fail "$test_name"
39334f3a
L
169 }
170}
171
b51176f1 172set test_name "Mixed x86_64 and i386 input test 2"
39334f3a 173set test mixed2
5a68afcf 174if { ![ld_simple_link $ld tmpdir/$test "-m$emul tmpdir/${test}a.o tmpdir/${test}b.o"] } {
39334f3a 175 if [string match "*i386 architecture of input file `tmpdir/${test}b.o' is incompatible with i386:x86-64 output*" $link_output] {
5a68afcf 176 pass "$test_name"
39334f3a 177 } {
5a68afcf 178 fail "$test_name"
39334f3a
L
179 }
180}
181
ac2aa337 182run_dump_test "abs"
8a9036a4 183run_dump_test "abs-l1om"
ac2aa337
JB
184run_dump_test "pcrel8"
185run_dump_test "pcrel16"
dd1093aa
L
186run_dump_test "tlsgd2"
187run_dump_test "tlsgd3"
188run_dump_test "tlsie2"
189run_dump_test "tlsie3"
41bed6dd
L
190run_dump_test "hidden1"
191run_dump_test "hidden2"
192run_dump_test "hidden3"
193run_dump_test "protected1"
194run_dump_test "protected2"
8a9036a4 195run_dump_test "protected2-l1om"
41bed6dd 196run_dump_test "protected3"
8a9036a4 197run_dump_test "protected3-l1om"
bdb892b9
L
198run_dump_test "protected4"
199run_dump_test "protected5"
9b769489 200run_dump_test "tlsle1"
1d85728f 201run_dump_test "tlspie1"
6f8bcf84 202run_dump_test "unique1"
a7b16ceb 203run_dump_test "nogot1"
0629d0af 204run_dump_test "nogot2"
56d4289c 205run_dump_test "discarded1"
2abca860 206run_dump_test "pr12718"
a81aeffc 207run_dump_test "pr12921"
aed64b35 208run_dump_test "pr13947"
2fe0fd06
L
209run_dump_test "pr12570a"
210run_dump_test "pr12570b"
17d6eea5 211run_dump_test "pr14215"
8981c88a 212run_dump_test "pr14207"
25d17eb4 213
5a68afcf 214if { ![istarget "x86_64-*-linux*"] && ![istarget "x86_64-*-nacl*"]} {
25d17eb4
L
215 return
216}
217
5a68afcf 218if ![ld_assemble $as "--x32 $srcdir/$subdir/start.s" tmpdir/startx32.o] {
889a4d3e
L
219 unresolved "Build ILP32 start.o"
220 return
221}
222
5a68afcf 223if ![ld_assemble $as "--32 $srcdir/$subdir/start.s" tmpdir/start32.o] {
889a4d3e
L
224 unresolved "Build ia32 start.o"
225 return
226}
227
5a68afcf 228if ![ld_assemble $as "--64 $srcdir/$subdir/start.s" tmpdir/start64.o] {
889a4d3e
L
229 unresolved "Build LP64 start.o"
230 return
231}
232
5a68afcf 233if ![ld_assemble $as "--x32 $srcdir/$subdir/foo.s" tmpdir/foox32.o] {
889a4d3e
L
234 unresolved "Build ILP32 foo.o"
235 return
236}
237
5a68afcf 238if ![ld_assemble $as "--32 $srcdir/$subdir/foo.s" tmpdir/foo32.o] {
889a4d3e
L
239 unresolved "Build ia32 foo.o"
240 return
241}
242
5a68afcf 243if ![ld_assemble $as "--64 $srcdir/$subdir/foo.s" tmpdir/foo64.o] {
889a4d3e
L
244 unresolved "Build LP64 foo.o"
245 return
246}
247
25d17eb4 248run_dump_test "compressed1"
889a4d3e
L
249run_dump_test "ilp32-1"
250run_dump_test "ilp32-2"
251run_dump_test "ilp32-3"
82e96e07 252run_dump_test "ilp32-4"
5a68afcf 253run_dump_test "ilp32-4-nacl"
248775ba 254run_dump_test "ilp32-5"
d7921315
L
255run_dump_test "ilp32-6"
256run_dump_test "ilp32-7"
257run_dump_test "ilp32-8"
258run_dump_test "ilp32-9"
df4f9443 259run_dump_test "ilp32-10"
8cf0d2dd 260run_dump_test "ilp32-11"
889a4d3e
L
261run_dump_test "ia32-1"
262run_dump_test "ia32-2"
263run_dump_test "ia32-3"
264run_dump_test "lp64-1"
265run_dump_test "lp64-2"
266run_dump_test "lp64-3"
64d25c44
L
267run_dump_test "pr13082-1a"
268run_dump_test "pr13082-1b"
269run_dump_test "pr13082-2a"
270run_dump_test "pr13082-2b"
271run_dump_test "pr13082-3a"
272run_dump_test "pr13082-3b"
273run_dump_test "pr13082-4a"
274run_dump_test "pr13082-4b"
275run_dump_test "pr13082-5a"
276run_dump_test "pr13082-5b"
277run_dump_test "pr13082-6a"
278run_dump_test "pr13082-6b"
adc7571d 279
56d4d7f2
L
280# Must be native with the C compiler
281if { [isnative] && [which $CC] != 0 } {
adc7571d
L
282 run_cc_link_tests {
283 {"Helper X32 DSO from x86-64 object" "" "-m64 -fPIC -g"
284 {simple.c} {} "libsimple.a"}
285 }
286
287 set convertx32 "$objcopy -O elf32-x86-64 tmpdir/simple.o tmpdir/simple-x32.o"
288 send_log "$convertx32\n"
289 set got [remote_exec host "$convertx32"]
290 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
291 send_log "$got\n"
292 fail "Convert x86-64 object to x32"
293 return
294 }
295
296 run_ld_link_tests {
297 {"X32 DSO from x86-64 object"
298 "-shared -melf32_x86_64 tmpdir/simple-x32.o" "--x32"
299 {dummy.s} {{readelf {-s --wide} x86-64-x32.rd}} "x86-64-x32"}
300 }
301}
This page took 0.452133 seconds and 4 git commands to generate.