[3/3] MIPS/BFD: Correctly report unsupported `.reginfo' section size

Message ID alpine.DEB.2.00.1802020122560.3553@tp.orcam.me.uk
State New
Headers show
Series
  • MIPS: Correctly report unsupported `.reginfo' section size in GAS/objcopy
Related show

Commit Message

Maciej W. Rozycki Feb. 2, 2018, 5:23 p.m.
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.
---
Hi,

 No regressions in MIPS testing.  I will commit this change once 1/3 and 
2/3 have been approved.

  Maciej
---
 bfd/elfxx-mips.c                                        |   11 ++++++++++-
 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/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 ++
 10 files changed, 46 insertions(+), 1 deletion(-)

binutils-mips-bfd-section-processing-reginfo.diff

Patch

Index: binutils/bfd/elfxx-mips.c
===================================================================
--- binutils.orig/bfd/elfxx-mips.c	2018-02-01 01:35:27.412907488 +0000
+++ binutils/bfd/elfxx-mips.c	2018-02-01 18:44:58.542838628 +0000
@@ -7102,9 +7102,18 @@  _bfd_mips_elf_section_processing (bfd *a
     {
       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)
Index: binutils/binutils/testsuite/binutils-all/mips/mips-reginfo-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/binutils/testsuite/binutils-all/mips/mips-reginfo-n32.d	2018-02-01 18:45:02.961380617 +0000
@@ -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
Index: binutils/binutils/testsuite/binutils-all/mips/mips-reginfo.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/binutils/testsuite/binutils-all/mips/mips-reginfo.d	2018-02-01 18:45:02.972457474 +0000
@@ -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
Index: binutils/binutils/testsuite/binutils-all/mips/mips-reginfo.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/binutils/testsuite/binutils-all/mips/mips-reginfo.s	2018-02-01 18:45:02.989670004 +0000
@@ -0,0 +1,2 @@ 
+	.section .foo, "a"
+	.word	0xdeadbeef
Index: binutils/binutils/testsuite/binutils-all/mips/mips.exp
===================================================================
--- binutils.orig/binutils/testsuite/binutils-all/mips/mips.exp	2018-02-01 18:44:49.196620660 +0000
+++ binutils/binutils/testsuite/binutils-all/mips/mips.exp	2018-02-01 18:45:03.005798507 +0000
@@ -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"
+}
Index: binutils/gas/testsuite/gas/mips/mips.exp
===================================================================
--- binutils.orig/gas/testsuite/gas/mips/mips.exp	2018-02-01 18:44:49.218808856 +0000
+++ binutils/gas/testsuite/gas/mips/mips.exp	2018-02-01 18:45:03.042310951 +0000
@@ -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"
Index: binutils/gas/testsuite/gas/mips/reginfo-2-n32.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/reginfo-2-n32.d	2018-02-01 18:45:03.082144038 +0000
@@ -0,0 +1,4 @@ 
+#name: MIPS assembled .reginfo section size (n32)
+#as: -n32 -mips3
+#source: reginfo-2.s
+#error-output: reginfo-2.l
Index: binutils/gas/testsuite/gas/mips/reginfo-2.d
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/reginfo-2.d	2018-02-01 18:45:03.102668779 +0000
@@ -0,0 +1,3 @@ 
+#name: MIPS assembled .reginfo section size
+#as: -32
+#error-output: reginfo-2.l
Index: binutils/gas/testsuite/gas/mips/reginfo-2.l
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/reginfo-2.l	2018-02-01 18:45:03.127250263 +0000
@@ -0,0 +1,3 @@ 
+.*: Incorrect `\.reginfo' section size; expected 24, got 28
+.*: Assembler messages:
+.*: Fatal error: can't close .*: Bad value
Index: binutils/gas/testsuite/gas/mips/reginfo-2.s
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ binutils/gas/testsuite/gas/mips/reginfo-2.s	2018-02-01 18:45:03.140634839 +0000
@@ -0,0 +1,2 @@ 
+	.section .reginfo
+	.word	0xdeadbeef