fix Windows build
[binutils-gdb.git] / ld / testsuite / ld-tic6x / tic6x.exp
blobde9dd98dec475d3e689b65bb69386a94236b64c3
1 # Expect script for ld-tic6x tests
3 # Copyright (C) 2012-2024 Free Software Foundation, Inc.
5 # This file is part of the GNU Binutils.
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.
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.
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.
22 if { ! [istarget tic6x-*-*] } {
23 return
26 foreach test [lsort [glob -nocomplain $srcdir/$subdir/*.d]] {
27 if { [runtest_file_p $runtests $test] } {
28 run_dump_test [file rootname $test]
32 set shlibtests {
33 {"C6X shared library without --dsbt-index"
34 "-shared -Tdsbt.ld --dsbt-size=3 --hash-style=sysv" ""
35 "-mdsbt -mpic -mpid=near" {shlib-1.s shlib-2.s}
36 {{readelf -WSsrld shlib-noindex.rd}
37 {objdump "-drj.plt -j.text" shlib-noindex.dd}
38 {objdump -sj.got shlib-noindex.sd}}
39 "libtestn.so"}
40 {"C6X shared library, LE, RELA"
41 "-shared -Tdsbt.ld --dsbt-index=2 --dsbt-size=3 --hash-style=sysv" ""
42 "-mdsbt -mpic -mpid=near" {shlib-1.s shlib-2.s}
43 {{readelf -WSsrld shlib-1.rd}
44 {objdump "-drj.plt -j.text" shlib-1.dd}
45 {objdump -sj.got shlib-1.sd}}
46 "libtest.so"}
47 {"C6X nonstatic app using shared library, LE, RELA"
48 "-Tdsbt.ld --dsbt-index 0 --dsbt-size=3 tmpdir/libtest.so --hash-style=sysv" ""
49 "-mdsbt -mpic -mpid=near" {shlib-app-1.s}
50 {{readelf -WSsrld shlib-app-1.rd}
51 {objdump "-drj.plt -j.text" shlib-app-1.dd}
52 {objdump -sj.got shlib-app-1.sd}
53 {objdump -R shlib-app-1.od}}
54 "shlib-dynapp-1"}
55 {"C6X shared library, LE, REL"
56 "-shared -Tdsbt.ld --dsbt-index=2 --dsbt-size=3 --hash-style=sysv" ""
57 "-mdsbt -mpic -mpid=near -mgenerate-rel" {shlib-1.s shlib-2.s}
58 {{readelf -WSsrld shlib-1r.rd}
59 {objdump "-drj.plt -j.text" shlib-1r.dd}
60 {objdump -sj.got shlib-1r.sd}}
61 "libtestr.so"}
62 {"C6X nonstatic app using shared library, LE, REL"
63 "-Tdsbt.ld --dsbt-index 0 --dsbt-size=3 --hash-style=sysv tmpdir/libtestr.so" ""
64 "-mdsbt -mpic -mpid=near -mgenerate-rel" {shlib-app-1r.s}
65 {{readelf -WSsrld shlib-app-1r.rd}
66 {objdump "-drj.plt -j.text" shlib-app-1r.dd}
67 {objdump -sj.got shlib-app-1r.sd}
68 {objdump -R shlib-app-1r.od}}
69 "shlib-dynapp-1r"}
70 {"C6X shared library, BE, RELA"
71 "-shared -Tdsbt-be.ld --dsbt-index=2 --dsbt-size=3 --hash-style=sysv" ""
72 "-mdsbt -mpic -mpid=near -mbig-endian" {shlib-1.s shlib-2.s}
73 {{readelf -WSsrld shlib-1b.rd}
74 {objdump "-drj.plt -j.text" shlib-1b.dd}
75 {objdump -sj.got shlib-1b.sd}}
76 "libtestb.so"}
77 {"C6X nonstatic app using shared library, BE, RELA"
78 "-Tdsbt-be.ld --dsbt-index 0 --dsbt-size=3 --hash-style=sysv tmpdir/libtestb.so" ""
79 "-mdsbt -mpic -mpid=near -mbig-endian" {shlib-app-1.s}
80 {{readelf -WSsrld shlib-app-1b.rd}
81 {objdump "-drj.plt -j.text" shlib-app-1b.dd}
82 {objdump -sj.got shlib-app-1b.sd}
83 {objdump -R shlib-app-1b.od}}
84 "shlib-dynapp-1b"}
85 {"C6X shared library, BE, REL"
86 "-shared -Tdsbt-be.ld --dsbt-index=2 --dsbt-size=3 --hash-style=sysv" ""
87 "-mdsbt -mpic -mpid=near -mgenerate-rel -mbig-endian" {shlib-1.s shlib-2.s}
88 {{readelf -WSsrld shlib-1rb.rd}
89 {objdump "-drj.plt -j.text" shlib-1rb.dd}
90 {objdump -sj.got shlib-1rb.sd}}
91 "libtestrb.so"}
92 {"C6X nonstatic app using shared library, BE, REL"
93 "-Tdsbt-be.ld --dsbt-index 0 --dsbt-size=3 --hash-style=sysv tmpdir/libtestrb.so" ""
94 "-mdsbt -mpic -mpid=near -mgenerate-rel -mbig-endian" {shlib-app-1r.s}
95 {{readelf -WSsrld shlib-app-1rb.rd}
96 {objdump "-drj.plt -j.text" shlib-app-1rb.dd}
97 {objdump -sj.got shlib-app-1rb.sd}
98 {objdump -R shlib-app-1rb.od}}
99 "shlib-dynapp-1rb"}
101 {"C6X static app, LE, RELA"
102 "-Tdsbt.ld --dsbt-index 0 --dsbt-size=3 --hash-style=sysv" ""
103 "-mdsbt -mpic -mpid=near" {shlib-1.s shlib-2.s shlib-app-1.s}
104 {{readelf -WSsrld static-app-1.rd}
105 {objdump "-drj.plt -j.text" static-app-1.dd}
106 {objdump -sj.got static-app-1.sd}
107 {objdump -R static-app-1.od}}
108 "static-app-1"}
109 {"C6X static app, LE, REL"
110 "-Tdsbt.ld --dsbt-index 0 --dsbt-size=3 --hash-style=sysv" ""
111 "-mdsbt -mpic -mpid=near -mgenerate-rel" {shlib-1.s shlib-2.s shlib-app-1r.s}
112 {{readelf -WSsrld static-app-1r.rd}
113 {objdump "-drj.plt -j.text" static-app-1r.dd}
114 {objdump -sj.got static-app-1r.sd}
115 {objdump -R static-app-1r.od}}
116 "static-app-1r"}
117 {"C6X static app, BE, RELA"
118 "-Tdsbt-be.ld --dsbt-index 0 --dsbt-size=3 --hash-style=sysv" ""
119 "-mdsbt -mpic -mpid=near -mbig-endian" {shlib-1.s shlib-2.s shlib-app-1.s}
120 {{readelf -WSsrld static-app-1b.rd}
121 {objdump "-drj.plt -j.text" static-app-1b.dd}
122 {objdump -sj.got static-app-1b.sd}
123 {objdump -R static-app-1b.od}}
124 "static-app-1b"}
125 {"C6X static app, BE, REL"
126 "-Tdsbt-be.ld --dsbt-index 0 --dsbt-size=3 --hash-style=sysv" ""
127 "-mdsbt -mpic -mpid=near -mbig-endian -mgenerate-rel" {shlib-1.s shlib-2.s shlib-app-1r.s}
128 {{readelf -WSsrld static-app-1rb.rd}
129 {objdump "-drj.plt -j.text" static-app-1rb.dd}
130 {objdump -sj.got static-app-1rb.sd}
131 {objdump -R static-app-1rb.od}}
132 "static-app-1rb"}
134 {"C6X shared library with --export-dynamic"
135 "-shared --export-dynamic -Tdsbt.ld --dsbt-size=3 --hash-style=sysv" ""
136 "-mdsbt -mpic -mpid=near" {shlib-1.s shlib-2.s}
137 {} "pr27271.so"}
140 run_ld_link_tests $shlibtests
142 if { [istarget tic6x-*-elf] } {
143 set expected_osabi "Bare-metal C6000"
144 } elseif { [istarget tic6x-*-uclinux] } {
145 set expected_osabi "Linux C6000"
146 } else {
147 return
150 if { ![ld_assemble_flags $as "-mpic -mpid=near" $srcdir/$subdir/shlib-1.s tmpdir/shlib-1.o]
151 || ![ld_assemble_flags $as "-mpic -mpid=near" $srcdir/$subdir/shlib-2.s tmpdir/shlib-2.o]
152 || ![ld_assemble $as $srcdir/$subdir/shlib-app-1.s tmpdir/shlib-app-1.o]
153 || ![ld_assemble_flags $as "-mpic -mpid=near -mbig-endian" $srcdir/$subdir/shlib-1.s tmpdir/shlib-1b.o]
154 || ![ld_assemble_flags $as "-mpic -mpid=near -mbig-endian" $srcdir/$subdir/shlib-2.s tmpdir/shlib-2b.o]
155 || ![ld_assemble_flags $as -mbig-endian $srcdir/$subdir/shlib-app-1.s tmpdir/shlib-app-1b.o]
156 || ![ld_link $ld tmpdir/libtest.so "-shared tmpdir/shlib-1.o tmpdir/shlib-2.o"]
157 || ![ld_link $ld tmpdir/libtestb.so "-shared -EB tmpdir/shlib-1b.o tmpdir/shlib-2b.o"]
158 || ![ld_link $ld tmpdir/shlib.o "-r tmpdir/shlib-1.o tmpdir/shlib-2.o"]
159 || ![ld_link $ld tmpdir/shlibb.o "-r -EB tmpdir/shlib-1b.o tmpdir/shlib-2b.o"]
160 || ![ld_link $ld tmpdir/dynapp-1 "tmpdir/libtest.so tmpdir/shlib-app-1.o"]
161 || ![ld_link $ld tmpdir/dynapp-1b "-EB tmpdir/libtestb.so tmpdir/shlib-app-1b.o"] } {
162 fail "TIC6X OSABI tests"
163 return
166 # A procedure to check the OS/ABI field in the ELF header of a binary file.
167 proc check_osabi_tic6x { test_name binary_file } {
168 global READELF
169 global READELFFLAGS
170 global expected_osabi
172 set cmd "$READELF $READELFFLAGS --file-header $binary_file"
173 send_log "$cmd\n"
174 set got [remote_exec host [concat sh -c [list "$cmd >dump.out"]] "" "/dev/null"]
176 if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
177 send_log "$got\n"
178 fail "$test_name"
179 remote_file build delete "dump.out"
180 return
182 remote_upload host "dump.out"
184 if { ![regexp "\n\[ \]*OS/ABI:\[ \]*(.+)\n\[ \]*ABI" \
185 [file_contents dump.out] nil osabi] } {
186 verbose "proc check_osabi_tic6x: Readelf failed to extract an ELF header from $binary_file"
187 fail "$test_name"
188 } elseif { $osabi == $expected_osabi } {
189 pass "$test_name"
190 } else {
191 verbose "Expected OSABI: $expected_osabi, Obtained osabi: $osabi"
192 fail "$test_name"
194 remote_file build delete "dump.out"
195 remote_file host delete "dump.out"
198 check_osabi_tic6x "C6X shared library OSABI, LE" tmpdir/libtest.so
199 check_osabi_tic6x "C6X shared library OSABI, BE" tmpdir/libtestb.so
200 check_osabi_tic6x "C6X dynamic app OSABI, LE" tmpdir/dynapp-1
201 check_osabi_tic6x "C6X dynamic app OSABI, BE" tmpdir/dynapp-1b
203 check_osabi_tic6x "C6X relocatable link OSABI, LE" tmpdir/shlib.o
204 check_osabi_tic6x "C6X relocatable link OSABI, BE" tmpdir/shlibb.o