update-section.exp 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. # Copyright (C) 2015 Free Software Foundation, Inc.
  2. # This program is free software; you can redistribute it and/or modify
  3. # it under the terms of the GNU General Public License as published by
  4. # the Free Software Foundation; either version 3 of the License, or
  5. # (at your option) any later version.
  6. #
  7. # This program is distributed in the hope that it will be useful,
  8. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. # GNU General Public License for more details.
  11. #
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program; if not, write to the Free Software
  14. # Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
  15. if { [is_remote host] } then {
  16. return
  17. }
  18. # These tests use ELF .section directives
  19. if ![is_elf_format] {
  20. return
  21. }
  22. send_user "Version [binutil_version $OBJCOPY]"
  23. proc do_assemble {srcfile} {
  24. global srcdir
  25. global subdir
  26. set objfile [regsub -- "\.s$" $srcfile ".o"]
  27. if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/${objfile}]} then {
  28. return 0;
  29. }
  30. return 1;
  31. }
  32. proc do_objcopy {objfile extraflags {pattern ""}} {
  33. global OBJCOPY
  34. global OBJCOPYFLAGS
  35. set testname "objcopy $extraflags ${objfile}"
  36. set got [binutils_run $OBJCOPY \
  37. "$OBJCOPYFLAGS ${extraflags} tmpdir/${objfile}"]
  38. if ![regexp $pattern $got] then {
  39. fail "objcopy ($testname)"
  40. return 0
  41. }
  42. if { $pattern != "" } then {
  43. pass "objcopy ($testname)"
  44. }
  45. return 1
  46. }
  47. proc do_compare {file1 file2} {
  48. set src1 "tmpdir/${file1}"
  49. set src2 "tmpdir/${file2}"
  50. set status [remote_exec build cmp "${src1} ${src2}"]
  51. set exec_output [lindex $status 1]
  52. set exec_output [prune_warnings $exec_output]
  53. set testname "compare ${file1} ${file2}"
  54. if [string match "" $exec_output] then {
  55. pass "objcopy ($testname)"
  56. } else {
  57. send_log "$exec_output\n"
  58. verbose "$exec_output" 1
  59. fail "objcopy ($testname)"
  60. return 0
  61. }
  62. return 1
  63. }
  64. #
  65. # Start Of Tests
  66. #
  67. foreach f [list update-1.s update-2.s update-3.s update-4.s] {
  68. if { ![do_assemble $f] } then {
  69. unsupported "update-section.exp"
  70. return
  71. }
  72. }
  73. if { ![do_objcopy update-1.o \
  74. "--dump-section .foo=tmpdir/dumped-contents"]
  75. || ![do_objcopy update-2.o \
  76. "--update-section .foo=tmpdir/dumped-contents"]
  77. || ![do_objcopy update-3.o \
  78. "--update-section .foo=tmpdir/dumped-contents"]
  79. || ![do_objcopy update-4.o \
  80. "--update-section .bar=tmpdir/dumped-contents \
  81. --rename-section .bar=.foo"] } then {
  82. # If any of the above tests failed then a FAIL will already have
  83. # been reported.
  84. return
  85. }
  86. # Check that the updated object files are as expected.
  87. do_compare update-1.o update-2.o
  88. do_compare update-1.o update-3.o
  89. do_compare update-1.o update-4.o
  90. # Check that --update-section on an unknown section will fail.
  91. if { ![do_objcopy update-2.o \
  92. "--update-section .bar=tmpdir/dumped-contents" \
  93. "error: .bar not found, can't be updated"] } then {
  94. return
  95. }
  96. # Check that --update-section and --remove-section on the same section
  97. # will fail.
  98. if { ![do_objcopy update-2.o \
  99. "--update-section .foo=tmpdir/dumped-contents \
  100. --remove-section .foo" \
  101. "error: section .foo matches both update and remove options"] \
  102. } then {
  103. return
  104. }