diff options
author | Alan Modra <amodra@gmail.com> | 2022-12-15 23:07:10 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-12-17 18:44:42 +1030 |
commit | 499766a6d77994259b3cdff602d8f38d014d08ce (patch) | |
tree | 5b10ac14d8383a3250baaa6fe3b02e913be16cc4 /bfd/elfcode.h | |
parent | 6e09ae77a199fe3a8ed814355eec7bb105a42ed4 (diff) | |
download | binutils-499766a6d77994259b3cdff602d8f38d014d08ce.zip binutils-499766a6d77994259b3cdff602d8f38d014d08ce.tar.gz binutils-499766a6d77994259b3cdff602d8f38d014d08ce.tar.bz2 |
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.
Diffstat (limited to 'bfd/elfcode.h')
-rw-r--r-- | bfd/elfcode.h | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/bfd/elfcode.h b/bfd/elfcode.h index 1392240..7a4de82 100644 --- a/bfd/elfcode.h +++ b/bfd/elfcode.h @@ -326,8 +326,8 @@ elf_swap_shdr_in (bfd *abfd, || dst->sh_size > filesize - dst->sh_offset) && !abfd->read_only) { - const char **warn = _bfd_per_xvec_warn (abfd->xvec); - *warn = _("warning: %pB has a section extending past end of file"); + _bfd_error_handler (_("warning: %pB has a section " + "extending past end of file"), abfd); abfd->read_only = 1; } } @@ -773,8 +773,8 @@ elf_object_p (bfd *abfd) i_ehdrp->e_shstrndx = SHN_UNDEF; if (!abfd->read_only) { - const char **warn = _bfd_per_xvec_warn (abfd->xvec); - *warn = _("warning: %pB has a corrupt string table index"); + _bfd_error_handler + (_("warning: %pB has a corrupt string table index"), abfd); abfd->read_only = 1; } } @@ -821,9 +821,8 @@ elf_object_p (bfd *abfd) i_phdr->p_align &= -i_phdr->p_align; if (!abfd->read_only) { - const char **warn = _bfd_per_xvec_warn (abfd->xvec); - *warn = _("warning: %pB has a program header " - "with invalid alignment"); + _bfd_error_handler (_("warning: %pB has a program header " + "with invalid alignment"), abfd); abfd->read_only = 1; } } |