1 # Copyright (C) 2015 Free Software Foundation, Inc.
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.
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.
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.
17 if { [is_remote host] } then {
21 send_user "Version [binutil_version $OBJCOPY]"
23 proc do_assemble {srcfile} {
26 set objfile [regsub -- "\.s$" $srcfile ".o"]
27 if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/${objfile}]} then {
33 proc do_objcopy {objfile extraflags {pattern ""}} {
37 set testname "objcopy $extraflags ${objfile}"
38 set got [binutils_run $OBJCOPY \
39 "$OBJCOPYFLAGS ${extraflags} tmpdir/${objfile}"]
40 if ![regexp $pattern $got] then {
41 fail "objcopy ($testname)"
44 if { $pattern != "" } then {
45 pass "objcopy ($testname)"
50 proc do_compare {file1 file2} {
51 set src1 "tmpdir/${file1}"
52 set src2 "tmpdir/${file2}"
53 set status [remote_exec build cmp "${src1} ${src2}"]
54 set exec_output [lindex $status 1]
55 set exec_output [prune_warnings $exec_output]
57 set testname "compare ${file1} ${file2}"
58 if [string match "" $exec_output] then {
59 pass "objcopy ($testname)"
61 send_log "$exec_output\n"
62 verbose "$exec_output" 1
63 fail "objcopy ($testname)"
73 foreach f [list update-1.s update-2.s update-3.s update-4.s] {
74 if { ![do_assemble $f] } then {
75 unsupported "update-section.exp"
80 if { ![do_objcopy update-1.o \
81 "--dump-section .foo=tmpdir/dumped-contents"]
82 || ![do_objcopy update-2.o \
83 "--update-section .foo=tmpdir/dumped-contents"]
84 || ![do_objcopy update-3.o \
85 "--update-section .foo=tmpdir/dumped-contents"]
86 || ![do_objcopy update-4.o \
87 "--update-section .bar=tmpdir/dumped-contents \
88 --rename-section .bar=.foo"] } then {
89 # If any of the above tests failed then a FAIL will already have
94 # Check that the updated object files are as expected.
95 do_compare update-1.o update-2.o
96 do_compare update-1.o update-3.o
97 do_compare update-1.o update-4.o
99 # Check that --update-section on an unknown section will fail.
100 if { ![do_objcopy update-2.o \
101 "--update-section .bar=tmpdir/dumped-contents" \
102 "error: .bar not found, can't be updated"] } then {
106 # Check that --update-section and --remove-section on the same section
108 if { ![do_objcopy update-2.o \
109 "--update-section .foo=tmpdir/dumped-contents \
110 --remove-section .foo" \
111 "error: section .foo matches both update and remove options"] \