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