6cffa7
diff -rup binutils.orig/bfd/elf32-i386.c binutils-2.30/bfd/elf32-i386.c
6cffa7
--- binutils.orig/bfd/elf32-i386.c	2018-02-27 17:25:53.961140597 +0000
6cffa7
+++ binutils-2.30/bfd/elf32-i386.c	2018-02-27 17:27:14.115133477 +0000
6cffa7
@@ -383,7 +383,7 @@ elf_i386_rtype_to_howto (bfd *abfd, unsi
6cffa7
     {
6cffa7
       (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
6cffa7
 			     abfd, (int) r_type);
6cffa7
-      indx = R_386_NONE;
6cffa7
+      return NULL;
6cffa7
     }
6cffa7
   /* PR 17512: file: 0f67f69d.  */
6cffa7
   if (elf_howto_table [indx].type != r_type)
6cffa7
diff -rup binutils.orig/bfd/elf64-ppc.c binutils-2.30/bfd/elf64-ppc.c
6cffa7
--- binutils.orig/bfd/elf64-ppc.c	2018-02-27 17:25:53.969140496 +0000
6cffa7
+++ binutils-2.30/bfd/elf64-ppc.c	2018-02-27 17:27:56.213604518 +0000
6cffa7
@@ -2516,9 +2516,12 @@ ppc64_elf_info_to_howto (bfd *abfd, arel
6cffa7
     {
6cffa7
       (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
6cffa7
 			     abfd, (int) type);
6cffa7
-      type = R_PPC64_NONE;
6cffa7
+      cache_ptr->howto = NULL;
6cffa7
     }
6cffa7
-  cache_ptr->howto = ppc64_elf_howto_table[type];
6cffa7
+  else
6cffa7
+    cache_ptr->howto = ppc64_elf_howto_table[type];
6cffa7
+  if (cache_ptr->howto == NULL || cache_ptr->howto->name == NULL)
6cffa7
+    _bfd_error_handler (_("%B: invalid relocation type %d"), abfd, type);
6cffa7
 }
6cffa7
 
6cffa7
 /* Handle the R_PPC64_ADDR16_HA and similar relocs.  */
6cffa7
diff -rup binutils.orig/bfd/elf64-s390.c binutils-2.30/bfd/elf64-s390.c
6cffa7
--- binutils.orig/bfd/elf64-s390.c	2018-02-27 17:25:53.968140509 +0000
6cffa7
+++ binutils-2.30/bfd/elf64-s390.c	2018-02-27 17:28:24.632247443 +0000
6cffa7
@@ -372,9 +372,10 @@ elf_s390_info_to_howto (bfd *abfd ATTRIB
6cffa7
 	{
6cffa7
 	  (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
6cffa7
 				 abfd, (int) r_type);
6cffa7
-	  r_type = R_390_NONE;
6cffa7
+	  cache_ptr->howto = NULL;
6cffa7
 	}
6cffa7
-      cache_ptr->howto = &elf_howto_table[r_type];
6cffa7
+      else
6cffa7
+	cache_ptr->howto = &elf_howto_table[r_type];
6cffa7
     }
6cffa7
 }
6cffa7
 
6cffa7
diff -rup binutils.orig/bfd/elf64-x86-64.c binutils-2.30/bfd/elf64-x86-64.c
6cffa7
--- binutils.orig/bfd/elf64-x86-64.c	2018-02-27 17:25:53.964140559 +0000
6cffa7
+++ binutils-2.30/bfd/elf64-x86-64.c	2018-02-27 17:29:12.554645307 +0000
6cffa7
@@ -284,7 +284,7 @@ elf_x86_64_rtype_to_howto (bfd *abfd, un
6cffa7
 	{
6cffa7
 	  (*_bfd_error_handler) (_("%B: invalid relocation type %d"),
6cffa7
 				 abfd, (int) r_type);
6cffa7
-	  r_type = R_X86_64_NONE;
6cffa7
+	  return NULL;
6cffa7
 	}
6cffa7
       i = r_type;
6cffa7
     }
