1# Expect script for ld-tic6x tests
2#
3#   Copyright (C) 2012-2020 Free Software Foundation, Inc.
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
22if { ! [istarget tic6x-*-*] } {
23    return
24}
25
26foreach test [lsort [glob -nocomplain $srcdir/$subdir/*.d]] {
27    if { [runtest_file_p $runtests $test] } {
28	run_dump_test [file rootname $test]
29    }
30}
31
32set 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"}
100
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"}
133}
134
135run_ld_link_tests $shlibtests
136
137if { [istarget tic6x-*-elf] } {
138    set expected_osabi "Bare-metal C6000"
139} elseif { [istarget tic6x-*-uclinux] } {
140    set expected_osabi "Linux C6000"
141} else {
142    return
143}
144
145if { ![ld_assemble_flags $as "-mpic -mpid=near" $srcdir/$subdir/shlib-1.s tmpdir/shlib-1.o]
146     || ![ld_assemble_flags $as "-mpic -mpid=near" $srcdir/$subdir/shlib-2.s tmpdir/shlib-2.o]
147     || ![ld_assemble $as $srcdir/$subdir/shlib-app-1.s tmpdir/shlib-app-1.o]
148     || ![ld_assemble_flags $as "-mpic -mpid=near -mbig-endian" $srcdir/$subdir/shlib-1.s tmpdir/shlib-1b.o]
149     || ![ld_assemble_flags $as "-mpic -mpid=near -mbig-endian" $srcdir/$subdir/shlib-2.s tmpdir/shlib-2b.o]
150     || ![ld_assemble_flags $as -mbig-endian $srcdir/$subdir/shlib-app-1.s tmpdir/shlib-app-1b.o]
151     || ![ld_link $ld tmpdir/libtest.so "-shared tmpdir/shlib-1.o tmpdir/shlib-2.o"]
152     || ![ld_link $ld tmpdir/libtestb.so "-shared -EB tmpdir/shlib-1b.o tmpdir/shlib-2b.o"]
153     || ![ld_link $ld tmpdir/shlib.o "-r tmpdir/shlib-1.o tmpdir/shlib-2.o"]
154     || ![ld_link $ld tmpdir/shlibb.o "-r -EB tmpdir/shlib-1b.o tmpdir/shlib-2b.o"]
155     || ![ld_link $ld tmpdir/dynapp-1 "tmpdir/libtest.so tmpdir/shlib-app-1.o"]
156     || ![ld_link $ld tmpdir/dynapp-1b "-EB tmpdir/libtestb.so tmpdir/shlib-app-1b.o"] } {
157    fail "TIC6X OSABI tests"
158    return
159}
160
161# A procedure to check the OS/ABI field in the ELF header of a binary file.
162proc check_osabi_tic6x { test_name binary_file } {
163    global READELF
164    global READELFFLAGS
165    global expected_osabi
166
167    set cmd "$READELF $READELFFLAGS --file-header $binary_file"
168    send_log "$cmd\n"
169    set got [remote_exec host [concat sh -c [list "$cmd >dump.out"]] "" "/dev/null"]
170
171    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
172	send_log "$got\n"
173	unresolved "$test_name"
174	remote_file build delete "dump.out"
175	return
176    }
177    remote_upload host "dump.out"
178
179    if { ![regexp "\n\[ \]*OS/ABI:\[ \]*(.+)\n\[ \]*ABI" \
180	   [file_contents dump.out] nil osabi] } {
181	verbose "proc check_osabi_tic6x: Readelf failed to extract an ELF header from $binary_file"
182	unresolved "$test_name"
183    } elseif { $osabi == $expected_osabi } {
184	pass "$test_name"
185    } else {
186	verbose "Expected OSABI: $expected_osabi, Obtained osabi: $osabi"
187	fail "$test_name"
188    }
189    remote_file build delete "dump.out"
190    remote_file host delete "dump.out"
191}
192
193check_osabi_tic6x "C6X shared library OSABI, LE" tmpdir/libtest.so
194check_osabi_tic6x "C6X shared library OSABI, BE" tmpdir/libtestb.so
195check_osabi_tic6x "C6X dynamic app OSABI, LE" tmpdir/dynapp-1
196check_osabi_tic6x "C6X dynamic app OSABI, BE" tmpdir/dynapp-1b
197
198check_osabi_tic6x "C6X relocatable link OSABI, LE" tmpdir/shlib.o
199check_osabi_tic6x "C6X relocatable link OSABI, BE" tmpdir/shlibb.o
200