Make bfd_error_handler_type like vprintf

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.
This commit is contained in:
Alan Modra 2016-09-30 11:03:52 +09:30
parent 1fcf3da985
commit 52d45da3f2
12 changed files with 57 additions and 62 deletions

View File

@ -1,3 +1,25 @@
2016-09-30 Alan Modra <amodra@gmail.com>
* 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.
2016-09-28 Akihiko Odaki <akihiko.odaki.4i@stu.hosei.ac.jp>
PR ld/20636

View File

@ -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)

View File

@ -41,6 +41,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)
@ -6928,14 +6929,12 @@ const char *bfd_errmsg (bfd_error_type error_tag);
void bfd_perror (const char *message);
typedef void (*bfd_error_handler_type) (const char *, ...);
typedef void (*bfd_error_handler_type) (const char *, va_list);
bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
void bfd_set_error_program_name (const char *);
bfd_error_handler_type bfd_get_error_handler (void);
typedef void (*bfd_assert_handler_type) (const char *bfd_formatmsg,
const char *bfd_version,
@ -6944,8 +6943,6 @@ typedef void (*bfd_assert_handler_type) (const char *bfd_formatmsg,
bfd_assert_handler_type bfd_set_assert_handler (bfd_assert_handler_type);
bfd_assert_handler_type bfd_get_assert_handler (void);
long bfd_get_reloc_upper_bound (bfd *abfd, asection *sect);
long bfd_canonicalize_reloc

View File

@ -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;
}
@ -840,23 +847,6 @@ bfd_set_error_program_name (const char *name)
_bfd_error_program_name = 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

View File

@ -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)
{
}

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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. */

View File

@ -114,9 +114,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. */

View File

@ -1,3 +1,7 @@
2016-09-30 Alan Modra <amodra@gmail.com>
* ldlang.c (ignore_bfd_errors): Update params.
2016-09-29 H.J. Lu <hongjiu.lu@intel.com>
PR ld/20528

View File

@ -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. */
}