6cffa7
@@ -347,7 +347,6 @@ elf_x86_64_info_to_howto (bfd *abfd ATTR
6cffa7
 
6cffa7
   r_type = ELF32_R_TYPE (dst->r_info);
6cffa7
   cache_ptr->howto = elf_x86_64_rtype_to_howto (abfd, r_type);
6cffa7
-  BFD_ASSERT (r_type == cache_ptr->howto->type);
6cffa7
 }
6cffa7
 
6cffa7
 /* Support for core dump NOTE sections.  */
6cffa7
diff -rup binutils.orig/bfd/elfcode.h binutils-2.30/bfd/elfcode.h
6cffa7
--- binutils.orig/bfd/elfcode.h	2018-02-27 17:25:53.964140559 +0000
6cffa7
+++ binutils-2.30/bfd/elfcode.h	2018-02-27 17:26:57.234345581 +0000
6cffa7
@@ -1474,6 +1474,12 @@ elf_slurp_reloc_table_from_section (bfd
6cffa7
 	(*ebd->elf_info_to_howto) (abfd, relent, &rela);
6cffa7
       else
6cffa7
 	(*ebd->elf_info_to_howto_rel) (abfd, relent, &rela);
6cffa7
+
6cffa7
+      if (relent->howto == NULL)
6cffa7
+	{
6cffa7
+	  bfd_set_error (bfd_error_bad_value);
6cffa7
+	  goto error_return;
6cffa7
+	}
6cffa7
     }
6cffa7
 
6cffa7
   if (allocated != NULL)
6cffa7
diff -rup binutils.orig/binutils/objcopy.c binutils-2.30/binutils/objcopy.c
6cffa7
--- binutils.orig/binutils/objcopy.c	2018-02-27 17:25:53.185150347 +0000
6cffa7
+++ binutils-2.30/binutils/objcopy.c	2018-02-27 17:30:05.806976202 +0000
6cffa7
@@ -3022,10 +3022,19 @@ copy_object (bfd *ibfd, bfd *obfd, const
6cffa7
 	 haven't been set yet.  mark_symbols_used_in_relocations will
6cffa7
 	 ignore input sections which have no corresponding output
6cffa7
 	 section.  */
6cffa7
+      bfd_set_error (bfd_error_no_error);
6cffa7
       if (strip_symbols != STRIP_ALL)
6cffa7
-	bfd_map_over_sections (ibfd,
6cffa7
-			       mark_symbols_used_in_relocations,
6cffa7
-			       isympp);
6cffa7
+	{
6cffa7
+	  bfd_map_over_sections (ibfd,
6cffa7
+				 mark_symbols_used_in_relocations,
6cffa7
+				 isympp);
6cffa7
+	  if (bfd_get_error () != bfd_error_no_error)
6cffa7
+	    {
6cffa7
+	      status = 1;
6cffa7
+	      return FALSE;
6cffa7
+	    }
6cffa7
+	}
6cffa7
+
6cffa7
       osympp = (asymbol **) xmalloc ((symcount + add_symbols + 1) * sizeof (asymbol *));
6cffa7
       symcount = filter_symbols (ibfd, obfd, osympp, isympp, symcount);
6cffa7
     }
6cffa7
diff -rup binutils.orig/binutils/testsuite/binutils-all/objcopy.exp binutils-2.27/binutils/testsuite/binutils-all/objcopy.exp
6cffa7
--- binutils.orig/binutils/testsuite/binutils-all/objcopy.exp	2018-04-11 12:34:04.671683298 +0100
6cffa7
+++ binutils-2.27/binutils/testsuite/binutils-all/objcopy.exp	2018-04-11 12:36:50.053734109 +0100
6cffa7
@@ -1083,6 +1083,29 @@ if [is_elf_format] {
6cffa7
     }
6cffa7
     run_dump_test "strip-11" $extra_strip11
6cffa7
 
