selective.exp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. # Expect script for LD selective linking tests
  2. # Copyright (C) 1998-2022 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. # Written by Catherine Moore (clm@cygnus.com)
  22. # Make sure that constructors are handled correctly.
  23. # Only ELF based ports support selective linking
  24. if { ![is_elf_format] || ![check_gc_sections_available] } {
  25. return
  26. }
  27. # List contains test-items with three items followed by four lists:
  28. # 1:name 2:test-type (CC or C++; add as needed) 3:filename 4:ld-flags
  29. # 5:must-have-symbols 6:must-not-have-symbols 7:xfail-targets.
  30. #
  31. # If a must(-not)-have symbol is a list, then that list must have two
  32. # items; the symbol name and a value the symbol must (not) have.
  33. #
  34. # Note: ld_nm trims leading `_' from _start
  35. #
  36. # FIXME: Instead of table, read settings from each source-file.
  37. set seltests {
  38. {selective1 C 1.c {} {} {dropme1 dropme2} {}}
  39. {selective2 C 2.c {} {} {foo} {}}
  40. {selective3 C 2.c {-u foo} {foo} {{foo 0}} {}}
  41. {selective4 C++ 3.cc {} {start a A::foo() B::foo()} {A::bar()} {mips*-*}}
  42. {selective5 C++ 4.cc {} {start a A::bar()} {A::foo() B::foo()} {mips*-*}}
  43. {selective6 C++ 5.cc {} {start a A::bar()}
  44. {A::foo() B::foo() dropme1() dropme2()} {*-*-*}}
  45. }
  46. set cflags "-w -O -ffunction-sections -fdata-sections $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
  47. set cxxflags "-fno-exceptions -fno-rtti $NOSANITIZE_CFLAGS $NOLTO_CFLAGS"
  48. set ldflags "--gc-sections -Bstatic"
  49. if [istarget mips*-*] {
  50. # MIPS16 doesn't support PIC code.
  51. set cflags "-mno-abicalls $cflags"
  52. # MIPS ELF uses __start by default, we override it.
  53. set ldflags "-e _start $ldflags"
  54. }
  55. if [istarget avr-*-*] {
  56. # Make .text start at a non-zero address, as some tests expect
  57. # valid symbols to have non-zero values.
  58. set ldflags "--section-start=.text=0x2 $ldflags"
  59. }
  60. # If we don't have g++ for the target, mark all tests as untested.
  61. if { ![is_remote host] && [which $CXX_FOR_TARGET] == 0 } {
  62. foreach testitem $seltests {
  63. untested "[lindex $testitem 0]"
  64. }
  65. return
  66. }
  67. foreach testitem $seltests {
  68. set testname [lindex $testitem 0]
  69. set testtype [lindex $testitem 1]
  70. set testfile [lindex $testitem 2]
  71. set objfile "tmpdir/[file rootname $testfile].o"
  72. set ldfile "tmpdir/[file rootname $testfile].x"
  73. set failed 0
  74. set ldargs [lindex $testitem 3]
  75. set mustsyms [lindex $testitem 4]
  76. set mustnotsyms [lindex $testitem 5]
  77. set xfails [lindex $testitem 6]
  78. foreach xfail_target $xfails {
  79. setup_xfail $xfail_target
  80. }
  81. # It's either C or C++ at the moment.
  82. if { $testtype == "C++" } {
  83. set compiler "$CXX_FOR_TARGET"
  84. # Starting with 3.4.0, -fvtable-gc is no longer supported and thus
  85. # the functionality we try to test for cannot be expected to work.
  86. set version [remote_exec host "$CXX_FOR_TARGET -dumpversion"]
  87. set version [lindex $version 1]
  88. if { [regexp "^(\[1-9\]\[0-9\]+|\[4-9\]|3.(\[1-9\]\[0-9\]+))\\." $version] \
  89. || [regexp "^(\[1-9\]\[0-9\]+|\[4-9\])" $version] } {
  90. set testflags "$cflags $cxxflags"
  91. setup_xfail {*-*-*}
  92. } else {
  93. set testflags "$cflags $cxxflags -fvtable-gc"
  94. }
  95. } else {
  96. set testflags "$cflags"
  97. set compiler "$CC_FOR_TARGET"
  98. }
  99. # Note that we do not actually *use* CXX; we just add cxxflags for C++
  100. # tests. It might have been a buglet originally; now I think better
  101. # leave as is.
  102. if { ![ld_compile "$compiler $testflags" $srcdir/$subdir/$testfile $objfile] } {
  103. unsupported $testname
  104. continue
  105. }
  106. # V850 targets need libgcc.a
  107. if [istarget v850*-*-elf] {
  108. set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
  109. set libgcc [lindex $libgcc 1]
  110. regsub -all "\[\r\n\]" $libgcc "" libgcc
  111. set objfile "$objfile $libgcc"
  112. }
  113. # ARM targets need libgcc.a in THUMB mode so that __call_via_r3 is provided
  114. if {[istarget arm-*-*]} {
  115. set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
  116. set libgcc [lindex $libgcc 1]
  117. regsub -all "\[\r\n\]" $libgcc "" libgcc
  118. set objfile "$objfile $libgcc"
  119. }
  120. # HPPA linux targets need libgcc.a for millicode routines ($$dyncall).
  121. if [istarget hppa*-*-linux*] {
  122. set libgcc [remote_exec host "$compiler -print-libgcc-file-name"]
  123. set libgcc [lindex $libgcc 1]
  124. regsub -all "\[\r\n\]" $libgcc "" libgcc
  125. set objfile "$objfile $libgcc"
  126. }
  127. # m6811/m6812 code has references to soft registers.
  128. if {[istarget m6811-*-*] || [istarget m6812-*-*] || [istarget m68hc1*-*-*]} {
  129. set objfile "$objfile --defsym _.frame=0 --defsym _.d1=0"
  130. set objfile "$objfile --defsym _.d2=0"
  131. }
  132. if ![ld_link $ld $ldfile "$ldflags [join $ldargs] $objfile"] {
  133. fail $testname
  134. continue
  135. }
  136. if ![ld_nm $nm --demangle $ldfile] {
  137. fail $testname
  138. continue
  139. }
  140. # Must make V2 demangled names look like V3
  141. foreach nm_output_key [array names nm_output] {
  142. if [regsub \\(void\\) $nm_output_key () new_nm_output_key] {
  143. set nm_output($new_nm_output_key) nm_output($nm_output_key)
  144. }
  145. }
  146. # Check each mandated symbol and optionally mandated values.
  147. foreach mustsym $mustsyms {
  148. if { [llength [concat $mustsym]] == 1 } {
  149. if { ![info exists nm_output($mustsym)] } {
  150. verbose -log "$testname: missing $mustsym"
  151. fail $testname
  152. set failed 1
  153. break
  154. }
  155. } {
  156. set mustsymname [lindex $mustsym 0]
  157. set mustsymvalue [lindex $mustsym 1]
  158. if { ![info exists nm_output($mustsymname)] } {
  159. verbose -log "$testname: missing $mustsymname"
  160. fail $testname
  161. set failed 1
  162. break
  163. } {
  164. if { $nm_output($mustsymname) != $mustsymvalue } {
  165. verbose -log "$testname: $mustsymname != $mustsymvalue"
  166. verbose -log "is instead $nm_output($mustsymname)"
  167. fail $testname
  168. set failed 1
  169. break
  170. }
  171. }
  172. }
  173. }
  174. if { $failed != 0 } {
  175. continue
  176. }
  177. # Check each unwanted symbol, or that symbols do not have specific
  178. # values.
  179. foreach mustnotsym $mustnotsyms {
  180. if { [llength [concat $mustnotsym]] == 1 } {
  181. if { [info exists nm_output($mustnotsym)] } {
  182. verbose -log "$testname: $mustnotsym == $nm_output($mustnotsym)"
  183. fail $testname
  184. set failed 1
  185. break
  186. }
  187. } {
  188. set mustnotsymname [lindex $mustnotsym 0]
  189. set mustnotsymvalue [lindex $mustnotsym 1]
  190. if { [info exists nm_output($mustnotsymname)] \
  191. && $nm_output($mustnotsymname) == $mustnotsymvalue} {
  192. verbose -log "$testname: $mustnotsymname == $mustnotsymvalue"
  193. fail $testname
  194. set failed 1
  195. break
  196. }
  197. }
  198. }
  199. if { $failed == 0 } {
  200. pass $testname
  201. }
  202. }