1 # Copyright (C) 2015-2020 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 # Check that we can dump empty sections.
86 if { ![do_objcopy update-1.o "--dump-section .text=tmpdir/empty"] } {
87 fail "objcopy (dump empty section)"
89 pass "objcopy (dump empty section)"
92 if { ![do_objcopy update-1.o \
93 "--dump-section .foo=tmpdir/dumped-contents"]
94 || ![do_objcopy update-2.o \
95 "--update-section .foo=tmpdir/dumped-contents"]
96 || ![do_objcopy update-3.o \
97 "--update-section .foo=tmpdir/dumped-contents"]
98 || ![do_objcopy update-4.o \
99 "--update-section .bar=tmpdir/dumped-contents \
100 --rename-section .bar=.foo"] } then {
101 # If any of the above tests failed then a FAIL will already have
106 # Check that the updated object files are as expected.
107 do_compare update-1.o update-2.o
108 do_compare update-1.o update-3.o
109 do_compare update-1.o update-4.o
111 # Check that --update-section on an unknown section will fail.
112 if { ![do_objcopy update-2.o \
113 "--update-section .bar=tmpdir/dumped-contents" \
114 "error: .bar not found, can't be updated"] } then {
118 # Check that --update-section and --remove-section on the same section
120 if { ![do_objcopy update-2.o \
121 "--update-section .foo=tmpdir/dumped-contents \
122 --remove-section .foo" \
123 "error: section .foo matches both update and remove options"] \