Make bfd_error_handler_type like vprintf

Alan Modra amodra@gmail.com
Fri Sep 30 08:11:00 GMT 2016


It was like printf, which means you can't use bfd_set_error_handler to
hook in a function to do something and then call the original handler.

The patch also deletes some unused functions and makes pointers local.

bfd/
	* bfd-in.h: Include stdarg.h.
	* bfd.c (bfd_error_handler_type): Make like vprintf.
	(_bfd_error_internal): Rename from _bfd_error_handler.  Make static.
	(error_handler_internal): New function, split out from..
	(_bfd_default_error_handler): ..here.  Rename to _bfd_error_handler.
	(bfd_set_error_handler): Update.
	(bfd_get_error_handler, bfd_get_assert_handler): Delete.
	(_bfd_assert_handler): Make static.
	* coffgen.c (null_error_handler): Update params.
	* elf-bfd.h (struct elf_backend_data <link_order_error_handler>):
	Don't use bfd_error_handler_type.
	* elf64-mmix.c (mmix_dump_bpo_gregs): Likewise.
	* elfxx-target.h (elf_backend_link_order_error_handler): Default
	to _bfd_error_handler.
	* libbfd-in.h (_bfd_default_error_handler): Don't declare.
	(bfd_assert_handler_type): Likewise.
	(_bfd_error_handler): Update.
	* bfd-in2.h: Regenerate.
	* libbfd.h: Regenerate.
ld/
	* ldlang.c (ignore_bfd_errors): Update params.

diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h
index fa3da83..4b3bcfd 100644
--- a/bfd/bfd-in.h
+++ b/bfd/bfd-in.h
@@ -34,6 +34,7 @@ extern "C" {
 
 #include "ansidecl.h"
 #include "symcat.h"
+#include <stdarg.h>
 #include <sys/stat.h>
 
 #if defined (__STDC__) || defined (ALMOST_STDC) || defined (HAVE_STRINGIZE)
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 806b9fb..4130d2d 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -598,11 +598,11 @@ SUBSECTION
 	problem.  They call a BFD error handler function.  This
 	function may be overridden by the program.
 
-	The BFD error handler acts like printf.
+	The BFD error handler acts like vprintf.
 
 CODE_FRAGMENT
 .
-.typedef void (*bfd_error_handler_type) (const char *, ...);
+.typedef void (*bfd_error_handler_type) (const char *, va_list);
 .
 */
 
@@ -634,10 +634,9 @@ static const char *_bfd_error_program_name;
 	integer_for_the_%d);
  */
 
-void
-_bfd_default_error_handler (const char *fmt, ...)
+static void
+error_handler_internal (const char *fmt, va_list ap)
 {
-  va_list ap;
   char *bufp;
   const char *new_fmt, *p;
   size_t avail = 1000;
@@ -651,7 +650,6 @@ _bfd_default_error_handler (const char *fmt, ...)
   else
     fprintf (stderr, "BFD: ");
 
-  va_start (ap, fmt);
   new_fmt = fmt;
   bufp = buf;
 
@@ -782,7 +780,6 @@ _bfd_default_error_handler (const char *fmt, ...)
     }
 
   vfprintf (stderr, new_fmt, ap);
-  va_end (ap);
 
   /* On AIX, putc is implemented as a macro that triggers a -Wunused-value
      warning, so use the fputc function to avoid it.  */
@@ -796,7 +793,17 @@ _bfd_default_error_handler (const char *fmt, ...)
    function pointer permits a program linked against BFD to intercept
    the messages and deal with them itself.  */
 
-bfd_error_handler_type _bfd_error_handler = _bfd_default_error_handler;
+static bfd_error_handler_type _bfd_error_internal = error_handler_internal;
+
+void
+_bfd_error_handler (const char *fmt, ...)
+{
+  va_list ap;
+
+  va_start (ap, fmt);
+  _bfd_error_internal (fmt, ap);
+  va_end (ap);
+}
 
 /*
 FUNCTION
@@ -815,8 +822,8 @@ bfd_set_error_handler (bfd_error_handler_type pnew)
 {
   bfd_error_handler_type pold;
 
-  pold = _bfd_error_handler;
-  _bfd_error_handler = pnew;
+  pold = _bfd_error_internal;
+  _bfd_error_internal = pnew;
   return pold;
 }
 
@@ -841,23 +848,6 @@ bfd_set_error_program_name (const char *name)
 }
 
 /*
-FUNCTION
-	bfd_get_error_handler
-
-SYNOPSIS
-	bfd_error_handler_type bfd_get_error_handler (void);
-
-DESCRIPTION
-	Return the BFD error handler function.
-*/
-
-bfd_error_handler_type
-bfd_get_error_handler (void)
-{
-  return _bfd_error_handler;
-}
-
-/*
 SUBSECTION
 	BFD assert handler
 
@@ -898,7 +888,7 @@ _bfd_default_assert_handler (const char *bfd_formatmsg,
    internal BFD error.  We use a non-variadic type to simplify passing
    on parameters to other functions, e.g. _bfd_error_handler.  */
 
