bfd/
[binutils-gdb.git] / ld / testsuite / ld-i386 / i386.exp
1 # Expect script for ld-i386 tests
2 # Copyright (C) 2002, 2005, 2006, 2007 Free Software Foundation
3 #
4 # This file is part of the GNU Binutils.
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
19 # MA 02110-1301, USA.
20 #
21
22 # Test i386 linking; all types of relocs. This tests the assembler and
23 # tools like objdump as well as the linker.
24
25 if {[istarget "i?86-*-vxworks"]} {
26 set i386tests {
27 {"VxWorks shared library test 1" "-shared -Tvxworks1.ld"
28 "" {vxworks1-lib.s}
29 {{readelf --relocs vxworks1-lib.rd} {objdump -dr vxworks1-lib.dd}
30 {readelf --symbols vxworks1-lib.nd} {readelf -d vxworks1-lib.td}}
31 "libvxworks1.so"}
32 {"VxWorks executable test 1 (dynamic)" \
33 "tmpdir/libvxworks1.so -Tvxworks1.ld -q --force-dynamic"
34 "" {vxworks1.s}
35 {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}}
36 "vxworks1"}
37 {"VxWorks executable test 2 (dynamic)" \
38 "-Tvxworks1.ld -q --force-dynamic"
39 "" {vxworks2.s}
40 {{readelf --segments vxworks2.sd}}
41 "vxworks2"}
42 {"VxWorks executable test 2 (static)"
43 "-Tvxworks1.ld"
44 "" {vxworks2.s}
45 {{readelf --segments vxworks2-static.sd}}
46 "vxworks2"}
47 }
48 run_ld_link_tests $i386tests
49 run_dump_test "vxworks1-static"
50 }
51
52 if [istarget "*-*-go32*"] {
53 run_ld_link_tests {{"go32 stub" "" "" {zero.s} {} "go32stub"}}
54
55 set src "tmpdir/go32stub"
56 set dest "tmpdir/go32stub-copy"
57
58 set test "go32 stub patch the source"
59 set fi [open $src r+]
60 fconfigure $fi -translation binary
61 if {[read $fi 2] != "MZ"} {
62 fail $test
63 } else {
64 pass $test
65 seek $fi 0x40
66 puts -nonewline $fi "objcopy-test-go32stub"
67 }
68 close $fi
69
70 set test "go32 stub objcopy"
71 set status [remote_exec build $OBJCOPY "$OBJCOPYFLAGS $src $dest"]
72 set exec_output [lindex $status 1]
73 set exec_output [prune_warnings $exec_output]
74 if [string match "" $exec_output] then {
75 pass $test
76 } else {
77 send_log "$exec_output\n"
78 verbose "$exec_output" 1
79 fail $test
80 }
81
82 # cmp would compare the whole files and some data after the initial exe
83 # stub could differ.
84 set test "go32 stub comparison after objcopy"
85 set fi [open $src]
86 fconfigure $fi -translation binary
87 set src_stub [read $fi 2048]
88 close $fi
89 set fi [open $dest]
90 fconfigure $fi -translation binary
91 set dest_stub [read $fi 2048]
92 close $fi
93 if {$src_stub == $dest_stub} {
94 pass $test
95 } else {
96 fail $test
97 }
98 }
99
100 if { !([istarget "i?86-*-elf*"]
101 || ([istarget "i?86-*-linux*"]
102 && ![istarget "*-*-*aout*"]
103 && ![istarget "*-*-*oldld*"])
104 || [istarget "x86_64-*-linux*"]
105 || [istarget "amd64-*-linux*"]) } {
106 return
107 }
108
109 # List contains test-items with 3 items followed by 2 lists:
110 # 0:name 1:ld options 2:assembler options
111 # 3:filenames of assembler files 4: action and options. 5: name of output file
112
113 # Actions:
114 # objdump: Apply objdump options on result. Compare with regex (last arg).
115 # nm: Apply nm options on result. Compare with regex (last arg).
116 # readelf: Apply readelf options on result. Compare with regex (last arg).
117
118 set i386tests {
119 {"TLS -fpic -shared transitions" "-shared -melf_i386"
120 "--32" {tlspic1.s tlspic2.s}
121 {{readelf -Ssrl tlspic.rd} {objdump -drj.text tlspic.dd}
122 {objdump -sj.got tlspic.sd} {objdump -sj.tdata tlspic.td}}
123 "libtlspic.so"}
124 {"TLS descriptor -fpic -shared transitions" "-shared -melf_i386"
125 "--32" {tlsdesc.s tlspic2.s}
126 {{readelf -Ssrl tlsdesc.rd} {objdump -drj.text tlsdesc.dd}
127 {objdump "-s -j.got -j.got.plt" tlsdesc.sd} {objdump -sj.tdata tlsdesc.td}}
128 "libtlsdesc.so"}
129 {"Helper shared library" "-shared -melf_i386"
130 "--32" {tlslib.s} {} "libtlslib.so"}
131 {"TLS -fpic and -fno-pic exec transitions"
132 "-melf_i386 tmpdir/libtlslib.so" "--32" {tlsbinpic.s tlsbin.s}
133 {{readelf -Ssrl tlsbin.rd} {objdump -drj.text tlsbin.dd}
134 {objdump -sj.got tlsbin.sd} {objdump -sj.tdata tlsbin.td}}
135 "tlsbin"}
136 {"TLS descriptor -fpic and -fno-pic exec transitions"
137 "-melf_i386 tmpdir/libtlslib.so" "--32" {tlsbindesc.s tlsbin.s}
138 {{readelf -Ssrl tlsbindesc.rd} {objdump -drj.text tlsbindesc.dd}
139 {objdump -sj.got tlsbindesc.sd} {objdump -sj.tdata tlsbindesc.td}}
140 "tlsbindesc"}
141 {"TLS -fno-pic -shared" "-shared -melf_i386"
142 "--32" {tlsnopic1.s tlsnopic2.s}
143 {{readelf -Ssrl tlsnopic.rd} {objdump -drj.text tlsnopic.dd}
144 {objdump -sj.got tlsnopic.sd}} "libtlsnopic.so"}
145 {"TLS with global dynamic and descriptors"
146 "-shared -melf_i386" "--32" {tlsgdesc.s}
147 {{readelf -Ssrl tlsgdesc.rd} {objdump -drj.text tlsgdesc.dd}}
148 "libtlsgdesc.so"}
149 {"TLS in debug sections" "-melf_i386"
150 "--32" {tlsg.s}
151 {{objdump -sj.debug_foobar tlsg.sd}} "tlsg"}
152 {"TLS @indntpoff with %eax" "-melf_i386" "--32" {tlsindntpoff.s}
153 {{objdump -drj.text tlsindntpoff.dd}} "tlsindntpoff"}
154 {"Reloc section order" "-shared -melf_i386 -z nocombreloc" "--32"
155 {reloc.s} {{objdump -hw reloc.d}} "reloc.so"}
156 {"Basic --emit-relocs support" "-shared -melf_i386 --emit-relocs" "--32"
157 {emit-relocs.s} {{readelf --relocs emit-relocs.d}} "emit-relocs.so"}
158 {"-z combreloc relocation sections" "-shared -melf_i386 -z combreloc"
159 "--32" {combreloc.s} {{readelf -r combreloc.d}} "combreloc.so"}
160 {"TLS GD->LE transition" "-melf_i386"
161 "--32" {tlsgd1.s}
162 {{objdump -dwr tlsgd1.dd}} "tlsgd1"}
163 {"TLS LD->LE transition" "-melf_i386"
164 "--32" {tlsld1.s}
165 {{objdump -dwr tlsld1.dd}} "tlsld1"}
166 {"TLS IE->LE transition" "-melf_i386"
167 "--32" {tlsie1.s}
168 {{objdump -dwr tlsie1.dd}} "tlsie1"}
169 }
170
171 run_ld_link_tests $i386tests
172
173 run_dump_test "abs"
174 run_dump_test "pcrel8"
175 run_dump_test "pcrel16"
176 run_dump_test "pcrel16abs"
177 run_dump_test "alloc"
178 run_dump_test "warn1"
179 run_dump_test "tlsgd2"
180 run_dump_test "tlsie2"
181 run_dump_test "tlsie3"
182 run_dump_test "tlsie4"
183 run_dump_test "tlsie5"
184 run_dump_test "hidden1"
185 run_dump_test "hidden2"
186 run_dump_test "hidden3"
187 run_dump_test "protected1"
188 run_dump_test "protected2"
189 run_dump_test "protected3"
190 run_dump_test "tlspie1"