opcodes error messages

Message ID 20180303010355.GF3812@bubble.grove.modra.org
State New
Headers show
Series
  • opcodes error messages
Related show

Commit Message

Alan Modra March 3, 2018, 1:03 a.m.
Another patch aimed at making binutils comply with the GNU coding
standard.  The generated files require
https://sourceware.org/ml/cgen/2018-q1/msg00004.html

I haven't fussed too much over messages in generator programs
(ie. those used only by developers) like opc2c.  Most of such messages
aren't even internationalized.

cpu/
	* frv.opc: Include opintl.h.
	(add_next_to_vliw): Use opcodes_error_handler to print error.
	Standardize error message.
	(fr500_check_insn_major_constraints, frv_vliw_add_insn): Likewise.
opcodes/
	* sysdep.h (opcodes_error_handler): Define.
	(_bfd_error_handler): Declare.
	* Makefile.am: Remove stray #.
	* opc2c.c (main): Remove bogus -l arg handling.  Print "DO NOT
	EDIT" comment.
	* aarch64-dis.c, * arc-dis.c, * arm-dis.c, * avr-dis.c,
	* d30v-dis.c, * h8300-dis.c, * mmix-dis.c, * ppc-dis.c,
	* riscv-dis.c, * s390-dis.c, * sparc-dis.c, * v850-dis.c: Use
	opcodes_error_handler to print errors.  Standardize error messages.
	* msp430-decode.opc, * nios2-dis.c, * rl78-decode.opc: Likewise,
	and include opintl.h.
	* nds32-asm.c: Likewise, and include sysdep.h and opintl.h.
	* i386-gen.c: Standardize error messages.
	* msp430-decode.c, * rl78-decode.c, rx-decode.c: Regenerate.
	* Makefile.in: Regenerate.
	* epiphany-asm.c, * epiphany-desc.c, * epiphany-dis.c,
	* epiphany-ibld.c, * fr30-asm.c, * fr30-desc.c, * fr30-dis.c,
	* fr30-ibld.c, * frv-asm.c, * frv-desc.c, * frv-dis.c, * frv-ibld.c,
	* frv-opc.c, * ip2k-asm.c, * ip2k-desc.c, * ip2k-dis.c, * ip2k-ibld.c,
	* iq2000-asm.c, * iq2000-desc.c, * iq2000-dis.c, * iq2000-ibld.c,
	* lm32-asm.c, * lm32-desc.c, * lm32-dis.c, * lm32-ibld.c,
	* m32c-asm.c, * m32c-desc.c, * m32c-dis.c, * m32c-ibld.c,
	* m32r-asm.c, * m32r-desc.c, * m32r-dis.c, * m32r-ibld.c,
	* mep-asm.c, * mep-desc.c, * mep-dis.c, * mep-ibld.c, * mt-asm.c,
	* mt-desc.c, * mt-dis.c, * mt-ibld.c, * or1k-asm.c, * or1k-desc.c,
	* or1k-dis.c, * or1k-ibld.c, * xc16x-asm.c, * xc16x-desc.c,
	* xc16x-dis.c, * xc16x-ibld.c, * xstormy16-asm.c, * xstormy16-desc.c,
	* xstormy16-dis.c, * xstormy16-ibld.c: Regenerate.


-- 
Alan Modra
Australia Development Lab, IBM

Comments

John Darrington March 3, 2018, 7:09 a.m. | #1
On Sat, Mar 03, 2018 at 11:33:55AM +1030, Alan Modra wrote:
     Another patch aimed at making binutils comply with the GNU coding
     standard.  The generated files require
     https://sourceware.org/ml/cgen/2018-q1/msg00004.html
     
      /* -- opc.c */
     +#include "opintl.h"
      #include "elf/frv.h"
      #include <stdio.h>
      
     @@ -500,9 +501,9 @@ add_next_to_vliw (FRV_VLIW *vliw, CGEN_ATTR_VALUE_ENUM_TYPE unit)
      
        if (next <= 0)
          {
     -      fprintf (stderr, "frv-opc.c line %d: bad vliw->next_slot value.\n",
     -	       __LINE__);
     -      abort (); /* Should never happen.  */
     +      /* xgettext:c-format */
     +      opcodes_error_handler (_("internal error: bad vliw->next_slot value"));
     +      abort ();
          }

