[PATCH 1/3] Make several more BFD globals thread-local
Alan Modra
amodra@gmail.com
Sat Mar 9 04:11:13 GMT 2024
On Fri, Mar 08, 2024 at 06:12:34PM -0700, Tom Tromey wrote:
> >>>>> "Tom" == Tom Tromey <tom@tromey.com> writes:
> Tom> Also I think it'd be good if print_warnmsg re-emitted the errors using
> Tom> _bfd_error_handler. This would let gdb print them the way it likes.
> Tom> However... that's a change to semantics so I don't know if that's OK or
> Tom> whether another error emitter is required. I guess I don't really know
> Tom> how to provoke one of these messages and when they would matter.
See 5aa0f10c424e commit log.
The testcase in https://oss-fuzz.com/testcase-detail/4772285297328128
is the one that prompted all the messing around with errors. Try
objdump or nm from 2.36 on that one..
> I'd appreciate some insight into this.
Yes, print_warnmsg should indeed be using _bfd_error_handler. Both
calls to print_warnmsg are preceeded by setting the error handler back
to the original one.
This also fixes a duplicate program name output.
* bfd.c (bfd_print_error): Make static. Don't print program name.
(error_handler_fprintf): Print program name here.
* format.c (print_warnmsg): Use _bfd_error_handler to print
cached messages.
* bfd-in2.h: Regenerate.
diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
index 79b24a7f6e9..76d450478a7 100644
--- a/bfd/bfd-in2.h
+++ b/bfd/bfd-in2.h
@@ -2558,9 +2558,6 @@ void bfd_perror (const char *message);
typedef void (*bfd_error_handler_type) (const char *, va_list);
typedef int (*bfd_print_callback) (void *, const char *, ...);
-void bfd_print_error (bfd_print_callback print_func,
- void *stream, const char *fmt, va_list ap);
-
void _bfd_error_handler (const char *fmt, ...) ATTRIBUTE_PRINTF_1;
bfd_error_handler_type bfd_set_error_handler (bfd_error_handler_type);
diff --git a/bfd/bfd.c b/bfd/bfd.c
index 71732a0f92b..1bdfac6c24c 100644
--- a/bfd/bfd.c
+++ b/bfd/bfd.c
@@ -1449,31 +1449,12 @@ _bfd_doprnt_scan (const char *format, va_list ap, union _bfd_doprnt_args *args)
return arg_count;
}
-/*
-FUNCTION
- bfd_print_error
-
-SYNOPSIS
- void bfd_print_error (bfd_print_callback print_func,
- void *stream, const char *fmt, va_list ap);
-
-DESCRIPTION
-
- This formats FMT and AP according to BFD "printf" rules,
- sending the output to STREAM by repeated calls to PRINT_FUNC.
- PRINT_FUNC is a printf-like function; it does not need to
- implement the BFD printf format extensions. This can be used
- in a callback that is set via bfd_set_error_handler to turn
- the error into ordinary output.
-*/
-
-void
+static void
bfd_print_error (bfd_print_callback print_func, void *stream,
const char *fmt, va_list ap)
{
union _bfd_doprnt_args args[MAX_ARGS];
- print_func (stream, "%s: ", _bfd_get_error_program_name ());
_bfd_doprnt_scan (fmt, ap, args);
_bfd_doprnt (print_func, stream, fmt, args);
}
@@ -1486,6 +1467,7 @@ error_handler_fprintf (const char *fmt, va_list ap)
/* PR 4992: Don't interrupt output being sent to stdout. */
fflush (stdout);
+ fprintf (stderr, "%s: ", _bfd_get_error_program_name ());
bfd_print_error ((bfd_print_callback) fprintf, stderr, fmt, ap);
/* On AIX, putc is implemented as a macro that triggers a -Wunused-value
diff --git a/bfd/format.c b/bfd/format.c
index 47c3e9ba35a..8f3fc7e7b96 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -255,15 +255,8 @@ bfd_preserve_finish (bfd *abfd ATTRIBUTE_UNUSED, struct bfd_preserve *preserve)
static void
print_warnmsg (struct per_xvec_message **list)
{
- fflush (stdout);
- fprintf (stderr, "%s: ", _bfd_get_error_program_name ());
-
for (struct per_xvec_message *warn = *list; warn; warn = warn->next)
- {
- fputs (warn->message, stderr);
- fputc ('\n', stderr);
- }
- fflush (stderr);
+ _bfd_error_handler ("%s", warn->message);
}
static void
--
Alan Modra
Australia Development Lab, IBM
More information about the Binutils
mailing list