1 # Copyright (C) 2015-2018 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 # These tests use ELF .section directives
26 send_user "Version [binutil_version $OBJCOPY]"
28 proc do_assemble {srcfile} {
31 set objfile [regsub -- "\.s$" $srcfile ".o"]
32 if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/${objfile}]} then {
38 proc do_objcopy {objfile extraflags {pattern ""}} {
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)"
49 if { $pattern != "" } then {
50 pass "objcopy ($testname)"
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]
62 set testname "compare ${file1} ${file2}"
63 if [string match "" $exec_output] then {
64 pass "objcopy ($testname)"
66 send_log "$exec_output\n"
67 verbose "$exec_output" 1
68 fail "objcopy ($testname)"
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"
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
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
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 {
111 # Check that --update-section and --remove-section on the same section
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"] \