My interpretation of the GNU coding standards doesn't require that internal 
error messages be internationalised.  It's only required for messages which 
appear during normal operation, or in response to bad user input.

Of course that doesn't mean that they cannot be i18n'd if it isn't going to put
too much load on the translators.

J'

-- 
Avoid eavesdropping.  Send strong encrypted email.
PGP Public key ID: 1024D/2DE827B3 
fingerprint = 8797 A26D 0854 2EAB 0285  A290 8A67 719C 2DE8 27B3
See http://sks-keyservers.net or any PGP keyserver for public key.

Patch

diff --git a/cpu/frv.opc b/cpu/frv.opc
index 869155d..1b0b05c 100644
--- a/cpu/frv.opc
+++ b/cpu/frv.opc
@@ -78,6 +78,7 @@  int spr_valid           (long);
 /* -- */
 
 /* -- opc.c */
+#include "opintl.h"
 #include "elf/frv.h"
 #include <stdio.h>
 
@@ -500,9 +501,9 @@  add_next_to_vliw (FRV_VLIW *vliw, CGEN_ATTR_VALUE_ENUM_TYPE unit)
 
   if (next <= 0)
     {
-      fprintf (stderr, "frv-opc.c line %d: bad vliw->next_slot value.\n",
-	       __LINE__);
-      abort (); /* Should never happen.  */
+      /* xgettext:c-format */
+      opcodes_error_handler (_("internal error: bad vliw->next_slot value"));
+      abort ();
     }
 
   /* The table is sorted by units allowed within slots, so vliws with
@@ -810,8 +811,8 @@  fr500_check_insn_major_constraints (FRV_VLIW *vliw, CGEN_ATTR_VALUE_ENUM_TYPE ma
 	&&   ! find_major_in_vliw (vliw, FR500_MAJOR_F_6)
 	&&   ! find_major_in_vliw (vliw, FR500_MAJOR_F_7);
     default:
-      fprintf (stderr, "frv-opc.c, line %d: bad major code, aborting.\n",
-	       __LINE__);
+      /* xgettext:c-format */
+      opcodes_error_handler (_("internal error: bad major code"));
       abort ();
       break;
     }
@@ -860,9 +861,9 @@  frv_vliw_add_insn (FRV_VLIW *vliw, const CGEN_INSN *insn)
   unit = CGEN_INSN_ATTR_VALUE (insn, CGEN_INSN_UNIT);
   if (unit == UNIT_NIL)
     {
-      fprintf (stderr, "frv-opc.c line %d: bad insn unit.\n",
-	       __LINE__);
-      abort (); /* No UNIT specified for this insn in frv.cpu.  */
+      /* xgettext:c-format */
+      opcodes_error_handler (_("internal error: bad insn unit"));
+      abort ();
     }
 
   switch (vliw->mach)
diff --git a/opcodes/Makefile.am b/opcodes/Makefile.am
index 2458027..1b269a8 100644
--- a/opcodes/Makefile.am
+++ b/opcodes/Makefile.am
@@ -471,7 +471,7 @@  stamp-lm32: $(CGENDEPS) $(CPUDIR)/lm32.cpu $(CPUDIR)/lm32.opc
 		extrafiles=opinst
 
 $(srcdir)/m32c-desc.h $(srcdir)/m32c-desc.c $(srcdir)/m32c-opc.h $(srcdir)/m32c-opc.c $(srcdir)/m32c-ibld.c $(srcdir)/m32c-asm.c $(srcdir)/m32c-dis.c: $(M32C_DEPS)
-#	@true
+	@true
 stamp-m32c: $(CGENDEPS) $(CPUDIR)/m32c.cpu $(CPUDIR)/m32c.opc
 	$(MAKE) run-cgen arch=m32c prefix=m32c options= \
 		archfile=$(CPUDIR)/m32c.cpu \
