binutils testsuite strip-13 test
authorAlan Modra <amodra@gmail.com>
Mon, 13 Aug 2018 04:11:18 +0000 (13:41 +0930)
committerAlan Modra <amodra@gmail.com>
Sat, 18 Aug 2018 04:16:32 +0000 (13:46 +0930)
The strip-13 test runs into difficulty using dc.a on some targets.
dc.a writes a power of 2 number of bytes large enough to contain a
target address.  On some targets, eg. avr-elf, this can be 2 bytes but
the ELF format used require words of 4 bytes to make up a relocation
entry.  There was a hack in the test, duplicating the reloc type into
what is normally the addend to make the test work when little-endian,
but that hack fails for similar big-endian targets.

This patch fixes that problem by arranging to emit 32-bit and 64-bit
ELF relocs using .4byte and .8byte directives, chosen as appropriate
for the ELF size.  I've also bumped the reloc number tested to a
higher unused value, and made the number more easily parameterised by
target should that be necessary in the future.  Whether REL or RELA
relocs are used is now chosen by a new is_rela readelf test of an
object file, rather than by lists of targets.

* testsuite/lib/binutils-common.exp (is_elf64): Use directory of
input file for readelf.out.
(is_rela): New proc.
* testsuite/binutils-all/objcopy.exp (elf64): Set new variable
from first result of is_elf64 test.
(reloc_format): Set using is_rela.
(strip-13): Pass RELOC and ELF64 to assembler.
(strip-14, strip-15): Use elf64 rather than calling is_elf64 again.
* testsuite/binutils-all/strip-13.d: Run for more targets.
* testsuite/binutils-all/strip-13mips64.s: Use RELOC and set
addend to zero.
* testsuite/binutils-all/strip-13rel.s: Use RELOC and ELF64.
Don't add _NONE reloc.
* testsuite/binutils-all/strip-13rela.s: Likewise.

binutils/ChangeLog
binutils/testsuite/binutils-all/objcopy.exp
binutils/testsuite/binutils-all/strip-13.d
binutils/testsuite/binutils-all/strip-13mips64.s
binutils/testsuite/binutils-all/strip-13rel.s
binutils/testsuite/binutils-all/strip-13rela.s
binutils/testsuite/lib/binutils-common.exp

index 071a005134b9ee6fb696e3fc57308f4c13884780..265bd68fc5360898adc831db001f2e143f244669 100644 (file)
@@ -1,3 +1,20 @@
+2018-08-18  Alan Modra  <amodra@gmail.com>
+
+       * testsuite/lib/binutils-common.exp (is_elf64): Use directory of
+       input file for readelf.out.
+       (is_rela): New proc.
+       * testsuite/binutils-all/objcopy.exp (elf64): Set new variable
+       from first result of is_elf64 test.
+       (reloc_format): Set using is_rela.
+       (strip-13): Pass RELOC and ELF64 to assembler.
+       (strip-14, strip-15): Use elf64 rather than calling is_elf64 again.
+       * testsuite/binutils-all/strip-13.d: Run for more targets.
+       * testsuite/binutils-all/strip-13mips64.s: Use RELOC and set
+       addend to zero.
+       * testsuite/binutils-all/strip-13rel.s: Use RELOC and ELF64.
+       Don't add _NONE reloc.
+       * testsuite/binutils-all/strip-13rela.s: Likewise.
+
 2018-08-10  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR binutils/23494
