tic6x.exp 8.5 KB

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