diff --git a/opcodes/aarch64-dis.c b/opcodes/aarch64-dis.c
index a7f5cfc..c63f595 100644
--- a/opcodes/aarch64-dis.c
+++ b/opcodes/aarch64-dis.c
@@ -78,7 +78,7 @@  parse_aarch64_dis_option (const char *option, unsigned int len ATTRIBUTE_UNUSED)
 #endif /* DEBUG_AARCH64 */
 
   /* Invalid option.  */
-  fprintf (stderr, _("Unrecognised disassembler option: %s\n"), option);
+  opcodes_error_handler (_("unrecognised disassembler option: %s"), option);
 }
 
 static void
diff --git a/opcodes/arc-dis.c b/opcodes/arc-dis.c
index cb72542..feb4ca8 100644
--- a/opcodes/arc-dis.c
+++ b/opcodes/arc-dis.c
@@ -778,7 +778,8 @@  parse_option (const char *option)
   else if (CONST_STRNEQ (option, "hex"))
     print_hex = TRUE;
   else
-    fprintf (stderr, _("Unrecognised disassembler option: %s\n"), option);
+    /* xgettext:c-format */
+    opcodes_error_handler (_("unrecognised disassembler option: %s"), option);
 }
 
 #define ARC_CPU_TYPE_A6xx(NAME,EXTRA)			\
@@ -820,7 +821,8 @@  parse_cpu_option (const char *option)
 	}
     }
 
-  fprintf (stderr, _("Unrecognised disassembler CPU option: %s\n"), option);
+  /* xgettext:c-format */
+  opcodes_error_handler (_("unrecognised disassembler CPU option: %s"), option);
   return ARC_OPCODE_NONE;
 }
 
diff --git a/opcodes/arm-dis.c b/opcodes/arm-dis.c
index f0fc93c..6f93cfd 100644
--- a/opcodes/arm-dis.c
+++ b/opcodes/arm-dis.c
@@ -6145,14 +6145,17 @@  parse_arm_disassembler_options (const char *options)
 	      }
 
 	  if (i >= NUM_ARM_OPTIONS)
-	    fprintf (stderr, _("Unrecognised register name set: %s\n"), opt);
+	    /* xgettext: c-format */
+	    opcodes_error_handler (_("unrecognised register name set: %s"),
+				   opt);
 	}
       else if (CONST_STRNEQ (opt, "force-thumb"))
 	force_thumb = 1;
       else if (CONST_STRNEQ (opt, "no-force-thumb"))
 	force_thumb = 0;
       else
-	fprintf (stderr, _("Unrecognised disassembler option: %s\n"), opt);
+	/* xgettext: c-format */
+	opcodes_error_handler (_("unrecognised disassembler option: %s"), opt);
     }
 
   return;
diff --git a/opcodes/avr-dis.c b/opcodes/avr-dis.c
index 16467b8..6a37c6e 100644
--- a/opcodes/avr-dis.c
+++ b/opcodes/avr-dis.c
@@ -212,7 +212,8 @@  avr_operand (unsigned int insn, unsigned int insn2, unsigned int pc, int constra
 
     case 'n':
       sprintf (buf, "??");
-      fprintf (stderr, _("Internal disassembler error"));
+      /* xgettext:c-format */
+      opcodes_error_handler (_("internal disassembler error"));
       ok = 0;
       break;
 
@@ -265,7 +266,8 @@  avr_operand (unsigned int insn, unsigned int insn2, unsigned int pc, int constra
 
     default:
       sprintf (buf, "??");
-      fprintf (stderr, _("unknown constraint `%c'"), constraint);
+      /* xgettext:c-format */
+      opcodes_error_handler (_("unknown constraint `%c'"), constraint);
       ok = 0;
     }
 
diff --git a/opcodes/d30v-dis.c b/opcodes/d30v-dis.c
index 63f64fb..f878343 100644
--- a/opcodes/d30v-dis.c
+++ b/opcodes/d30v-dis.c
@@ -225,7 +225,9 @@  print_insn (struct disassemble_info *info,
 		  val |= OPERAND_FLAG;
 		  break;
 		default:
-		  fprintf (stderr, "illegal id (%d)\n", id);
+		  /* xgettext: c-format */
+		  opcodes_error_handler (_("illegal id (%d)"), id);
+		  abort ();
 		}
 	    }
 	  else if (oper->flags & OPERAND_ACC)