-bfd_assert_handler_type _bfd_assert_handler = _bfd_default_assert_handler;
+static bfd_assert_handler_type _bfd_assert_handler = _bfd_default_assert_handler;
 
 /*
 FUNCTION
@@ -921,23 +911,6 @@ bfd_set_assert_handler (bfd_assert_handler_type pnew)
   _bfd_assert_handler = pnew;
   return pold;
 }
-
-/*
-FUNCTION
-	bfd_get_assert_handler
-
-SYNOPSIS
-	bfd_assert_handler_type bfd_get_assert_handler (void);
-
-DESCRIPTION
-	Return the BFD assert handler function.
-*/
-
-bfd_assert_handler_type
-bfd_get_assert_handler (void)
-{
-  return _bfd_assert_handler;
-}
 
 /*
 INODE
diff --git a/bfd/coffgen.c b/bfd/coffgen.c
index 75512fb..b9b8860 100644
--- a/bfd/coffgen.c
+++ b/bfd/coffgen.c
@@ -1218,7 +1218,8 @@ coff_write_native_symbol (bfd *abfd,
 }
 
 static void
-null_error_handler (const char * fmt ATTRIBUTE_UNUSED, ...)
+null_error_handler (const char *fmt ATTRIBUTE_UNUSED,
+		    va_list ap ATTRIBUTE_UNUSED)
 {
 }
 
diff --git a/bfd/elf-bfd.h b/bfd/elf-bfd.h
index 6bebbbe..7f78b1d 100644
--- a/bfd/elf-bfd.h
+++ b/bfd/elf-bfd.h
@@ -1326,7 +1326,7 @@ struct elf_backend_data
      Elf_Internal_Shdr *osection);
 		
   /* Used to handle bad SHF_LINK_ORDER input.  */
-  bfd_error_handler_type link_order_error_handler;
+  void (*link_order_error_handler) (const char *, ...);
 
   /* Name of the PLT relocation section.  */
   const char *relplt_name;
diff --git a/bfd/elf64-mmix.c b/bfd/elf64-mmix.c
index 2038813..9c56f7c 100644
--- a/bfd/elf64-mmix.c
+++ b/bfd/elf64-mmix.c
@@ -172,7 +172,7 @@ extern void mmix_elf_symbol_processing (bfd *, asymbol *);
 
 /* Only intended to be called from a debugger.  */
 extern void mmix_dump_bpo_gregs
-  (struct bfd_link_info *, bfd_error_handler_type);
+  (struct bfd_link_info *, void (*) (const char *, ...));
 
 static void
 mmix_set_relaxable_size (bfd *, asection *, void *);
@@ -2485,7 +2485,7 @@ bpo_reloc_request_sort_fn (const void * p1, const void * p2)
 
 void
 mmix_dump_bpo_gregs (struct bfd_link_info *link_info,
-		     bfd_error_handler_type pf)
+		     void (*pf) (const char *fmt, ...))
 {
   bfd *bpo_greg_owner;
   asection *bpo_gregs_section;
diff --git a/bfd/elfxx-target.h b/bfd/elfxx-target.h
index ba13012..6bab686 100644
--- a/bfd/elfxx-target.h
+++ b/bfd/elfxx-target.h
@@ -660,7 +660,7 @@
 #endif
 
 #ifndef elf_backend_link_order_error_handler
-#define elf_backend_link_order_error_handler _bfd_default_error_handler
+#define elf_backend_link_order_error_handler _bfd_error_handler
 #endif
 
 #ifndef elf_backend_common_definition
diff --git a/bfd/libbfd-in.h b/bfd/libbfd-in.h
index cde3aad..f27adc9 100644
--- a/bfd/libbfd-in.h
+++ b/bfd/libbfd-in.h
@@ -109,9 +109,7 @@ extern void *bfd_realloc2
 extern void *bfd_zmalloc2
   (bfd_size_type, bfd_size_type);
 
-extern void _bfd_default_error_handler (const char *s, ...);
-extern bfd_error_handler_type _bfd_error_handler;
-extern bfd_assert_handler_type _bfd_assert_handler;
+extern void _bfd_error_handler (const char *s, ...);
 
 /* These routines allocate and free things on the BFD's objalloc.  */
 
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 07c2182..0a38d0b 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -5984,7 +5984,8 @@ lang_end (void)
    BFD.  */
 
 static void
-ignore_bfd_errors (const char *s ATTRIBUTE_UNUSED, ...)
+ignore_bfd_errors (const char *fmt ATTRIBUTE_UNUSED,
+		   va_list ap ATTRIBUTE_UNUSED)
 {
   /* Don't do anything.  */
 }

-- 
Alan Modra
Australia Development Lab, IBM



More information about the Binutils mailing list