index 8d8b39909eb8e17a091d05a31b492b3946ae4375..342585f36280df34bbba87f91135db011ae990b0 100644 (file)
@@ -1033,6 +1033,7 @@ if { ([istarget "ia64-*-elf*"]
 }
 
 # ELF specific tests
+set elf64 ""
 if [is_elf_format] {
     objcopy_test_symbol_manipulation
     objcopy_test_elf_common_symbols
@@ -1049,7 +1050,9 @@ if [is_elf_format] {
     run_dump_test "group-7c"
     run_dump_test "copy-1"
     run_dump_test "note-1"
+    # Use bintest.o from the note-1 test to determine ELF32 or ELF64
     if [is_elf64 tmpdir/bintest.o] {
+       set elf64 "--defsym ELF64=1"
        run_dump_test "note-2-64"
        run_dump_test "note-3-64"
        run_dump_test "note-4-64"
@@ -1064,6 +1067,11 @@ if [is_elf_format] {
 run_dump_test "copy-2"
 run_dump_test "copy-3"
 run_dump_test "copy-4"
+# Use bintest.o from the copy-4 test to determine ELF reloc type
+set reloc_format rel
+if { [is_elf_format] && [is_rela tmpdir/bintest.o] } {
+    set reloc_format rela
+}
 run_dump_test "pr19020a"
 run_dump_test "pr19020b"
 
@@ -1081,27 +1089,12 @@ if [is_elf_format] {
 
     if { [istarget "mips64*-*-openbsd*"] } {
        set reloc_format mips64
-    } elseif { ([istarget "arm*-*"] \
-               && ![istarget "*-*-vxworks"] \
-               && ![istarget "*-*-windiss"]) \
-              || [istarget "d10v-*"] \
-              || [istarget "dlx-*"] \
-              || [istarget "i*86-*"] \
-              || [istarget "m681*-*"] \
-              || [istarget "m68hc1*-*"] \
-              || ([istarget "mips*-*"] \
-                  && ![istarget "mips64*-ps2-elf*"] \
-                  && ![istarget "*-*-irix6*"] \
-                  && ![istarget "mips64*-*-freebsd*"] \
-                  && ![istarget "mips64*-*-kfreebsd*-gnu"] \
-                  && ![istarget "mips64*-*-linux*"]) \
-              || [istarget "score*-*"] \
-              || [istarget "xgate-*"] } {
-       set reloc_format rel
-    } else {
-       set reloc_format rela
     }
-    run_dump_test "strip-13" [list [list source strip-13${reloc_format}.s]]
+    # A relocation type not supported by any target
+    set reloc 215
+    run_dump_test "strip-13" [list \
+                                 [list source strip-13${reloc_format}.s] \
+                                 [list as "${elf64} --defsym RELOC=${reloc}"]]
     # Select a relocation number that corresponds to one actually
     # supported by the target and ABI being tested.
     if { [istarget "aarch64*-*"] } {
@@ -1117,15 +1110,11 @@ if [is_elf_format] {
        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" : ""}]]]
+                                 [list source strip-14${reloc_format}.s] \
+                                 [list as "${elf64} --defsym RELOC=${reloc}"]]
     run_dump_test "strip-15" [list \
-                               [list source strip-15${reloc_format}.s] \
-                               [list as "--defsym RELOC=${reloc}"] \
-                               [list as [expr {[is_elf64 tmpdir/bintest.o] \
-                                   ? "--defsym ELF64=1" : ""}]]]
+                                 [list source strip-15${reloc_format}.s] \
+                                 [list as "${elf64} --defsym RELOC=${reloc}"]]
 
     # This requires STB_GNU_UNIQUE support with OSABI set to GNU.
     if { [supports_gnu_unique] } {
index 0ccb73ef448e567652899a72439a00cbfac39fad..05d21ecb39e3f03ad5273ac9e5dee18780685c42 100644 (file)
@@ -1,10 +1,8 @@
 #PROG: strip
 #strip: -g
-#error: \A[^\n]*: unsupported relocation type 0x8f\n
+#error: \A[^\n]*: unsupported relocation type 0x[0-9a-f]+\n
 #error:   [^\n]*: bad value\Z
-#not-target: h8300-* ip2k-* m6811-* m68hc11-* rx-*
-# The H8300-*, IP2K and 68HC11 targets use 16-bit addressing, so `.dc.a'
-#  does not work for manual relocation data construction.
+#not-target: rx-*
 # The RX targets do not complain about unrecognised relocs, unless they
 #  are actually used
 #  (which is what should really happen with the other targets...)
index cee9c755955c6e30019ca93b9f466aae966581c9..ea652a47d76bdaac26ba6a68014264ecdb6aff72 100644 (file)
@@ -5,8 +5,8 @@ foo:
        .section .rela.text
        .dc.a    0
        .dc.l    0
-       .dc.b    0, 0, 0, 0x8f
-       .dc.a    0x0000008f
+       .dc.b    0, 0, 0, RELOC
+       .dc.a    0
 
        .dc.a    0
        .dc.l    0
index de7eae1e3426fdf0bfa56f6e515840789997b94e..f708f6f43235d01e53af6dad6a8cad45308cff84 100644 (file)
@@ -3,8 +3,10 @@ foo:
        .dc.l    0x12345678
 
        .section .rel.text
-       .dc.a    0
-       .dc.a    0x0000008f
-
-       .dc.a    0
-       .dc.a    0
+ .ifdef ELF64
+       .8byte  0
+       .8byte  RELOC
+ .else
+       .4byte  0
+       .4byte  RELOC
+ .endif
index 886c0ee6f1c4018a9ffbdfa2e2fd5e73f7109d55..2c01ab2a99fec3f808d06663ff78a1bdffba105f 100644 (file)
@@ -3,10 +3,12 @@ foo:
        .dc.l    0x12345678
 
        .section .rela.text
-       .dc.a    0
-       .dc.a    0x0000008f
-       .dc.a    0x0000008f
-
-       .dc.a    0
-       .dc.a    0
-       .dc.a    0
+ .ifdef ELF64
+       .8byte  0
+       .8byte  RELOC
+       .8byte  0
+ .else
+       .4byte  0
+       .4byte  RELOC
+       .4byte  0
+ .endif
index 7de7d6796a5c4107cef6b28e57f18d4d56ca71e6..b1ede4cdf60607c09b62862e0e280565023a5acc 100644 (file)
@@ -111,15 +111,16 @@ proc is_elf64 { binary_file } {
     global READELF
     global READELFFLAGS
 
+    set tmpfile [file dirname $binary_file]/readelf.out
     set readelf_size ""
-    catch "exec $READELF $READELFFLAGS -h $binary_file > readelf.out" got
+    catch "exec $READELF $READELFFLAGS -h $binary_file > $tmpfile" got
 
     if ![string match "" $got] then {
        return 0
     }
 
     if { ![regexp "\n\[ \]*Class:\[ \]*ELF(\[0-9\]+)\n" \
-          [file_contents readelf.out] nil readelf_size] } {
+          [file_contents $tmpfile] nil readelf_size] } {
        return 0
     }
 
@@ -130,6 +131,26 @@ proc is_elf64 { binary_file } {
     return 0
 }
 
+# True if the object format is known to use RELA relocations.
+#
+proc is_rela { binary_file } {
+    global READELF
+    global READELFFLAGS
+
+    set tmpfile [file dirname $binary_file]/readelf.out
+    catch "exec $READELF $READELFFLAGS -S $binary_file > $tmpfile" got
+
+    if ![string match "" $got] then {
+       return 0
+    }
+
+    if { ![regexp "RELA" [file_contents $tmpfile]] } {
+       return 0
+    }
+
+    return 1
+}
+
 # True if the target matches TARGET, specified as a TCL procedure if
 # in square brackets or as machine triplet otherwise.
 #
This page took 0.125825 seconds and 4 git commands to generate.