diff --git a/opcodes/h8300-dis.c b/opcodes/h8300-dis.c
index 2b504eb..d9e5c9d 100644
--- a/opcodes/h8300-dis.c
+++ b/opcodes/h8300-dis.c
@@ -59,7 +59,8 @@  bfd_h8_disassemble_init (void)
 
       if (i & 1)
 	{
-	  fprintf (stderr, "Internal error, h8_disassemble_init.\n");
+	  /* xgettext:c-format */
+	  opcodes_error_handler (_("internal error, h8_disassemble_init"));
 	  abort ();
 	}
 
diff --git a/opcodes/i386-gen.c b/opcodes/i386-gen.c
index 669ac0c..abd4ebf 100644
--- a/opcodes/i386-gen.c
+++ b/opcodes/i386-gen.c
@@ -722,7 +722,7 @@  fail (const char *message, ...)
   va_list args;
 
   va_start (args, message);
-  fprintf (stderr, _("%s: Error: "), program_name);
+  fprintf (stderr, _("%s: error: "), program_name);
   vfprintf (stderr, message, args);
   va_end (args);
   xexit (1);
@@ -901,9 +901,9 @@  set_bitfield (char *f, bitfield *array, int value,
     return;
 
   if (lineno != -1)
-    fail (_("%s: %d: Unknown bitfield: %s\n"), filename, lineno, f);
+    fail (_("%s: %d: unknown bitfield: %s\n"), filename, lineno, f);
   else
-    fail (_("Unknown bitfield: %s\n"), f);
+    fail (_("unknown bitfield: %s\n"), f);
 }
 
 static void
