1# Expect script for ld-powerpc tests
2#   Copyright (C) 2002-2014 Free Software Foundation, Inc.
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
22if { ![istarget "powerpc*-*-*"]	} {
23    return
24}
25
26if {[istarget "*-*-vxworks"]} {
27    set ppcvxtests {
28	{"VxWorks shared library test 1 (default script)" "-shared" ""
29	 "-mregnames" {vxworks1-lib.s}
30	 {{readelf --segments vxworks1-lib.sd}}
31	 "libvxworks1.so"}
32	{"VxWorks shared library test 1" "-shared -Tvxworks1.ld" ""
33	 "-mregnames" {vxworks1-lib.s}
34	 {{readelf --relocs vxworks1-lib.rd} {objdump -dr vxworks1-lib.dd}
35	  {readelf --symbols vxworks1-lib.nd} {readelf -d vxworks1-lib.td}}
36	 "libvxworks1.so"}
37	{"VxWorks executable test 1 (dynamic)" \
38	 "tmpdir/libvxworks1.so -Tvxworks1.ld -q --force-dynamic" ""
39	 "-mregnames" {vxworks1.s}
40	 {{readelf --relocs vxworks1.rd} {objdump -dr vxworks1.dd}}
41	 "vxworks1"}
42	{"VxWorks executable test 2 (dynamic)" \
43	 "-Tvxworks1.ld -q --force-dynamic" ""
44	 "-mregnames" {vxworks2.s}
45	 {{readelf --segments vxworks2.sd}}
46	 "vxworks2"}
47	{"VxWorks executable test 2 (static)"
48	 "-Tvxworks1.ld" ""
49	 "-mregnames" {vxworks2.s}
50	 {{readelf --segments vxworks2-static.sd}}
51	 "vxworks2"}
52	{"VxWorks relax test"
53	 "-Tvxworks1.ld --relax -q" ""
54	 "-mregnames" {vxworks-relax.s}
55	 {{readelf --relocs vxworks-relax.rd}}
56	 "vxworks-relax"}
57	{"VxWorks relocatable relax test"
58	 "-Tvxworks1.ld -r --relax -q" ""
59	 "-mregnames" {vxworks-relax-2.s}
60	 {{readelf --relocs vxworks-relax-2.rd}}
61	 "vxworks-relax-2"}
62    }
63    run_ld_link_tests $ppcvxtests
64    run_dump_test "vxworks1-static"
65    return
66}
67
68# powerpc ELF only at the moment.  Disable for nto too, even though it
69# is ELF, because we pass -melf32ppc to ld and powerpc-nto-ld wants
70# -melf32ppcnto.
71
72if { [istarget "*-*-macos*"] || [istarget "*-*-netware*"]
73     || [istarget "*-*-pe"] || [istarget "*-*-winnt*"]
74     || [istarget "*-*-cygwin*"] || [istarget "*-*-aix*"]
75     || [istarget "*-*-beos*"] || [istarget "*-*-lynxos*"]
76     || [istarget "*-*-nto*"] } {
77    return
78}
79
80proc supports_ppc64 { } {
81    global ld
82
83    catch "exec $ld --help | grep emulations" tmp
84    if [ regexp "elf64l?ppc" $tmp ] then {
85	return 1
86    } else {
87	return 0
88    }
89}
90
91# List contains test-items with 3 items followed by 2 lists:
92# 0:name 1:ld early options 2:ld late options 3:assembler options
93# 4:filenames of assembler files 5: action and options. 6: name of output file
94
95# Actions:
96# objdump: Apply objdump options on result.  Compare with regex (last arg).
97# nm: Apply nm options on result.  Compare with regex (last arg).
98# readelf: Apply readelf options on result.  Compare with regex (last arg).
99
100set ppcelftests {
101    {"Reloc section order" "-melf32ppc -shared -z nocombreloc" "" "-a32" {reloc.s}
102     {{objdump -hw reloc.d}} "reloc.so"}
103    {"APUinfo section processing" "-melf32ppc" ""
104     "-a32 -me500" {apuinfo1.s apuinfo-nul.s apuinfo2.s}
105     {{readelf -x2 apuinfo.rd}} "apuinfo"}
106    {"APUinfo VLE section processing" "-melf32ppc" ""
107     "-a32 -me500 -mvle" {apuinfo1.s apuinfo-vle.s apuinfo2.s}
108     {{readelf -x2 apuinfo-vle.rd}} "apuinfo-vle"}
109    {"APUinfo NULL section processing" "-melf32ppc" ""
110     "-a32 -me500" {apuinfo-nul1.s apuinfo-nul.s}
111     {{readelf -x2 apuinfo-nul.rd}} "apuinfo"}
112    {"TLS32 static exec" "-melf32ppc" "" "-a32"  {tls32.s tlslib32.s}
113     {{objdump -dr tls32.d} {objdump -sj.got tls32.g}
114      {objdump -sj.tdata tls32.t}}
115     "tls32"}
116    {"TLS32 helper shared library" "-shared -melf32ppc tmpdir/tlslib32.o" "" "" {}
117     {} "libtlslib32.so"}
118    {"TLS32 dynamic exec" "-melf32ppc --no-ld-generated-unwind-info tmpdir/tls32.o tmpdir/libtlslib32.so" "" "" {}
119     {{readelf -WSsrl tlsexe32.r} {objdump -dr tlsexe32.d}
120      {objdump -sj.got tlsexe32.g} {objdump -sj.tdata tlsexe32.t}}
121      "tlsexe32"}
122    {"TLS32 shared" "-shared -melf32ppc --no-ld-generated-unwind-info tmpdir/tls32.o" "" "" {}
123     {{readelf -WSsrl tlsso32.r} {objdump -dr tlsso32.d}
124      {objdump -sj.got tlsso32.g} {objdump -sj.tdata tlsso32.t}}
125      "tls32.so"}
126    {"TLS32 markers" "-melf32ppc" "" "-a32"  {tlsmark32.s tlslib32.s}
127     {{objdump -dr tlsmark32.d}}
128      "tlsmark32"}
129    {"TLS32 opt 1" "-melf32ppc" "" "-a32"  {tlsopt1_32.s tlslib32.s}
130     {{objdump -dr tlsopt1_32.d}}
131      "tlsopt1_32"}
132    {"TLS32 opt 2" "-melf32ppc" "" "-a32"  {tlsopt2_32.s tlslib32.s}
133     {{objdump -dr tlsopt2_32.d}}
134      "tlsopt2_32"}
135    {"TLS32 opt 3" "-melf32ppc" "" "-a32"  {tlsopt3_32.s tlslib32.s}
136     {{objdump -dr tlsopt3_32.d}}
137      "tlsopt3_32"}
138    {"TLS32 opt 4" "-melf32ppc" "" "-a32"  {tlsopt4_32.s tlslib32.s}
139     {{objdump -dr tlsopt4_32.d}}
140      "tlsopt4_32"}
141    {"Shared library with global symbol" "-shared -melf32ppc" "" "-a32" {sdalib.s}
142     {} "sdalib.so"}
143    {"Dynamic application with SDA" "-melf32ppc tmpdir/sdalib.so" "" "-a32" {sdadyn.s}
144     {{objdump -R sdadyn.d}} "sdadyn"}
145    {"relaxing" "-melf32ppc --relax -Ttext=0 --defsym far=0x80001234 --defsym near=0x00004320" "" "-a32" "relax.s"
146     {{objdump -dr relax.d}}
147      "relax"}
148    {"relocatable relaxing" "-melf32ppc -r --relax" "" "-a32" "relax.s"
149     {{objdump -dr relaxr.d}}
150      "relax"}
151}
152
153set ppc64elftests {
154    {"TLS static exec" "-melf64ppc" "" "-a64"  {tls.s tlslib.s}
155     {{objdump -dr tls.d} {objdump -sj.got tls.g} {objdump -sj.tdata tls.t}}
156      "tls"}
157    {"TLS helper shared library" "-shared -melf64ppc tmpdir/tlslib.o" "" "" {}
158     {} "libtlslib.so"}
159    {"TLS helper old shared lib" "-shared -melf64ppc" "" "-a64" {oldtlslib.s}
160     {} "liboldlib.so"}
161    {"TLS dynamic exec" "-melf64ppc --no-ld-generated-unwind-info tmpdir/tls.o tmpdir/libtlslib.so" "" "" {}
162     {{readelf -WSsrl tlsexe.r} {objdump -dr tlsexe.d}
163      {objdump -sj.got tlsexe.g} {objdump -sj.tdata tlsexe.t}}
164      "tlsexe"}
165    {"TLS dynamic old" "-melf64ppc --no-ld-generated-unwind-info tmpdir/tls.o tmpdir/liboldlib.so" "" "" {}
166     {{readelf -WSsrl tlsexe.r} {objdump -dr tlsexe.d}
167      {objdump -sj.got tlsexe.g} {objdump -sj.tdata tlsexe.t}}
168      "tlsexeold"}
169    {"TLS shared" "-shared -melf64ppc --no-ld-generated-unwind-info tmpdir/tls.o" "" "" {}
170     {{readelf -WSsrl tlsso.r} {objdump -dr tlsso.d}
171      {objdump -sj.got tlsso.g} {objdump -sj.tdata tlsso.t}}
172      "tls.so"}
173    {"TLSTOC static exec" "-melf64ppc tmpdir/tlslib.o " "" "-a64"  {tlstoc.s}
174     {{objdump -dr tlstoc.d} {objdump -sj.got tlstoc.g}
175      {objdump -sj.tdata tlstoc.t}}
176      "tlstoc"}
177    {"TLSTOC dynamic exec" "-melf64ppc --no-ld-generated-unwind-info tmpdir/tlstoc.o tmpdir/libtlslib.so" ""
178     "" {}
179     {{readelf -WSsrl tlsexetoc.r} {objdump -dr tlsexetoc.d}
180      {objdump -sj.got tlsexetoc.g} {objdump -sj.tdata tlsexetoc.t}}
181      "tlsexetoc"}
182    {"TLSTOC dynamic old" "-melf64ppc --no-ld-generated-unwind-info tmpdir/tlstoc.o tmpdir/liboldlib.so" ""
183     "" {}
184     {{readelf -WSsrl tlsexetoc.r} {objdump -dr tlsexetoc.d}
185      {objdump -sj.got tlsexetoc.g} {objdump -sj.tdata tlsexetoc.t}}
186      "tlsexetocold"}
187    {"TLSTOC shared" "-shared -melf64ppc --no-ld-generated-unwind-info tmpdir/tlstoc.o" "" "" {}
188     {{readelf -WSsrl tlstocso.r} {objdump -dr tlstocso.d}
189      {objdump -sj.got tlstocso.g} {objdump -sj.tdata tlstocso.t}}
190      "tlstoc.so"}
191    {"TLS markers" "-melf64ppc" "" "-a64"  {tlsmark.s tlslib.s}
192     {{objdump -dr tlsmark.d}}
193      "tlsmark"}
194    {"TLS opt 1" "-melf64ppc" "" "-a64"  {tlsopt1.s tlslib.s}
195     {{objdump -dr tlsopt1.d}}
196      "tlsopt1"}
197    {"TLS opt 2" "-melf64ppc" "" "-a64"  {tlsopt2.s tlslib.s}
198     {{objdump -dr tlsopt2.d}}
199      "tlsopt2"}
200    {"TLS opt 3" "-melf64ppc" "" "-a64"  {tlsopt3.s tlslib.s}
201     {{objdump -dr tlsopt3.d}}
202      "tlsopt3"}
203    {"TLS opt 4" "-melf64ppc" "" "-a64"  {tlsopt4.s tlslib.s}
204     {{objdump -dr tlsopt4.d}}
205      "tlsopt4"}
206    {"sym@tocbase" "-shared -melf64ppc" "" "-a64" {symtocbase-1.s symtocbase-2.s}
207	{{objdump -dj.data symtocbase.d}} "symtocbase.so"}
208    {"TOC opt" "-melf64ppc" "" "-a64"  {tocopt.s}
209	{{ld tocopt.out} {objdump -s tocopt.d}} "tocopt"}
210    {"TOC opt2" "-melf64ppc --defsym x=2" "" "-a64"  {tocopt2.s}
211	{{ld tocopt2.out} {objdump -s tocopt2.d}} "tocopt2"}
212    {"TOC opt3" "-melf64ppc -no-keep-memory --defsym x=2" "" "-a64"  {tocopt3.s}
213	{{objdump -s tocopt3.d}} "tocopt3"}
214    {"TOC opt4" "-melf64ppc -no-keep-memory --defsym x=2" "" "-a64"
215        {tocopt4a.s tocopt4b.s} {{objdump -s tocopt4.d}} "tocopt4"}
216    {"TOC opt5" "-melf64ppc" "" "-a64"  {tocopt5.s}
217	{{objdump -s tocopt5.d}} "tocopt5"}
218    {"ambig shared v1" "-shared -melf64ppc" "" "-a64" {funv1.s} {} "funv1.so"}
219    {"ambig shared v2" "-shared -melf64ppc" "" "-a64" {funv2.s} {} "funv2.so"}
220}
221
222set ppceabitests {
223    {"VLE multiple segments 1" "-T vle-multiseg-1.ld" ""
224     "-mregnames -mvle" {vle-multiseg.s}
225    {{readelf "-l" vle-multiseg-1.d}} "vle-multiseg-1"}
226    {"VLE multiple segments 2" "-T vle-multiseg-2.ld" ""
227     "-mregnames -mvle" {vle-multiseg.s}
228    {{readelf "-l" vle-multiseg-2.d}} "vle-multiseg-2"}
229    {"VLE multiple segments 3" "-T vle-multiseg-3.ld" ""
230     "-mregnames -mvle" {vle-multiseg.s}
231    {{readelf "-l" vle-multiseg-3.d}} "vle-multiseg-3"}
232    {"VLE multiple segments 4" "-T vle-multiseg-4.ld" ""
233     "-mregnames -mvle" {vle-multiseg.s}
234    {{readelf "-l" vle-multiseg-4.d}} "vle-multiseg-4"}
235    {"VLE multiple segments 5" "-T vle-multiseg-5.ld" ""
236     "-mregnames -mvle" {vle-multiseg.s}
237    {{readelf "-l" vle-multiseg-5.d}} "vle-multiseg-5"}
238    {"VLE relocations 1" "-T vle.ld" ""
239     "-mvle" {vle-reloc-1.s vle-reloc-def-1.s}
240    {{objdump "-Mvle -d" vle-reloc-1.d}} "vle-reloc-1"}
241    {"VLE relocations 2" "-T vle.ld" ""
242     "-mvle" {vle-reloc-2.s vle-reloc-def-2.s}
243    {{objdump "-Mvle -d" vle-reloc-2.d}} "vle-reloc-2"}
244    {"VLE relocations 3" "-T vle.ld" ""
245     "-mvle" {vle-reloc-3.s vle-reloc-def-3.s}
246    {{objdump "-Mvle -d" vle-reloc-3.d}} "vle-reloc-3"}
247}
248
249if [istarget "powerpc*le*-*-*"] then {
250    set options_regsub(ld) {{-melf([3264]*)ppc} {-melf\1lppc}}
251
252    for {set i 0} {$i < [llength $ppcelftests]} {incr i} {
253	set line [lindex $ppcelftests $i]
254	set ld_options [lindex $line 1]
255	regsub -all elf32ppc $ld_options elf32lppc ld_options
256	set line [lreplace $line 1 1 $ld_options]
257	set ppcelftests [lreplace $ppcelftests $i $i $line]
258    }
259
260    if [ supports_ppc64 ] then {
261	for {set i 0} {$i < [llength $ppc64elftests]} {incr i} {
262	    set line [lindex $ppc64elftests $i]
263	    set ld_options [lindex $line 1]
264	    regsub -all elf64ppc $ld_options elf64lppc ld_options
265	    set line [lreplace $line 1 1 $ld_options]
266	    set ppc64elftests [lreplace $ppc64elftests $i $i $line]
267	}
268    }
269}
270
271run_ld_link_tests $ppcelftests
272
273if [ supports_ppc64 ] then {
274    run_ld_link_tests $ppc64elftests
275    run_dump_test "relbrlt"
276    run_dump_test "elfv2so"
277    run_dump_test "elfv2exe"
278    run_dump_test "elfv2-2so"
279    run_dump_test "elfv2-2exe"
280    run_dump_test "ambiguousv1"
281    run_dump_test "ambiguousv1b"
282    run_dump_test "ambiguousv2"
283    run_dump_test "ambiguousv2b"
284    run_dump_test "defsym"
285}
286
287if { [istarget "powerpc*-eabi*"] } {
288    run_ld_link_tests $ppceabitests
289}
290
291run_dump_test "plt1"
292
293run_dump_test "attr-gnu-4-00"
294run_dump_test "attr-gnu-4-01"
295run_dump_test "attr-gnu-4-02"
296run_dump_test "attr-gnu-4-03"
297run_dump_test "attr-gnu-4-10"
298run_dump_test "attr-gnu-4-11"
299run_dump_test "attr-gnu-4-12"
300run_dump_test "attr-gnu-4-13"
301run_dump_test "attr-gnu-4-14"
302run_dump_test "attr-gnu-4-20"
303run_dump_test "attr-gnu-4-21"
304run_dump_test "attr-gnu-4-22"
305run_dump_test "attr-gnu-4-23"
306run_dump_test "attr-gnu-4-24"
307run_dump_test "attr-gnu-4-31"
308run_dump_test "attr-gnu-4-32"
309run_dump_test "attr-gnu-4-33"
310run_dump_test "attr-gnu-4-34"
311run_dump_test "attr-gnu-4-41"
312
313run_dump_test "attr-gnu-8-11"
314run_dump_test "attr-gnu-8-23"
315run_dump_test "attr-gnu-8-31"
316
317run_dump_test "attr-gnu-12-11"
318run_dump_test "attr-gnu-12-21"
319
320run_dump_test "vle-multiseg-6"
321