binutils/testsuite: Verify the handling of invalid `r_sym' in relocation
authorMaciej W. Rozycki <macro@mips.com>
Mon, 9 Apr 2018 12:42:00 +0000 (13:42 +0100)
committerMaciej W. Rozycki <macro@mips.com>
Mon, 9 Apr 2018 12:42:00 +0000 (13:42 +0100)
Verify that `strip' terminates gracefully and a correct error message is
produced for a relocation encountered with an invalid symbol index.  No
single relocation number is valid across all targets we support, so pick
a few numbers to choose from depending on the target.

binutils/
* testsuite/binutils-all/strip-14.d: New test.
* testsuite/binutils-all/strip-14rel.s: New test source.
* testsuite/binutils-all/strip-14rela.s: New test source.
* testsuite/binutils-all/strip-14mips64.s: New test source.
* testsuite/binutils-all/objcopy.exp: Run the new test.

binutils/ChangeLog
binutils/testsuite/binutils-all/objcopy.exp
binutils/testsuite/binutils-all/strip-14.d [new file with mode: 0644]
binutils/testsuite/binutils-all/strip-14mips64.s [new file with mode: 0644]
binutils/testsuite/binutils-all/strip-14rel.s [new file with mode: 0644]
binutils/testsuite/binutils-all/strip-14rela.s [new file with mode: 0644]

index a6b8c95d9faf64d62940e832d3942744dde6d8b0..0c1b95d21bc05460da205e5b54685ca3b31c4c3c 100644 (file)
@@ -1,3 +1,11 @@
+2018-04-09  Maciej W. Rozycki  <macro@mips.com>
+
+       * testsuite/binutils-all/strip-14.d: New test.
+       * testsuite/binutils-all/strip-14rel.s: New test source.
+       * testsuite/binutils-all/strip-14rela.s: New test source.
+       * testsuite/binutils-all/strip-14mips64.s: New test source.
+       * testsuite/binutils-all/objcopy.exp: Run the new test.
+
 2018-04-06  Tom Tromey  <tom@tromey.com>
 
        * dwarf.c (read_and_display_attr_value): Add missing DW_LANG
index 0639fe5bf98297302b8342fc9872bca9c37dbcbf..532bdc6ac76bf891b9a4c2c6ba1a01a6c9c5adfa 100644 (file)
@@ -1107,6 +1107,22 @@ if [is_elf_format] {
        set reloc_format rela
     }
     run_dump_test "strip-13" [list [list source strip-13${reloc_format}.s]]
+    # Select a relocation number that corresponds to one actually
+    # supported by the target and ABI being tested.
+    if { [istarget "aarch64*-*"] } {
+       set reloc 259
+    } elseif { [istarget "ia64*-*"] \
+              || [istarget "m32r*-*"] \
+              || [istarget "v850*-*"] } {
+       set reloc 50
+    } else {
+       set reloc 1
+    }
+    run_dump_test "strip-14" [list \
+                               [list source strip-14${reloc_format}.s] \
+                               [list as "--defsym RELOC=${reloc}"] \
+                               [list as [expr {[is_elf64 tmpdir/bintest.o] \
+                                   ? "--defsym ELF64=1" : ""}]]]
 
     # This requires STB_GNU_UNIQUE support with OSABI set to GNU.
     if { [supports_gnu_unique] } {
diff --git a/binutils/testsuite/binutils-all/strip-14.d b/binutils/testsuite/binutils-all/strip-14.d
new file mode 100644 (file)
index 0000000..e2ce251
--- /dev/null
@@ -0,0 +1,7 @@
+#PROG: strip
+#strip: -g
+#error: \A[^\n]*: relocation 0 has invalid symbol index 1048560\Z
+#not-target: rx-*
+# The RX targets do not complain about bad relocs, unless they are
+#  actually used
+#  (which is what should really happen with the other targets...)
diff --git a/binutils/testsuite/binutils-all/strip-14mips64.s b/binutils/testsuite/binutils-all/strip-14mips64.s
new file mode 100644 (file)
index 0000000..723da8d
--- /dev/null
@@ -0,0 +1,14 @@
+       .text
+foo:
+       .dc.l    0x12345678
+
+       .section .rela.text
+       .dc.a    0
+       .dc.l    0x000ffff0
+       .dc.b    0, 0, 0, RELOC
+       .dc.a    0x00000001
+
+       .dc.a    0
+       .dc.l    0
+       .dc.b    0, 0, 0, 0
+       .dc.a    0
diff --git a/binutils/testsuite/binutils-all/strip-14rel.s b/binutils/testsuite/binutils-all/strip-14rel.s
new file mode 100644 (file)
index 0000000..b0ddc49
--- /dev/null
@@ -0,0 +1,23 @@
+       .text
+foo:
+       .dc.l    0x12345678
+
+       .section .rel.text
+       .ifdef   ELF64
+
+       .dc.a    0
+       .dc.a    0x000ffff000000000 + RELOC
+
+       .dc.a    0
+       .dc.a    0
+       .else
+
+       # Some targets, such as `m68hc11-*', use 16-bit addresses.
+       # With them `.dc.a' emits 16-bit quantities, so we need to use
+       # `.dc.l' for 32-bit relocation data.
+       .dc.l    0
+       .dc.l    0x0ffff000 + RELOC
+
+       .dc.l    0
+       .dc.l    0
+       .endif
diff --git a/binutils/testsuite/binutils-all/strip-14rela.s b/binutils/testsuite/binutils-all/strip-14rela.s
new file mode 100644 (file)
index 0000000..414d303
--- /dev/null
@@ -0,0 +1,27 @@
+       .text
+foo:
+       .dc.l    0x12345678
+
+       .section .rela.text
+       .ifdef   ELF64
+
+       .dc.a    0
+       .dc.a    0x000ffff000000000 + RELOC
+       .dc.a    0x0000000000000001
+
+       .dc.a    0
+       .dc.a    0
+       .dc.a    0
+       .else
+
+       # Some targets, such as `h8300-*' or `ip2k-*', use 16-bit addresses.
+       # With them `.dc.a' emits 16-bit quantities, so we need to use
+       # `.dc.l' for 32-bit relocation data.
+       .dc.l    0
+       .dc.l    0x0ffff000 + RELOC
+       .dc.l    0x00000001
+
+       .dc.l    0
+       .dc.l    0
+       .dc.l    0
+       .endif