aboutsummaryrefslogtreecommitdiff
path: root/binutils/testsuite
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2015-02-13 17:04:42 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2015-02-28 21:25:51 +0000
commitacf1419f9c52d06ee70169b85c5f8980c7359f8f (patch)
treed8a193b0f2a2411aa63f1cf4a4284c33368cb5df /binutils/testsuite
parentb7236fbee40060bcf5e90740a5c5706317749f91 (diff)
downloadgdb-acf1419f9c52d06ee70169b85c5f8980c7359f8f.zip
gdb-acf1419f9c52d06ee70169b85c5f8980c7359f8f.tar.gz
gdb-acf1419f9c52d06ee70169b85c5f8980c7359f8f.tar.bz2
objcopy: Add --update-section option.
New option for objcopy --update-section allows the contents of a section to be updated while maintaining the section flags, and, for ELF files, the section to segment mapping. New test uses --dump-section and --update-section to check that a section can be made larger and smaller with an update. binutils/ChangeLog: * objcopy.c (update_sections): New list. (command_line_switch): Add OPTION_UPDATE_SECTION. (copy_options): Add update-section. (copy_usage): Document new option. (is_update_section): New function. (is_strip_section_1): Add check for attempt to update and remove the same section. (copy_object): Update size and content of requested sections. (skip_section): Don't copy for updated sections. (copy_main): Handle --update-section. * doc/binutils.texi (objcopy): Add description of --update-section option. * NEWS: Mention --update-section option. binutils/testsuite/ChangeLog: * binutils-all/update-1.s: New file. * binutils-all/update-2.s: New file. * binutils-all/update-3.s: New file. * binutils-all/update-4.s: New file. * binutils-all/update-section.exp: New file.
Diffstat (limited to 'binutils/testsuite')
-rw-r--r--binutils/testsuite/ChangeLog8
-rw-r--r--binutils/testsuite/binutils-all/update-1.s2
-rw-r--r--binutils/testsuite/binutils-all/update-2.s2
-rw-r--r--binutils/testsuite/binutils-all/update-3.s3
-rw-r--r--binutils/testsuite/binutils-all/update-4.s2
-rw-r--r--binutils/testsuite/binutils-all/update-section.exp114
6 files changed, 131 insertions, 0 deletions
diff --git a/binutils/testsuite/ChangeLog b/binutils/testsuite/ChangeLog
index 8e78434..ef8efa3 100644
--- a/binutils/testsuite/ChangeLog
+++ b/binutils/testsuite/ChangeLog
@@ -1,3 +1,11 @@
+2015-02-26 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * binutils-all/update-1.s: New file.
+ * binutils-all/update-2.s: New file.
+ * binutils-all/update-3.s: New file.
+ * binutils-all/update-4.s: New file.
+ * binutils-all/update-section.exp: New file.
+
2015-02-24 Nick Clifton <nickc@redhat.com>
* binutils-all/objcopy.exp: Skip the strip-10 test for the V850.
diff --git a/binutils/testsuite/binutils-all/update-1.s b/binutils/testsuite/binutils-all/update-1.s
new file mode 100644
index 0000000..8ef51a0
--- /dev/null
+++ b/binutils/testsuite/binutils-all/update-1.s
@@ -0,0 +1,2 @@
+ .section ".foo", "aw"
+ .word 1, 1, 1, 1
diff --git a/binutils/testsuite/binutils-all/update-2.s b/binutils/testsuite/binutils-all/update-2.s
new file mode 100644
index 0000000..b720812
--- /dev/null
+++ b/binutils/testsuite/binutils-all/update-2.s
@@ -0,0 +1,2 @@
+ .section ".foo", "aw"
+ .word 2, 2, 2, 2, 2, 2
diff --git a/binutils/testsuite/binutils-all/update-3.s b/binutils/testsuite/binutils-all/update-3.s
new file mode 100644
index 0000000..087986f
--- /dev/null
+++ b/binutils/testsuite/binutils-all/update-3.s
@@ -0,0 +1,3 @@
+ .section ".foo", "aw"
+ .word 3, 3
+
diff --git a/binutils/testsuite/binutils-all/update-4.s b/binutils/testsuite/binutils-all/update-4.s
new file mode 100644
index 0000000..ae8a844
--- /dev/null
+++ b/binutils/testsuite/binutils-all/update-4.s
@@ -0,0 +1,2 @@
+ .section ".bar", "aw"
+ .word 5
diff --git a/binutils/testsuite/binutils-all/update-section.exp b/binutils/testsuite/binutils-all/update-section.exp
new file mode 100644
index 0000000..6a74302
--- /dev/null
+++ b/binutils/testsuite/binutils-all/update-section.exp
@@ -0,0 +1,114 @@
+# Copyright (C) 2015 Free Software Foundation, Inc.
+
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
+
+if { [is_remote host] } then {
+ return
+}
+
+send_user "Version [binutil_version $OBJCOPY]"
+
+proc do_assemble {srcfile} {
+ global srcdir
+ global subdir
+ set objfile [regsub -- "\.s$" $srcfile ".o"]
+ if {![binutils_assemble $srcdir/$subdir/${srcfile} tmpdir/${objfile}]} then {
+ return 0;
+ }
+ return 1;
+}
+
+proc do_objcopy {objfile extraflags {pattern ""}} {
+ global OBJCOPY
+ global OBJCOPYFLAGS
+
+ set testname "objcopy $extraflags ${objfile}"
+ set got [binutils_run $OBJCOPY \
+ "$OBJCOPYFLAGS ${extraflags} tmpdir/${objfile}"]
+ if ![regexp $pattern $got] then {
+ fail "objcopy ($testname)"
+ return 0
+ }
+ if { $pattern != "" } then {
+ pass "objcopy ($testname)"
+ }
+ return 1
+}
+
+proc do_compare {file1 file2} {
+ set src1 "tmpdir/${file1}"
+ set src2 "tmpdir/${file2}"
+ set status [remote_exec build cmp "${src1} ${src2}"]
+ set exec_output [lindex $status 1]
+ set exec_output [prune_warnings $exec_output]
+
+ set testname "compare ${file1} ${file2}"
+ if [string match "" $exec_output] then {
+ pass "objcopy ($testname)"
+ } else {
+ send_log "$exec_output\n"
+ verbose "$exec_output" 1
+ fail "objcopy ($testname)"
+ return 0
+ }
+ return 1
+}
+
+#
+# Start Of Tests
+#
+
+foreach f [list update-1.s update-2.s update-3.s update-4.s] {
+ if { ![do_assemble $f] } then {
+ unsupported "update-section.exp"
+ return
+ }
+}
+
+if { ![do_objcopy update-1.o \
+ "--dump-section .foo=tmpdir/dumped-contents"]
+ || ![do_objcopy update-2.o \
+ "--update-section .foo=tmpdir/dumped-contents"]
+ || ![do_objcopy update-3.o \
+ "--update-section .foo=tmpdir/dumped-contents"]
+ || ![do_objcopy update-4.o \
+ "--update-section .bar=tmpdir/dumped-contents \
+ --rename-section .bar=.foo"] } then {
+ # If any of the above tests failed then a FAIL will already have
+ # been reported.
+ return
+}
+
+# Check that the updated object files are as expected.
+do_compare update-1.o update-2.o
+do_compare update-1.o update-3.o
+do_compare update-1.o update-4.o
+
+# Check that --update-section on an unknown section will fail.
+if { ![do_objcopy update-2.o \
+ "--update-section .bar=tmpdir/dumped-contents" \
+ "error: .bar not found, can't be updated"] } then {
+ return
+}
+
+# Check that --update-section and --remove-section on the same section
+# will fail.
+if { ![do_objcopy update-2.o \
+ "--update-section .foo=tmpdir/dumped-contents \
+ --remove-section .foo" \
+ "error: section .foo matches both update and remove options"] \
+ } then {
+ return
+}