This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] MIPS/BFD: Correctly report unsupported `.reginfo' section size


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2d6dda71611ba6cc16fe2bd21ac816d5f7d1e74d

commit 2d6dda71611ba6cc16fe2bd21ac816d5f7d1e74d
Author: Maciej W. Rozycki <macro@mips.com>
Date:   Mon Feb 5 14:00:21 2018 +0000

    MIPS/BFD: Correctly report unsupported `.reginfo' section size
    
    Report an error when an unsupported `.reginfo' section size is found in
    `_bfd_mips_elf_section_processing', removing an assertion that triggers
    at elfxx-mips.c:7105 in GAS when assembling input like:
    
    	.section	.reginfo
    	.word		0xdeadbeef
    
    and in `objcopy --rename-section' when renaming an incorrectly sized
    section to `.reginfo'.
    
    	bfd/
    	* elfxx-mips.c (_bfd_mips_elf_section_processing): For
    	SHT_MIPS_REGINFO sections don't assert the correct size and
    	report an error instead.
    
    	binutils/
    	* testsuite/binutils-all/mips/mips-reginfo.d: New test.
    	* testsuite/binutils-all/mips/mips-reginfo-n32.d: New test.
    	* testsuite/binutils-all/mips/mips-reginfo.s: New test source.
    	* testsuite/binutils-all/mips/mips.exp: Run the new tests.
    
    	gas/
    	* testsuite/gas/mips/reginfo-2.d: New test.
    	* testsuite/gas/mips/reginfo-2-n32.d: New test.
    	* testsuite/gas/mips/reginfo-2.l: New test stderr output.
    	* testsuite/gas/mips/reginfo-2.s: New test source.
    	* testsuite/gas/mips/mips.exp: Run the new tests.

Diff:
---
 bfd/ChangeLog                                           |  6 ++++++
 bfd/elfxx-mips.c                                        | 11 ++++++++++-
 binutils/ChangeLog                                      |  7 +++++++
 binutils/testsuite/binutils-all/mips/mips-reginfo-n32.d |  7 +++++++
 binutils/testsuite/binutils-all/mips/mips-reginfo.d     |  6 ++++++
 binutils/testsuite/binutils-all/mips/mips-reginfo.s     |  2 ++
 binutils/testsuite/binutils-all/mips/mips.exp           |  5 +++++
 gas/ChangeLog                                           |  8 ++++++++
 gas/testsuite/gas/mips/mips.exp                         |  4 ++++
 gas/testsuite/gas/mips/reginfo-2-n32.d                  |  4 ++++
 gas/testsuite/gas/mips/reginfo-2.d                      |  3 +++
 gas/testsuite/gas/mips/reginfo-2.l                      |  3 +++
 gas/testsuite/gas/mips/reginfo-2.s                      |  2 ++
 13 files changed, 67 insertions(+), 1 deletion(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 091e363..9a8a320 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,11 @@
 2018-02-05  Maciej W. Rozycki  <macro@mips.com>
 
+	* elfxx-mips.c (_bfd_mips_elf_section_processing): For
+	SHT_MIPS_REGINFO sections don't assert the correct size and
+	report an error instead.
+
+2018-02-05  Maciej W. Rozycki  <macro@mips.com>
+
 	* elf.c (_bfd_elf_write_object_contents): Propagate a failure
 	status from `->elf_backend_section_processing'.
 
diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c
index 2854013..ab65894 100644
--- a/bfd/elfxx-mips.c
+++ b/bfd/elfxx-mips.c
@@ -7102,9 +7102,18 @@ _bfd_mips_elf_section_processing (bfd *abfd, Elf_Internal_Shdr *hdr)
     {
       bfd_byte buf[4];
 
-      BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo));
       BFD_ASSERT (hdr->contents == NULL);
 
+      if (hdr->sh_size != sizeof (Elf32_External_RegInfo))
+	{
+	  _bfd_error_handler
+	    (_("%B: Incorrect `.reginfo' section size; expected %Lu, got %Lu"),
+	     abfd, (bfd_size_type) sizeof (Elf32_External_RegInfo),
+	     hdr->sh_size);
+	  bfd_set_error (bfd_error_bad_value);
+	  return FALSE;
+	}
+
       if (bfd_seek (abfd,
 		    hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4,
 		    SEEK_SET) != 0)
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index b52c2d6..f6f3e99 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,5 +1,12 @@
 2018-02-05  Maciej W. Rozycki  <macro@mips.com>
 