@@ -966,7 +966,7 @@  process_i386_cpu_flag (FILE *table, char *flag, int macro,
 	  last -= 1;
 	  next = flag + 2;
 	  if (*last != ')')
-	    fail (_("%s: %d: Missing `)' in bitfield: %s\n"), filename,
+	    fail (_("%s: %d: missing `)' in bitfield: %s\n"), filename,
 		  lineno, flag);
 	  *last = '\0';
 	}
diff --git a/opcodes/mmix-dis.c b/opcodes/mmix-dis.c
index bf14b77..89a4cd9 100644
--- a/opcodes/mmix-dis.c
+++ b/opcodes/mmix-dis.c
@@ -27,24 +27,23 @@ 
 #include "bfd.h"
 #include "opintl.h"
 
-#define BAD_CASE(x)				\
- do						\
-   {						\
-     fprintf (stderr,				\
-	      _("Bad case %d (%s) in %s:%d\n"),	\
-	      x, #x, __FILE__, __LINE__);	\
-     abort ();					\
-   }						\
+#define BAD_CASE(x)						\
+  do								\
+   {								\
+     opcodes_error_handler (_("bad case %d (%s) in %s:%d"),	\
+			    x, #x, __FILE__, __LINE__);		\
+     abort ();							\
+   }								\
  while (0)
 
-#define FATAL_DEBUG							\
- do									\
-   {									\
-     fprintf (stderr,							\
-	      _("Internal: Non-debugged code (test-case missing): %s:%d"),\
-	      __FILE__, __LINE__);					\
-     abort ();								\
-   }									\
+#define FATAL_DEBUG						\
+ do								\
+   {								\
+     opcodes_error_handler (_("internal: non-debugged code "	\
+			      "(test-case missing): %s:%d"),	\
+			    __FILE__, __LINE__);		\
+     abort ();							\
+   }								\
  while (0)
 
 #define ROUND_MODE(n)					\
diff --git a/opcodes/msp430-decode.opc b/opcodes/msp430-decode.opc
index 5afd3f3..8cdae5a 100644
--- a/opcodes/msp430-decode.opc
+++ b/opcodes/msp430-decode.opc
@@ -25,6 +25,7 @@ 
 #include <stdlib.h>
 #include <string.h>
 #include "ansidecl.h"
+#include "opintl.h"
 #include "opcode/msp430-decode.h"
 
 static int trace = 0;
@@ -140,9 +141,9 @@  immediate (int bytes, int sign_extend, LocalData *ld)
 	i -= 0x100000000ULL;
       break;
     default:
-      fprintf (stderr,
-	       "Programmer error: immediate() called with invalid byte count %d\n",
-	       bytes);
+      opcodes_error_handler
+	(_("internal error: immediate() called with invalid byte count %d"),
+	   bytes);
       abort ();
     }
   return i;
diff --git a/opcodes/nds32-asm.c b/opcodes/nds32-asm.c
index c483dce..b5309fb 100644
--- a/opcodes/nds32-asm.c
+++ b/opcodes/nds32-asm.c
@@ -20,17 +20,16 @@ 
    02110-1301, USA.  */
 
 
-#include <config.h>
+#include "sysdep.h"
 
-#include <stdlib.h>
 #include <stdint.h>
-#include <string.h>
 #include <assert.h>
 
 #include "safe-ctype.h"
 #include "libiberty.h"
 #include "hashtab.h"
 #include "bfd.h"
+#include "opintl.h"
 
 #include "opcode/nds32.h"
 #include "nds32-asm.h"
@@ -1505,9 +1504,11 @@  build_opcode_syntax (struct nds32_opcode *opc)
 
       if (fd == NULL)
 	{
-	  fprintf (stderr, "Internal error: Unknown operand, %s\n", str);
+	  /* xgettext: c-format */
+	  opcodes_error_handler (_("internal error: unknown operand, %s"), str);
+	  abort ();
 	}
-      assert (fd && fidx >= 0 && fidx < (int) ARRAY_SIZE (operand_fields));
+      assert (fidx >= 0 && fidx < (int) ARRAY_SIZE (operand_fields));
       *plex |= LEX_SET_FIELD (fidx);
 
       str += len;
@@ -2057,14 +2058,16 @@  parse_operand (nds32_asm_desc_t *pdesc, nds32_asm_insn_t *pinsn,
 	    value = value & 0xfffff;
 	  break;
 	default:
-	  fprintf (stderr, "Internal error: Don't know how to handle "
-		   "parsing results.\n");
+	  /* xgettext: c-format */
+	  opcodes_error_handler (_("internal error: don't know how to handle "
+				   "parsing results"));
 	  abort ();
 	}
     }
   else
     {
-      fprintf (stderr, "Internal error: Unknown hardware resource.\n");
+      /* xgettext: c-format */
+      opcodes_error_handler (_("internal error: unknown hardware resource"));
       abort ();
     }
 
diff --git a/opcodes/nios2-dis.c b/opcodes/nios2-dis.c
index 9eedbf9..257e5bb 100644
--- a/opcodes/nios2-dis.c
+++ b/opcodes/nios2-dis.c
@@ -22,6 +22,7 @@ 
 
 #include "sysdep.h"
 #include "disassemble.h"
+#include "opintl.h"
 #include "opcode/nios2.h"
 #include "libiberty.h"
 #include <string.h>
@@ -130,9 +131,9 @@  nios2_init_opcode_hash (nios2_disassembler_state *state)
 	      (nios2_opcode_hash *) malloc (sizeof (nios2_opcode_hash));
 	    if (new_hash == NULL)
 	      {
-		fprintf (stderr,
-			 "error allocating memory...broken disassembler\n");
-		abort ();
+		/* xgettext:c-format */
+		opcodes_error_handler (_("out of memory"));
+		exit (1);
 	      }
 	    new_hash->opcode = op;
 	    new_hash->next = NULL;
@@ -257,8 +258,10 @@  nios2_control_regs (void)
 static void
 bad_opcode (const struct nios2_opcode *op)
 {
-  fprintf (stderr, "Internal error: broken opcode descriptor for `%s %s'\n",
-	   op->name, op->args);
+  opcodes_error_handler
+    /* xgettext:c-format */
+    (_("internal error: broken opcode descriptor for `%s %s'"),
+     op->name, op->args);
   abort ();
 }
 
diff --git a/opcodes/opc2c.c b/opcodes/opc2c.c
index 8a2c7f3..1184599 100644
--- a/opcodes/opc2c.c
+++ b/opcodes/opc2c.c
@@ -577,14 +577,6 @@  main (int argc, char ** argv)
   VaryRef * vlist;
   int skipping_section = 0;
 
-  if (argc > 2 && strcmp (argv[1], "-l") == 0)
-    {
-      sim_log = fopen (argv[2], "w");
-      fprintf (stderr, "sim_log: %s\n", argv[2]);
-      argc -= 2;
-      argv += 2;
-    }
-
   if (argc < 2)
     {
       fprintf (stderr, "usage: opc2c infile.opc > outfile.opc\n");
@@ -802,6 +794,8 @@  main (int argc, char ** argv)
       store_opcode_bits (opcodes[i], 0, indirect);
     }
 
+  printf ("/* DO NOT EDIT!  -*- buffer-read-only: t -*- vi:set ro:  */\n");
+
   dump_lines (&prefix_text, 0, 0);
 
   emit_indirect (indirect, 0);
diff --git a/opcodes/ppc-dis.c b/opcodes/ppc-dis.c
index eee84d2..a2cfc0b 100644
--- a/opcodes/ppc-dis.c
+++ b/opcodes/ppc-dis.c
@@ -356,7 +356,8 @@  powerpc_init_dialect (struct disassemble_info *info)
       else if ((new_cpu = ppc_parse_cpu (dialect, &sticky, opt)) != 0)
 	dialect = new_cpu;
       else
-	fprintf (stderr, _("warning: ignoring unknown -M%s option\n"), opt);
+	/* xgettext: c-format */
+	opcodes_error_handler (_("warning: ignoring unknown -M%s option"), opt);
     }
 
   info->private_data = priv;
