Skip to content
This repository was archived by the owner on Aug 17, 2022. It is now read-only.

Commit 2d6dda7

Browse files
author
Maciej W. Rozycki
committed
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.
1 parent 7550610 commit 2d6dda7

File tree

13 files changed

+67
-1
lines changed

13 files changed

+67
-1
lines changed

bfd/ChangeLog

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
2018-02-05 Maciej W. Rozycki <[email protected]>
2+
3+
* elfxx-mips.c (_bfd_mips_elf_section_processing): For
4+
SHT_MIPS_REGINFO sections don't assert the correct size and
5+
report an error instead.
6+
17
2018-02-05 Maciej W. Rozycki <[email protected]>
28

39
* elf.c (_bfd_elf_write_object_contents): Propagate a failure

bfd/elfxx-mips.c

+10-1
Original file line numberDiff line numberDiff line change
@@ -7102,9 +7102,18 @@ _bfd_mips_elf_section_processing (bfd *abfd, Elf_Internal_Shdr *hdr)
71027102
{
71037103
bfd_byte buf[4];
71047104

7105-
BFD_ASSERT (hdr->sh_size == sizeof (Elf32_External_RegInfo));
71067105
BFD_ASSERT (hdr->contents == NULL);
71077106

7107+
if (hdr->sh_size != sizeof (Elf32_External_RegInfo))
7108+
{
7109+
_bfd_error_handler
7110+
(_("%B: Incorrect `.reginfo' section size; expected %Lu, got %Lu"),
7111+
abfd, (bfd_size_type) sizeof (Elf32_External_RegInfo),
7112+
hdr->sh_size);
7113+
bfd_set_error (bfd_error_bad_value);
7114+
return FALSE;
7115+
}
7116+
71087117
if (bfd_seek (abfd,
71097118
hdr->sh_offset + sizeof (Elf32_External_RegInfo) - 4,
71107119
SEEK_SET) != 0)

binutils/ChangeLog

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
2018-02-05 Maciej W. Rozycki <[email protected]>
2+
3+
* testsuite/binutils-all/mips/mips-reginfo.d: New test.
4+
* testsuite/binutils-all/mips/mips-reginfo-n32.d: New test.
5+
* testsuite/binutils-all/mips/mips-reginfo.s: New test source.
6+
* testsuite/binutils-all/mips/mips.exp: Run the new tests.
7+
18
2018-02-05 Maciej W. Rozycki <[email protected]>
29

310
* testsuite/config/default.exp (binutils_run): Document
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#PROG: objcopy
2+
#name: MIPS objcopy .reginfo section size (n32)
3+
#as: -n32 -mips3
4+
#objcopy: --rename-section .foo=.reginfo
5+
#source: mips-reginfo.s
6+
#error: \A[^\n]*: Incorrect `\.reginfo' section size; expected 24, got 4\n
7+
#error: [^\n]*: Bad value\Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#PROG: objcopy
2+
#name: MIPS objcopy .reginfo section size
3+
#as: -32
4+
#objcopy: --rename-section .foo=.reginfo
5+
#error: \A[^\n]*: Incorrect `\.reginfo' section size; expected 24, got 4\n
6+
#error: [^\n]*: Bad value\Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.section .foo, "a"
2+
.word 0xdeadbeef

binutils/testsuite/binutils-all/mips/mips.exp

+5
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,8 @@ if $has_newabi {
6060
run_dump_test "mips-note-2r-n32"
6161
run_dump_test "mips-note-2r-n64"
6262
}
63+
64+
run_dump_test "mips-reginfo"
65+
if $has_newabi {
66+
run_dump_test "mips-reginfo-n32"
67+
}

gas/ChangeLog

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
2018-02-05 Maciej W. Rozycki <[email protected]>
2+
3+
* testsuite/gas/mips/reginfo-2.d: New test.
4+
* testsuite/gas/mips/reginfo-2-n32.d: New test.
5+
* testsuite/gas/mips/reginfo-2.l: New test stderr output.
6+
* testsuite/gas/mips/reginfo-2.s: New test source.
7+
* testsuite/gas/mips/mips.exp: Run the new tests.
8+
19
2018-02-05 Nick Clifton <[email protected]>
210

311
* po/ru.po: Updated Russian translation.

gas/testsuite/gas/mips/mips.exp

+4
Original file line numberDiff line numberDiff line change
@@ -1494,6 +1494,10 @@ if { [istarget mips*-*-vxworks*] } {
14941494
run_dump_test "pr12915"
14951495
run_dump_test "reginfo-1a"
14961496
run_dump_test "reginfo-1b"
1497+
run_dump_test "reginfo-2"
1498+
if $has_newabi {
1499+
run_dump_test "reginfo-2-n32"
1500+
}
14971501

14981502
run_dump_test "micromips"
14991503
run_dump_test "micromips-trap"
+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#name: MIPS assembled .reginfo section size (n32)
2+
#as: -n32 -mips3
3+
#source: reginfo-2.s
4+
#error-output: reginfo-2.l

gas/testsuite/gas/mips/reginfo-2.d

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#name: MIPS assembled .reginfo section size
2+
#as: -32
3+
#error-output: reginfo-2.l

gas/testsuite/gas/mips/reginfo-2.l

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.*: Incorrect `\.reginfo' section size; expected 24, got 28
2+
.*: Assembler messages:
3+
.*: Fatal error: can't close .*: Bad value

gas/testsuite/gas/mips/reginfo-2.s

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
.section .reginfo
2+
.word 0xdeadbeef

0 commit comments

Comments
 (0)