]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commit
Re: The problem with warning in elf_object_p
authorAlan Modra <amodra@gmail.com>
Thu, 15 Dec 2022 12:37:10 +0000 (23:07 +1030)
committerAlan Modra <amodra@gmail.com>
Sat, 17 Dec 2022 08:14:42 +0000 (18:44 +1030)
commit499766a6d77994259b3cdff602d8f38d014d08ce
tree5b10ac14d8383a3250baaa6fe3b02e913be16cc4
parent6e09ae77a199fe3a8ed814355eec7bb105a42ed4
Re: The problem with warning in elf_object_p

Commit 5aa0f10c424e added a per_xvec_warn array to provide support for
warnings from elf_object_p (and a later patch for warnings from
pe_bfd_object_p) to be cached and then only printed if the target
matches.  It was quite limited in the style of message supported, only
one message could be printed, and didn't really meet the stated aim of
only warning when a target matches:  There are many other errors and
warnings that can be emitted by functions called from elf_object_p.

So this patch extends the error handler functions to support printing
to a string buffer, extends per_xvec_warn to support multiple errors/
warnings, and hooks this all into bfd_check_format_matches.  If
bfd_check_format_matches succeeds then any errors/warnings are printed
for the matching target.  If bfd_check_format_matches fails either due
to no match or to multiple matches and only one target vector produced
errors, then those errors are printed.

* bfd.c (MAX_ARGS): Define, use throughout.
(print_func): New typedef.
(_bfd_doprnt): Add new print param.  Replace calls to fprintf
with print.
(PRINT_TYPE): Similarly.
(error_handler_fprintf): Renamed from error_handler_internal.
Use _bfd_get_error_program_name.  Add fprintf arg.  Move code
setting up args..
(_bfd_doprnt_scan): ..to here.  Add ap param.
(struct buf_stream): New.
(err_sprintf): New function.
(error_handler_bfd): New static variable.
(error_handler_sprintf): New function.
(_bfd_set_error_handler_caching): New function.
(_bfd_get_error_program_name): New function.
* elfcode.h (elf_swap_shdr_in): Use _bfd_error_handler in
warning messages.
(elf_object_p): Likewise.
* format.c (print_warnmsg): New function.
(clear_warnmsg): Rewrite.
(null_error_handler): New function.
(bfd_check_format_matches): Ignore warnings from recursive calls
checking first element of an archive.  Use caching error handler
otherwise.  Print warnings on successful match, or when only one
target has emitted warnings/errors.
* peicode.h (pe_bfd_object_p): Use _bfd_error_handler in
warning messages.
* targets.c (per_xvec_warn): Change type of array elements.
(struct per_xvec_message): New.
(_bfd_per_xvec_warn): Rewrite.
* Makefile.am (LIBBFD_H_FILES): Add bfd.c.
* Makefile.in: Regenerate.
* bfd-in2.h: Regenerate.
* libbfd.h: Regenerate.
bfd/Makefile.am
bfd/Makefile.in
bfd/bfd-in2.h
bfd/bfd.c
bfd/elfcode.h
bfd/format.c
bfd/libbfd.h
bfd/peicode.h
bfd/targets.c