diff --git a/opcodes/riscv-dis.c b/opcodes/riscv-dis.c
index cc642d4..e8fc6ea 100644
--- a/opcodes/riscv-dis.c
+++ b/opcodes/riscv-dis.c
@@ -64,8 +64,8 @@  parse_riscv_dis_option (const char *option)
     }
   else
     {
-      /* Invalid option.  */
-      fprintf (stderr, _("Unrecognized disassembler option: %s\n"), option);
+      /* xgettext:c-format */
+      opcodes_error_handler (_("unrecognized disassembler option: %s"), option);
     }
 }
 
diff --git a/opcodes/rl78-decode.opc b/opcodes/rl78-decode.opc
index a6368ad..49e9e69 100644
--- a/opcodes/rl78-decode.opc
+++ b/opcodes/rl78-decode.opc
@@ -25,6 +25,7 @@ 
 #include <stdlib.h>
 #include <string.h>
 #include "ansidecl.h"
+#include "opintl.h"
 #include "opcode/rl78.h"
 
 static int trace = 0;
@@ -100,7 +101,10 @@  immediate (int bytes, int sign_extend, LocalData * ld)
 	i -= 0x1000000;
       break;
     default:
-      fprintf (stderr, "Programmer error: immediate() called with invalid byte count %d\n", bytes);
+      opcodes_error_handler
+	/* xgettext:c-format */
+	(_("internal error: immediate() called with invalid byte count %d"),
+	   bytes);
       abort();
     }
   return i;
diff --git a/opcodes/s390-dis.c b/opcodes/s390-dis.c
index 2c34af0..6763d9f 100644
--- a/opcodes/s390-dis.c
+++ b/opcodes/s390-dis.c
@@ -72,7 +72,8 @@  disassemble_init_s390 (struct disassemble_info *info)
       else if (CONST_STRNEQ (p, "insnlength"))
 	option_use_insn_len_bits_p = 1;
       else