+	* testsuite/binutils-all/mips/mips-reginfo.d: New test.
+	* testsuite/binutils-all/mips/mips-reginfo-n32.d: New test.
+	* testsuite/binutils-all/mips/mips-reginfo.s: New test source.
+	* testsuite/binutils-all/mips/mips.exp: Run the new tests.
+
+2018-02-05  Maciej W. Rozycki  <macro@mips.com>
+
 	* testsuite/config/default.exp (binutils_run): Document
 	`binutils_run_status'.
 	* testsuite/lib/utils-lib.exp (default_binutils_run): Likewise,
diff --git a/binutils/testsuite/binutils-all/mips/mips-reginfo-n32.d b/binutils/testsuite/binutils-all/mips/mips-reginfo-n32.d
new file mode 100644
index 0000000..fe55e95
--- /dev/null
+++ b/binutils/testsuite/binutils-all/mips/mips-reginfo-n32.d
@@ -0,0 +1,7 @@
+#PROG: objcopy
+#name: MIPS objcopy .reginfo section size (n32)
+#as: -n32 -mips3
+#objcopy: --rename-section .foo=.reginfo
+#source: mips-reginfo.s
+#error: \A[^\n]*: Incorrect `\.reginfo' section size; expected 24, got 4\n
+#error:   [^\n]*: Bad value\Z
diff --git a/binutils/testsuite/binutils-all/mips/mips-reginfo.d b/binutils/testsuite/binutils-all/mips/mips-reginfo.d
new file mode 100644
index 0000000..7a8c1ca
--- /dev/null
+++ b/binutils/testsuite/binutils-all/mips/mips-reginfo.d
@@ -0,0 +1,6 @@
+#PROG: objcopy
+#name: MIPS objcopy .reginfo section size
+#as: -32
+#objcopy: --rename-section .foo=.reginfo
+#error: \A[^\n]*: Incorrect `\.reginfo' section size; expected 24, got 4\n
+#error:   [^\n]*: Bad value\Z
diff --git a/binutils/testsuite/binutils-all/mips/mips-reginfo.s b/binutils/testsuite/binutils-all/mips/mips-reginfo.s
new file mode 100644
index 0000000..75eaa94
--- /dev/null
+++ b/binutils/testsuite/binutils-all/mips/mips-reginfo.s
@@ -0,0 +1,2 @@
+	.section .foo, "a"
+	.word	0xdeadbeef
diff --git a/binutils/testsuite/binutils-all/mips/mips.exp b/binutils/testsuite/binutils-all/mips/mips.exp
index be6e785..2167d4a 100644
--- a/binutils/testsuite/binutils-all/mips/mips.exp
+++ b/binutils/testsuite/binutils-all/mips/mips.exp
@@ -60,3 +60,8 @@ if $has_newabi {
     run_dump_test "mips-note-2r-n32"
     run_dump_test "mips-note-2r-n64"
 }
+
+run_dump_test "mips-reginfo"
+if $has_newabi {
+    run_dump_test "mips-reginfo-n32"
+}
diff --git a/gas/ChangeLog b/gas/ChangeLog
index 7bbb9ce..6c9ff3e 100644
--- a/gas/ChangeLog
+++ b/gas/ChangeLog
@@ -1,3 +1,11 @@
+2018-02-05  Maciej W. Rozycki  <macro@mips.com>
+
+	* testsuite/gas/mips/reginfo-2.d: New test.
+	* testsuite/gas/mips/reginfo-2-n32.d: New test.
+	* testsuite/gas/mips/reginfo-2.l: New test stderr output.
+	* testsuite/gas/mips/reginfo-2.s: New test source.
+	* testsuite/gas/mips/mips.exp: Run the new tests.
+
 2018-02-05  Nick Clifton  <nickc@redhat.com>
 
 	* po/ru.po: Updated Russian translation.
diff --git a/gas/testsuite/gas/mips/mips.exp b/gas/testsuite/gas/mips/mips.exp
index 74c39d4..d119138 100644
--- a/gas/testsuite/gas/mips/mips.exp
+++ b/gas/testsuite/gas/mips/mips.exp
@@ -1494,6 +1494,10 @@ if { [istarget mips*-*-vxworks*] } {
     run_dump_test "pr12915"
     run_dump_test "reginfo-1a"
     run_dump_test "reginfo-1b"
+    run_dump_test "reginfo-2"
+    if $has_newabi {
+	run_dump_test "reginfo-2-n32"
+    }
 
     run_dump_test "micromips"
     run_dump_test "micromips-trap"
diff --git a/gas/testsuite/gas/mips/reginfo-2-n32.d b/gas/testsuite/gas/mips/reginfo-2-n32.d
new file mode 100644
index 0000000..ec1f9e3
--- /dev/null
+++ b/gas/testsuite/gas/mips/reginfo-2-n32.d
@@ -0,0 +1,4 @@
+#name: MIPS assembled .reginfo section size (n32)
+#as: -n32 -mips3
+#source: reginfo-2.s
+#error-output: reginfo-2.l
diff --git a/gas/testsuite/gas/mips/reginfo-2.d b/gas/testsuite/gas/mips/reginfo-2.d
new file mode 100644
index 0000000..7bfe7f9
--- /dev/null
+++ b/gas/testsuite/gas/mips/reginfo-2.d
@@ -0,0 +1,3 @@
+#name: MIPS assembled .reginfo section size
+#as: -32
+#error-output: reginfo-2.l
diff --git a/gas/testsuite/gas/mips/reginfo-2.l b/gas/testsuite/gas/mips/reginfo-2.l
new file mode 100644
index 0000000..ea9fef9
--- /dev/null
+++ b/gas/testsuite/gas/mips/reginfo-2.l
@@ -0,0 +1,3 @@
+.*: Incorrect `\.reginfo' section size; expected 24, got 28
+.*: Assembler messages:
+.*: Fatal error: can't close .*: Bad value
diff --git a/gas/testsuite/gas/mips/reginfo-2.s b/gas/testsuite/gas/mips/reginfo-2.s
new file mode 100644
index 0000000..7471062
--- /dev/null
+++ b/gas/testsuite/gas/mips/reginfo-2.s
@@ -0,0 +1,2 @@
+	.section .reginfo
+	.word	0xdeadbeef


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]