6cffa7
+    if { [istarget "mips64*-*-openbsd*"] } {
6cffa7
+	set reloc_format mips64
6cffa7
+    } elseif { [istarget "arm-*"] \
6cffa7
+	       || [istarget "d10v-*"] \
6cffa7
+	       || [istarget "dlx-*"] \
6cffa7
+	       || [istarget "i*86-*"] \
6cffa7
+	       || [istarget "i960-*"] \
6cffa7
+	       || [istarget "m681*-*"] \
6cffa7
+	       || [istarget "m68hc1*-*"] \
6cffa7
+	       || ([istarget "mips*-*"] \
6cffa7
+		   && ![istarget "mips64*-ps2-elf*"] \
6cffa7
+		   && ![istarget "*-*-irix6*"] \
6cffa7
+		   && ![istarget "mips64*-*-freebsd*"] \
6cffa7
+		   && ![istarget "mips64*-*-kfreebsd*-gnu"] \
6cffa7
+		   && ![istarget "mips64*-*-linux*"]) \
6cffa7
+	       || [istarget "score*-*"] \
6cffa7
+	       || [istarget "xgate-*"] } {
6cffa7
+	set reloc_format rel
6cffa7
+    } else {
6cffa7
+	set reloc_format rela
6cffa7
+    }
6cffa7
+    run_dump_test "strip-13" [list [list source strip-13${reloc_format}.s]]
6cffa7
+    
6cffa7
     if { [istarget "i*86-*"] || [istarget "x86_64-*-*"] } {
6cffa7
 	# Check to make sure we don't strip a symbol named in relocations.
6cffa7
 	set test "objcopy keeps symbols needed by relocs"
6cffa7
diff -rup binutils.orig/binutils/testsuite/lib/utils-lib.exp binutils-2.27/binutils/testsuite/lib/utils-lib.exp
6cffa7
--- binutils.orig/binutils/testsuite/lib/utils-lib.exp	2018-04-11 12:34:04.674683263 +0100
6cffa7
+++ binutils-2.27/binutils/testsuite/lib/utils-lib.exp	2018-04-11 12:54:56.097850613 +0100
6cffa7
@@ -1,4 +1,4 @@
6cffa7
-# Copyright (C) 1993-2016 Free Software Foundation, Inc.
6cffa7
+# Copyright (C) 1993-2018 Free Software Foundation, Inc.
6cffa7
 
6cffa7
 # This program is free software; you can redistribute it and/or modify
6cffa7
 # it under the terms of the GNU General Public License as published by
6cffa7
@@ -51,12 +51,17 @@ proc binutil_version { prog } {
6cffa7
 # default_binutils_run
6cffa7
 #	run a program, returning the output
6cffa7
 #	sets binutils_run_failed if the program does not exist
6cffa7
+#	sets binutils_run_status to the exit status of the program
6cffa7
 #
6cffa7
 proc default_binutils_run { prog progargs } {
6cffa7
     global binutils_run_failed
6cffa7
+    global binutils_run_status
6cffa7
     global host_triplet
6cffa7
 
6cffa7
     set binutils_run_failed 0
6cffa7
+    if [info exists binutils_run_status] {
6cffa7
+	unset binutils_run_status
6cffa7
+    }
6cffa7
 
6cffa7
     if ![is_remote host] {
6cffa7
 	if {[which $prog] == 0} then {
6cffa7
@@ -83,6 +88,7 @@ proc default_binutils_run { prog progarg
6cffa7
     regsub -all "\\$" "$progargs" "\\$" progargs
6cffa7
 
6cffa7
     set state [remote_exec host $prog $progargs]
6cffa7
+    set binutils_run_status [lindex $state 0]
6cffa7
     set exec_output [prune_warnings [lindex $state 1]]
6cffa7
     if {![string match "" $exec_output]} then {
6cffa7
 	send_log "$exec_output\n"
6cffa7
@@ -127,7 +133,6 @@ proc default_binutils_assemble_flags { s
6cffa7
     } else {
6cffa7
 	send_log "$exec_output\n"
6cffa7
 	verbose "$exec_output"
6cffa7
-	perror "$source: assembly failed"
6cffa7
 	return 0
6cffa7
     }
6cffa7
 }
6cffa7
@@ -214,6 +219,11 @@ proc exe_ext {} {
6cffa7
 #	Assemble the file SOURCE.s.  If omitted, this defaults to FILE.s.
6cffa7
 #       This is useful if several .d files want to share a .s file.
6cffa7
 #
6cffa7
+#   dump: DUMP
6cffa7
+#	Match against DUMP.d.  If omitted, this defaults to FILE.d.  This
6cffa7
+#	is useful if several .d files differ by options only.  Options are
6cffa7
+#	always read from FILE.d.
6cffa7
+#
6cffa7
 #   target: GLOBS...
6cffa7
 #       Run this test only on a specified list of targets.  More precisely,
6cffa7
 #       each glob in the space-separated list is passed to "istarget"; if
6cffa7
@@ -237,22 +247,22 @@ proc exe_ext {} {
6cffa7
 #
6cffa7
 #   error: REGEX
6cffa7
 #	An error with message matching REGEX must be emitted for the test
6cffa7
-#	to pass.  The PROG, objdump, nm and objcopy options have no
6cffa7
-#	meaning and need not supplied if this is present.
6cffa7
+#	to pass.  The DUMPPROG, addr2line, nm, objdump, readelf and size
6cffa7
+#	options have no meaning and need not supplied if this is present.
6cffa7
+#	Multiple "error" directives append to the expected error message.
6cffa7
+#
6cffa7
+#   error_output: FILE
6cffa7
+#	Means the same as 'error', except the regular expression lines
6cffa7
+#	are contains in FILE.
6cffa7
 #
6cffa7
 #   warning: REGEX
6cffa7
-#	Expect a gas warning matching REGEX.  It is an error to issue
6cffa7
-#	both "error" and "warning".
6cffa7
-#
6cffa7
-#   stderr: FILE
6cffa7
-#       FILE contains regexp lines to be matched against the diagnostic
6cffa7
-#       output of the assembler.  This does not preclude the use of
6cffa7
-#       PROG, nm, objdump, or objcopy.
6cffa7
-#
6cffa7
-#   error-output: FILE
6cffa7
-#       Means the same as 'stderr', but also indicates that the assembler
6cffa7
-#       is expected to exit unsuccessfully (therefore PROG, objdump, nm,
6cffa7
-#       and objcopy have no meaning and should not be supplied).
6cffa7
+#	Expect a warning matching REGEX.  It is an error to issue both
6cffa7
+#	"error" and "warning".  Multiple "warning" directives append to
6cffa7
+#	the expected linker warning message.
6cffa7
+#
6cffa7
+#   warning_output: FILE
6cffa7
+#	Means the same as 'warning', except the regular expression
6cffa7
+#	lines are contains in FILE.
6cffa7
 #
6cffa7
 # Each option may occur at most once.
6cffa7
 #
6cffa7
@@ -266,6 +276,7 @@ proc run_dump_test { name {extra_options
6cffa7
     global OBJDUMP NM OBJCOPY READELF STRIP
6cffa7
     global OBJDUMPFLAGS NMFLAGS OBJCOPYFLAGS READELFFLAGS STRIPFLAGS
6cffa7
     global ELFEDIT ELFEDITFLAGS
6cffa7
+    global binutils_run_status
6cffa7
     global host_triplet
6cffa7
     global env
6cffa7
     global copyfile
6cffa7
@@ -299,6 +310,11 @@ proc run_dump_test { name {extra_options
6cffa7
     set opts(PROG) {}
6cffa7
     set opts(DUMPPROG) {}
6cffa7
     set opts(source) {}
6cffa7
+    set opts(dump) {}
6cffa7
+    set opts(error) {}
6cffa7
+    set opts(warning) {}
6cffa7
+    set opts(error_output) {}
6cffa7
+    set opts(warning_output) {}
6cffa7
     set opts(target) {}
6cffa7
     set opts(not-target) {}
6cffa7
     set opts(skip) {}
6cffa7
@@ -317,12 +333,18 @@ proc run_dump_test { name {extra_options
6cffa7
 	# directory.
6cffa7
 	regsub -all "\\\$srcdir" "$opt_val" "$srcdir/$subdir" opt_val
6cffa7
 
6cffa7
-	if [string length $opts($opt_name)] {
6cffa7
-	    perror "option $opt_name multiply set in $file.d"
6cffa7
-	    unresolved $subdir/$name
6cffa7
-	    return
6cffa7
+	switch -- $opt_name {
6cffa7
+	    warning {}
6cffa7
+	    error {}
6cffa7
+	    default {
6cffa7
+		if [string length $opts($opt_name)] {
6cffa7
+		    perror "option $opt_name multiply set in $file.d"
6cffa7
+		    unresolved $subdir/$name
6cffa7
+		    return
6cffa7
+		}
6cffa7
+	    }
6cffa7
 	}
6cffa7
-	set opts($opt_name) $opt_val
6cffa7
+	append opts($opt_name) $opt_val
6cffa7
     }
6cffa7
 
6cffa7
     foreach i $extra_options {
6cffa7
@@ -340,7 +362,8 @@ proc run_dump_test { name {extra_options
6cffa7
 
6cffa7
 	# add extra option to end of existing option, adding space
6cffa7
 	# if necessary.
6cffa7
-	if [string length $opts($opt_name)] {
6cffa7
+	if { ![regexp "warning|error" $opt_name]
6cffa7
+	     && [string length $opts($opt_name)] } {
6cffa7
 	    append opts($opt_name) " "
6cffa7
 	}
6cffa7
 	append opts($opt_name) $opt_val
6cffa7
@@ -378,28 +401,35 @@ proc run_dump_test { name {extra_options
6cffa7
     }
6cffa7
 
6cffa7
     set dumpprogram ""
6cffa7
-    if { $opts(DUMPPROG) != "" } {
6cffa7
-	switch -- $opts(DUMPPROG) {
6cffa7
-	    addr2line	{ set dumpprogram addr2line }
6cffa7
-	    nm		{ set dumpprogram nm }
6cffa7
-	    objdump	{ set dumpprogram objdump }
6cffa7
-	    readelf	{ set dumpprogram readelf }
6cffa7
-	    size	{ set dumpprogram size }
6cffa7
-	    default	{
6cffa7
-		perror "unrecognized dump program option $opts(DUMPPROG) in $file.d"
6cffa7
-		unresolved $testname
6cffa7
-		return }
6cffa7
-	}
6cffa7
-    } else {
6cffa7
-	# Guess which program to run, by seeing which option was specified.
6cffa7
-	foreach p {addr2line nm objdump readelf size} {
6cffa7
-	    if {$opts($p) != ""} {
6cffa7
-		if {$dumpprogram != ""} {
6cffa7
-		    perror "more than one possible dump program specified in $file.d"
6cffa7
+    # It's meaningless to require an output-testing method when we
6cffa7
+    # expect an error.
6cffa7
+    if { $opts(error) == "" && $opts(error_output) == "" } {
6cffa7
+	if { $opts(DUMPPROG) != "" } {
6cffa7
+	    switch -- $opts(DUMPPROG) {
6cffa7
+		addr2line	{ set dumpprogram addr2line }
6cffa7
+		nm		{ set dumpprogram nm }
6cffa7
+		objdump		{ set dumpprogram objdump }
6cffa7
+		readelf		{ set dumpprogram readelf }
6cffa7
+		size		{ set dumpprogram size }
6cffa7
+		default		{
6cffa7
+		    perror "unrecognized dump program option $opts(DUMPPROG)\
6cffa7
+			    in $file.d"
6cffa7
 		    unresolved $testname
6cffa7
 		    return
6cffa7
-		} else {
6cffa7
-		    set dumpprogram $p
6cffa7
+		}
6cffa7
+	    }
6cffa7
+	} else {
6cffa7
+	    # Guess which program to run, by seeing which option was specified.
6cffa7
+	    foreach p {addr2line nm objdump readelf size} {
6cffa7
+		if {$opts($p) != ""} {
6cffa7
+		    if {$dumpprogram != ""} {
6cffa7
+			perror "more than one possible dump program specified\
6cffa7
+				in $file.d"
6cffa7
+			unresolved $testname
6cffa7
+			return
6cffa7
+		    } else {
6cffa7
+			set dumpprogram $p
6cffa7
+		    }
6cffa7
 		}
6cffa7
 	    }
6cffa7
 	}
6cffa7
@@ -456,6 +486,12 @@ proc run_dump_test { name {extra_options
6cffa7
 	set srcfile $srcdir/$subdir/$opts(source)
6cffa7
     }
6cffa7
 
6cffa7
+    if { $opts(dump) == "" } {
6cffa7
+	set dumpfile ${file}.d
6cffa7
+    } else {
6cffa7
+	set dumpfile $srcdir/$subdir/$opts(dump)
6cffa7
+    }
6cffa7
+
6cffa7
     if { $opts(as) == "binary" } {
6cffa7
 	while {[file type $srcfile] eq "link"} {
6cffa7
 	    set newfile [file readlink $srcfile]
6cffa7
@@ -464,7 +500,8 @@ proc run_dump_test { name {extra_options
6cffa7
 	    }
6cffa7
 	    set srcfile $newfile
6cffa7
 	}
6cffa7
-	file copy -force ${srcfile} $tempfile
6cffa7
+	# Make sure we copy the file if we are doing remote host testing.
6cffa7
+	remote_download host ${srcfile} $tempfile
6cffa7
     } else {
6cffa7
 	set exec_output [binutils_assemble_flags ${srcfile} $tempfile $opts(as)]
6cffa7
 	if [string match "" $exec_output] then {
6cffa7
@@ -475,16 +512,95 @@ proc run_dump_test { name {extra_options
6cffa7
 	}
6cffa7
     }
6cffa7
 
6cffa7
+    if { (($opts(warning) != "") && ($opts(error) != "")) \
6cffa7
+	 || (($opts(warning) != "") && ($opts(error_output) != "")) \
6cffa7
+	 || (($opts(warning) != "") && ($opts(warning_output) != "")) \
6cffa7
+	 || (($opts(error) != "") && ($opts(warning_output) != "")) \
6cffa7
+	 || (($opts(error) != "") && ($opts(error_output) != "")) \
6cffa7
+	 || (($opts(warning_output) != "") && ($opts(error_output) != "")) } {
6cffa7
+	perror "bad mix of warning, error, warning_output, and error_output\
6cffa7
+		test-directives"
6cffa7
+	unresolved $testname
6cffa7
+	return
6cffa7
+    }
6cffa7
+
6cffa7
+    set check_prog(source) ""
6cffa7
+    set check_prog(terminal) 0
6cffa7
+    if { $opts(error) != "" \
6cffa7
+	 || $opts(warning) != "" \
6cffa7
+	 || $opts(error_output) != "" \
6cffa7
+	 || $opts(warning_output) != "" } {
6cffa7
+
6cffa7
+	if { $opts(error) != "" || $opts(error_output) != "" } {
6cffa7
+	    set check_prog(terminal) 1
6cffa7
+	} else {
6cffa7
+	    set check_prog(terminal) 0
6cffa7
+	}
6cffa7
+
6cffa7
+	if { $opts(error) != "" || $opts(warning) != "" } {
6cffa7
+	    set check_prog(source) "regex"
6cffa7
+	    if { $opts(error) != "" } {
6cffa7
+		set check_prog(regex) $opts(error)
6cffa7
+	    } else {
6cffa7
+		set check_prog(regex) $opts(warning)
6cffa7
+	    }
6cffa7
+	} else {
6cffa7
+	    set check_prog(source) "file"
6cffa7
+	    if { $opts(error_output) != "" } {
6cffa7
+		set check_prog(file) $opts(error_output)
6cffa7
+	    } else {
6cffa7
+		set check_prog(file) $opts(warning_output)
6cffa7
+	    }
6cffa7
+	}
6cffa7
+    }
6cffa7
+
6cffa7
     set progopts1 $opts($program)
6cffa7
     eval set progopts \$[string toupper $program]FLAGS
6cffa7
     eval set binary \$[string toupper $program]
6cffa7
 
6cffa7
     set exec_output [binutils_run $binary "$progopts $progopts1 $tempfile $destopt ${copyfile}.o"]
6cffa7
-    if ![string match "" $exec_output] {
6cffa7
-	send_log "$exec_output\n"
6cffa7
+    set cmdret 0
6cffa7
+    if [info exists binutils_run_status] {
6cffa7
+	set cmdret $binutils_run_status
6cffa7
+    }
6cffa7
+
6cffa7
+    regsub "\n$" $exec_output "" exec_output
6cffa7
+    if { $cmdret != 0 || $exec_output != "" || $check_prog(source) != "" } {
6cffa7
+	set exitstat "succeeded"
6cffa7
+	if { $cmdret != 0 } {
6cffa7
+	    set exitstat "failed"
6cffa7
+	}
6cffa7
+
6cffa7
+	if { $check_prog(source) == "regex" } {
6cffa7
+	    verbose -log "$exitstat with: <$exec_output>,\
6cffa7
+			  expected: <$check_prog(regex)>"
6cffa7
+	} elseif { $check_prog(source) == "file" } {
6cffa7
+	    verbose -log "$exitstat with: <$exec_output>,\
6cffa7
+			  expected in file $check_prog(file)"
6cffa7
+	    set_file_contents "tmpdir/prog.messages" "$exec_output"
6cffa7
+	} else {
6cffa7
+	    verbose -log "$exitstat with: <$exec_output>, no expected output"
6cffa7
+	}
6cffa7
+	send_log -- "$exec_output\n"
6cffa7
 	verbose "$exec_output"
6cffa7
-	fail $testname
6cffa7
-	return
6cffa7
+
6cffa7
+	if { (($check_prog(source) == "") == ($exec_output == "")) \
6cffa7
+	     && (($cmdret == 0) == ($check_prog(terminal) == 0)) \
6cffa7
+	     && ((($check_prog(source) == "regex") \
6cffa7
+		  && ($check_prog(regex) == "") == ($exec_output == "") \
6cffa7
+		  && [regexp -- $check_prog(regex) $exec_output]) \
6cffa7
+		 || (($check_prog(source) == "file") \
6cffa7
+		     && (![regexp_diff "tmpdir/prog.messages" \
6cffa7
+			   "$srcdir/$subdir/$check_prog(file)"]))) } {
6cffa7
+	    # We have the expected output from prog.
6cffa7
+	    if { $check_prog(terminal) || $program == "" } {
6cffa7
+		pass $testname
6cffa7
+		return
6cffa7
+	    }
6cffa7
+	} else {
6cffa7
+	    fail $testname
6cffa7
+	    return
6cffa7
+	}
6cffa7
     }
6cffa7
 
6cffa7
     set progopts1 $opts($dumpprogram)
6cffa7
@@ -534,7 +650,7 @@ proc run_dump_test { name {extra_options
6cffa7
     }
6cffa7
 
6cffa7
     verbose_eval {[file_contents "tmpdir/dump.out"]} 3
6cffa7
-    if { [regexp_diff "tmpdir/dump.out" "${file}.d"] } then {
6cffa7
+    if { [regexp_diff "tmpdir/dump.out" "${dumpfile}"] } then {
6cffa7
 	fail $testname
6cffa7
 	verbose "output is [file_contents "tmpdir/dump.out"]" 2
6cffa7
 	return
6cffa7
--- /dev/null	2018-04-11 08:10:00.466225454 +0100
6cffa7
+++ binutils-2.27/binutils/testsuite/binutils-all/strip-13.d	2018-04-11 12:55:42.481306111 +0100
6cffa7
@@ -0,0 +1,10 @@
6cffa7
+#PROG: strip
6cffa7
+#strip: -g
6cffa7
+#error: \A[^\n]*: invalid relocation type 143\n
6cffa7
+#error:   [^\n]*: Bad value\Z
6cffa7
+#not-target: h8300-* ip2k-* m6811-* m68hc11-* rx-*
6cffa7
+# The H8300-*, IP2K and 68HC11 targets use 16-bit addressing, so `.dc.a'
6cffa7
+#  does not work for manual relocation data construction.
6cffa7
+# The RX targets do not complain about unrecognised relocs, unless they
6cffa7
+#  are actually used
6cffa7
+#  (which is what should really happen with the other targets...)
6cffa7
--- /dev/null	2018-04-11 08:10:00.466225454 +0100
6cffa7
+++ binutils-2.27/binutils/testsuite/binutils-all/strip-13mips64.s	2018-04-11 12:37:17.195412074 +0100
6cffa7
@@ -0,0 +1,14 @@
6cffa7
+	.text
6cffa7
+foo:
6cffa7
+	.dc.l    0x12345678
6cffa7
+
6cffa7
+	.section .rela.text
6cffa7
+	.dc.a	 0
6cffa7
+	.dc.l    0
6cffa7
+	.dc.b    0, 0, 0, 0x8f
6cffa7
+	.dc.a	 0x0000008f
6cffa7
+
6cffa7
+	.dc.a	 0
6cffa7
+	.dc.l    0
6cffa7
+	.dc.b    0, 0, 0, 0
6cffa7
+	.dc.a	 0
6cffa7
--- /dev/null	2018-04-11 08:10:00.466225454 +0100
6cffa7
+++ binutils-2.27/binutils/testsuite/binutils-all/strip-13rela.s	2018-04-11 12:37:17.195412074 +0100
6cffa7
@@ -0,0 +1,12 @@
6cffa7
+	.text
6cffa7
+foo:
6cffa7
+	.dc.l    0x12345678
6cffa7
+
6cffa7
+	.section .rela.text
6cffa7
+	.dc.a	 0
6cffa7
+	.dc.a    0x0000008f
6cffa7
+	.dc.a	 0x0000008f
6cffa7
+
6cffa7
+	.dc.a	 0
6cffa7
+	.dc.a    0
6cffa7
+	.dc.a	 0
6cffa7
--- /dev/null	2018-04-11 08:10:00.466225454 +0100
6cffa7
+++ binutils-2.27/binutils/testsuite/binutils-all/strip-13rel.s	2018-04-11 12:37:17.195412074 +0100
6cffa7
@@ -0,0 +1,10 @@
6cffa7
+	.text
6cffa7
+foo:
6cffa7
+	.dc.l    0x12345678
6cffa7
+
6cffa7
+	.section .rel.text
6cffa7
+	.dc.a	 0
6cffa7
+	.dc.a    0x0000008f
6cffa7
+
6cffa7
+	.dc.a	 0
6cffa7
+	.dc.a    0
6cffa7
--- binutils.orig/bfd/elfnn-aarch64.c	2018-04-11 12:34:04.649683557 +0100
6cffa7
+++ binutils-2.27/bfd/elfnn-aarch64.c	2018-04-11 13:33:08.539305994 +0100
6cffa7
@@ -1977,6 +1977,8 @@ elfNN_aarch64_info_to_howto (bfd *abfd A
6cffa7
 
6cffa7
   r_type = ELFNN_R_TYPE (elf_reloc->r_info);
6cffa7
   bfd_reloc->howto = elfNN_aarch64_howto_from_type (r_type);
6cffa7
+  if (bfd_reloc->howto == NULL)
6cffa7
+    _bfd_error_handler (_("%B: invalid relocation type %d"), abfd, r_type);
6cffa7
 }
6cffa7
 
6cffa7
 static reloc_howto_type *