checks.exp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. # Expect script for LD section checks tests
  2. # Copyright (C) 1999-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 Nick Clifton (nickc@cygnus.com)
  22. proc section_check {} {
  23. global LDFLAGS
  24. global as
  25. global ld
  26. global srcdir
  27. global subdir
  28. # The usage of .lcomm in asm.s is incompatible with ia64 and ppc xcoff.
  29. if { [istarget ia64-*-*] || [is_xcoff_format] } {
  30. return
  31. }
  32. set test "check sections 1"
  33. set ldflags "$LDFLAGS --check-sections -e foo"
  34. if { ![ld_assemble $as $srcdir/$subdir/asm.s tmpdir/asm.o]} {
  35. unsupported $test
  36. return
  37. }
  38. if ![ld_link $ld tmpdir/asm.x "$ldflags tmpdir/asm.o"] {
  39. fail $test
  40. } else {
  41. pass $test
  42. }
  43. set test "check sections 2"
  44. # Change the linker flags so that our "buggy" linker
  45. # script is used.
  46. set ldflags "$LDFLAGS --check-sections -T $srcdir/$subdir/script -e foo"
  47. # Perform the equivalent of invoking ld_link
  48. # except that we need to massage the output further.
  49. set exec_output [run_host_cmd "$ld" "-o tmpdir/asm.x $ldflags tmpdir/asm.o"]
  50. set exec_output [prune_warnings $exec_output]
  51. # Make sure that we got some output from the linker
  52. if [string match "" $exec_output] then {
  53. fail $test
  54. }
  55. # Now remove our expected error message
  56. regsub -all ".*: section .data .* overlaps section .text .*" $exec_output "" exec_output
  57. # And check to see if anything else, (unexpected) was left
  58. if [string match "" $exec_output] then {
  59. pass $test
  60. } else {
  61. verbose -log "Unexpected linker message(s): $exec_output"
  62. fail $test
  63. }
  64. }
  65. proc overflow_check {} {
  66. # Test only on some 32-bit targets that are often tested
  67. if { ![istarget i?86-*-*]
  68. && ![istarget powerpc-*-*]
  69. && ![istarget arm*-*-*] } {
  70. return
  71. }
  72. if ![is_elf_format] {
  73. return
  74. }
  75. run_dump_test "over"
  76. run_dump_test "over2"
  77. }
  78. section_check
  79. overflow_check