-	fprintf (stderr, "Unknown S/390 disassembler option: %s\n", p);
+	/* xgettext:c-format */
+	opcodes_error_handler (_("unknown S/390 disassembler option: %s"), p);
 
       p = strchr (p, ',');
       if (p != NULL)
diff --git a/opcodes/sparc-dis.c b/opcodes/sparc-dis.c
index fb428e8..77df145 100644
--- a/opcodes/sparc-dis.c
+++ b/opcodes/sparc-dis.c
@@ -303,10 +303,9 @@  compare_opcodes (const void * a, const void * b)
      wrong with the opcode table.  */
   if (match0 & lose0)
     {
-      fprintf
-	(stderr,
-	 /* xgettext:c-format */
-	 _("Internal error:  bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
+      opcodes_error_handler
+	/* xgettext:c-format */
+	(_("internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
 	 op0->name, match0, lose0);
       op0->lose &= ~op0->match;
       lose0 = op0->lose;
@@ -314,10 +313,9 @@  compare_opcodes (const void * a, const void * b)
 
   if (match1 & lose1)
     {
-      fprintf
-	(stderr,
-	 /* xgettext:c-format */
-	 _("Internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
+      opcodes_error_handler
+	/* xgettext:c-format */
+	(_("internal error: bad sparc-opcode.h: \"%s\", %#.8lx, %#.8lx\n"),
 	 op1->name, match1, lose1);
       op1->lose &= ~op1->match;
       lose1 = op1->lose;
@@ -374,10 +372,10 @@  compare_opcodes (const void * a, const void * b)
 	  return i;
 	}
       else
-	fprintf (stderr,
-		 /* xgettext:c-format */
-		 _("Internal error: bad sparc-opcode.h: \"%s\" == \"%s\"\n"),
-		 op0->name, op1->name);
+	opcodes_error_handler
+	  /* xgettext:c-format */
+	  (_("internal error: bad sparc-opcode.h: \"%s\" == \"%s\"\n"),
+	   op0->name, op1->name);
     }
 
   /* Fewer arguments are preferred.  */
diff --git a/opcodes/sysdep.h b/opcodes/sysdep.h
index 4258a0d..20f5828 100644
--- a/opcodes/sysdep.h
+++ b/opcodes/sysdep.h
@@ -56,6 +56,9 @@ 
 extern char *stpcpy (char *__dest, const char *__src);
 #endif
 
+#define opcodes_error_handler _bfd_error_handler
+extern void _bfd_error_handler (const char *, ...) ATTRIBUTE_PRINTF_1;
+
 /* Use sigsetjmp/siglongjmp without saving the signal mask if possible.
    It is faster than setjmp/longjmp on systems where the signal mask is
    saved.  */
diff --git a/opcodes/v850-dis.c b/opcodes/v850-dis.c
index 448dc79..af4437c 100644
--- a/opcodes/v850-dis.c
+++ b/opcodes/v850-dis.c
@@ -450,7 +450,8 @@  disassemble (bfd_vma memaddr,
 		      case 0xffe00001: regs = list12_regs; break;
 		      default:
 			/* xgettext:c-format */
-			fprintf (stderr, _("unknown operand shift: %x\n"), operand->shift);
+			opcodes_error_handler (_("unknown operand shift: %x"),
+					       operand->shift);
 			abort ();
 		      }
 
@@ -460,10 +461,17 @@  disassemble (bfd_vma memaddr,
 			  {
 			    switch (regs[ i ])
 			      {
-			      default: mask |= (1 << regs[ i ]); break;
+			      default:
+				mask |= (1 << regs[ i ]);
+				break;
+			      case 0:
 				/* xgettext:c-format */
-			      case 0:  fprintf (stderr, _("unknown reg: %d\n"), i ); abort ();
-			      case -1: pc = 1; break;
+				opcodes_error_handler (_("unknown reg: %d"), i);
+				abort ();
+				break;
+			      case -1:
+				pc = 1;
+				break;
 			      }
 			  }
 		      }