bootstrap.exp 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. # Expect script for LD Bootstrap Tests
  2. # Copyright (C) 1993-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 Jeffrey Wheat (cassidy@cygnus.com)
  22. # Rewritten by Ian Lance Taylor (ian@cygnus.com)
  23. #
  24. # Make sure that ld can bootstrap itself.
  25. # This test can only be run if ld generates native executables.
  26. if ![isnative] {
  27. return
  28. }
  29. # Skip for -fprofile-generate=.
  30. catch "exec $nm $plug_opt $OFILES" exec_output
  31. send_log "foo: $exec_output"
  32. if { [ string match "*__gcov_*" $exec_output ] } {
  33. return
  34. }
  35. remote_exec host "$nm --help" "" "/dev/null" "plugin-support"
  36. set tmp [file_contents "plugin-support"]
  37. regexp ".*\(--plugin\).*\n" $tmp foo plugins
  38. if [info exists plugins] then {
  39. set plugins "yes"
  40. } else {
  41. set plugins "no"
  42. }
  43. # LD can have plugin support even if BFD does not.
  44. if [check_plugin_api_available] {
  45. set plugins "yes"
  46. }
  47. # Bootstrap ld. First link the object files together using -r, in
  48. # order to test -r. Then link the result into an executable, ld1, to
  49. # really test -r. Use ld1 to link a fresh ld, ld2. Use ld2 to link a
  50. # new ld, ld3. ld2 and ld3 should be identical.
  51. set test_flags {"" "strip" "--static" "-Wl,--traditional-format"
  52. "-Wl,--no-keep-memory" "-Wl,--relax"
  53. "-Wl,--max-cache-size=-1"}
  54. if { [istarget "powerpc-*-*"] } {
  55. lappend test_flags "-Wl,--ppc476-workaround"
  56. }
  57. set gcc_B_opt_save $gcc_B_opt
  58. if {![file exists tmpdir/ldscripts]} then {
  59. catch "exec ln -s ../ldscripts tmpdir/ldscripts" status
  60. }
  61. foreach ldexe {ld1 ld2 ld3} {
  62. if {![file isdirectory tmpdir/gcc$ldexe]} then {
  63. catch "exec mkdir tmpdir/gcc$ldexe" status
  64. catch "exec ln -s ../$ldexe tmpdir/gcc$ldexe/ld" status
  65. catch "exec ln -s ld tmpdir/gcc$ldexe/collect-ld" status
  66. catch "exec ln -s ../../../gas/as-new tmpdir/gcc$ldexe/as" status
  67. }
  68. }
  69. foreach flags $test_flags {
  70. set gcc_B_opt $gcc_B_opt_save
  71. set do_strip "no"
  72. if {"$flags" == "strip"} {
  73. set testname "bootstrap with $flags"
  74. set flags ""
  75. set do_strip "yes"
  76. } else { if {"$flags" != ""} {
  77. set testname "bootstrap with $flags"
  78. } else {
  79. set testname "bootstrap"
  80. }}
  81. # --static is meaningless and --relax is incompatible with -r.
  82. regsub -- "-Wl," $flags "" partial_flags
  83. if { "$partial_flags" == "--static" || "$partial_flags" == "--relax" } {
  84. set partial_flags ""
  85. }
  86. if { $partial_flags == "--ppc476-workaround" } {
  87. append partial_flags " -T $srcdir/$subdir/ppc476.t"
  88. }
  89. # This test can only be run if we have the ld build directory,
  90. # since we need the object files.
  91. if {$ld != "$objdir/ld-new"} {
  92. untested $testname
  93. continue
  94. }
  95. # If -static doesn't work, these tests will fail.
  96. if { $flags == "--static" && [string match "" $STATIC_LDFLAGS] } then {
  97. untested $testname
  98. continue
  99. }
  100. # Plugin support requires linking with a dynamic library which
  101. # means that these tests will fail.
  102. if { $flags == "--static" && $plugins == "yes" } then {
  103. untested $testname
  104. continue
  105. }
  106. # If we only have a shared libbfd, we probably can't run the
  107. # --static test.
  108. if { $flags == "--static" && ! [string match "*libbfd.a*" $BFDLIB] } then {
  109. untested $testname
  110. continue
  111. }
  112. if ![ld_relocate $ld tmpdir/ld-partial.o "$partial_flags $OFILES"] {
  113. fail $testname
  114. continue
  115. }
  116. # On AIX, you need to specify an import list when using --static.
  117. # You only want the import list when creating the final
  118. # executable.
  119. if { [istarget "*-*-aix*"]
  120. && ![istarget "ia64-*-aix*"]} {
  121. if {"$flags" == "--static"} {
  122. set flags "--static -bI:/lib/syscalls.exp"
  123. }
  124. }
  125. # On Cygwin, -lintl may require -liconv when linking statically.
  126. set extralibs ""
  127. if { [istarget "*-*-cygwin*"]} {
  128. if {"$flags" == "--static"} {
  129. set extralibs "-liconv"
  130. }
  131. }
  132. # Check if the system's zlib library is used.
  133. if {[file exists ../zlib/Makefile ]} then {
  134. set extralibs "$extralibs -L../zlib -lz"
  135. } else {
  136. set extralibs "$extralibs -lz"
  137. }
  138. # Plugin support requires linking with libdl.
  139. if { $plugins == "yes" } {
  140. if { ![istarget "*-*-freebsd*"]} {
  141. set extralibs "$extralibs -ldl"
  142. }
  143. }
  144. # On Irix 5, linking with --static only works if all the files are
  145. # compiled using -non_shared.
  146. if {"$flags" == "--static"} {
  147. setup_xfail "mips*-*-irix5*"
  148. }
  149. if ![ld_link $CC tmpdir/ld1 "$CFLAGS $flags tmpdir/ld-partial.o $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
  150. fail $testname
  151. continue
  152. }
  153. if {"$do_strip" == "yes"} {
  154. verbose -log "$strip tmpdir/ld1"
  155. catch "exec $strip tmpdir/ld1" exec_output
  156. set exec_output [prune_warnings $exec_output]
  157. if ![string match "" $exec_output] then {
  158. verbose -log "$exec_output"
  159. fail $testname
  160. continue
  161. }
  162. }
  163. regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld1/ gcc_B_opt
  164. if ![ld_link $CC tmpdir/ld2 "$CFLAGS $flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
  165. fail $testname
  166. continue
  167. }
  168. regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld2/ gcc_B_opt
  169. if ![ld_link $CC tmpdir/ld3 "$CFLAGS $flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
  170. fail $testname
  171. continue
  172. }
  173. if { "$flags" == "--static"
  174. && ([istarget ia64-*-elf*]
  175. || [istarget ia64-*-linux*]
  176. || [istarget mips*-*-linux*]) } {
  177. # On ia64 and mips, tmpdir/ld2 != tmpdir/ld3 is normal since they are
  178. # generated by different linkers, tmpdir/ld1 and tmpdir/ld2.
  179. # So we rebuild tmpdir/ld2 with tmpdir/ld3.
  180. regsub /tmpdir/ld/ $gcc_B_opt_save /tmpdir/gccld3/ gcc_B_opt
  181. if ![ld_link $CC tmpdir/ld2 "$CFLAGS $flags $OFILES $CTFLIB $BFDLIB $LIBIBERTY $extralibs"] {
  182. fail $testname
  183. continue
  184. }
  185. }
  186. if {[istarget "*-*-pe"]
  187. || [istarget "*-*-wince"]
  188. || [istarget "*-*-cygwin*"]
  189. || [istarget "*-*-winnt*"]
  190. || [istarget "*-*-mingw*"]
  191. || [istarget "*-*-interix*"]
  192. || [istarget "*-*-beospe*"]} {
  193. # Trim off the date present in PE binaries by only looking
  194. # at the ends of the files
  195. # Although this works, a way to set the date would be better.
  196. # Removing or zeroing the date stamp in the binary produced by
  197. # the linker is not possible as it is required by the target OS.
  198. set do_compare [string map {16 220 f1 tmpdir/ld2 f2 tmpdir/ld3 tmp-foo1 tmpdir/ld2tail tmp-foo2 tmpdir/ld3tail} $DO_COMPARE]
  199. send_log "$do_compare\n"
  200. verbose "$do_compare"
  201. catch "exec sh -c [list $do_compare]" exec_output
  202. } else {
  203. send_log "cmp tmpdir/ld2 tmpdir/ld3\n"
  204. verbose "cmp tmpdir/ld2 tmpdir/ld3"
  205. catch "exec cmp tmpdir/ld2 tmpdir/ld3" exec_output
  206. }
  207. set exec_output [prune_warnings $exec_output]
  208. if [string match "" $exec_output] then {
  209. pass $testname
  210. } else {
  211. send_log "$exec_output\n"
  212. verbose "$exec_output" 1
  213. fail $testname
  214. }
  215. }
  216. set gcc_B_opt $gcc_B_opt_save
  217. catch "exec rm -f tmpdir/ld-partial.o tmpdir/ld1 tmpdir/ld2 tmpdir/ld3" status
  218. catch "exec rm -f tmpdir/ld2tail tmpdir/ld3tail" status