public inbox for binutils-cvs@sourceware.org
 help / color / mirror / Atom feed
* [binutils-gdb] Error messages emitted during bfd_check_format_matches
@ 2024-06-17 13:03 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2024-06-17 13:03 UTC (permalink / raw)
  To: binutils-cvs

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=2df6e967098a2f48a83a2ec6000a9c53b493c737

commit 2df6e967098a2f48a83a2ec6000a9c53b493c737
Author: Alan Modra <amodra@gmail.com>
Date:   Sat Jun 15 07:43:08 2024 +0930

    Error messages emitted during bfd_check_format_matches
    
    Error/warning messages are only printed for the target that
    successfully matched, which makes sense for warnings, but not so much
    for errors where the errors cause no target to match.  I noticed this
    when looking at the pr20520 testcase again with objdump, which just
    reports "file format not recognized" omitting the five "SHT_GROUP
    section [index n] has no SHF_GROUP sections" messages.  They are
    omitted because multiple ELF targets match the object file.  This is
    going to be true for all ELF objects due to at least the proper ELF
    target and the generic ELF target matching.
    
            * format.c (print_and_clear_messages): Print messages if all
            targets with messages have exactly the same set of messages.

Diff:
---
 bfd/format.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/bfd/format.c b/bfd/format.c
index 443fc6dbde0..d0af388ab45 100644
--- a/bfd/format.c
+++ b/bfd/format.c
@@ -282,20 +282,40 @@ clear_warnmsg (struct per_xvec_message **list)
 /* Free all the storage in LIST.  Note that the first element of LIST
    is special and is assumed to be stack-allocated.  TARG is used for
    re-issuing warning messages.  If TARG is PER_XVEC_NO_TARGET, then
-   it acts like a sort of wildcard -- messages are only reissued if
-   they are all associated with a single BFD target, regardless of
-   which one it is.  If TARG is anything else, then only messages
-   associated with TARG are emitted.  */
+   it acts like a sort of wildcard -- messages are reissued if all
+   targets with messages have identical messages.  One copy of the
+   messages are then reissued.  If TARG is anything else, then only
+   messages associated with TARG are emitted.  */
 
 static void
 print_and_clear_messages (struct per_xvec_messages *list,
 			  const bfd_target *targ)
 {
-  struct per_xvec_messages *iter = list;
+  struct per_xvec_messages *iter;
 
-  if (targ == PER_XVEC_NO_TARGET && list->next == NULL)
-    print_warnmsg (&list->messages);
+  if (targ == PER_XVEC_NO_TARGET)
+    {
+      iter = list->next;
+      while (iter != NULL)
+	{
+	  struct per_xvec_message *msg1 = list->messages;
+	  struct per_xvec_message *msg2 = iter->messages;
+	  do
+	    {
+	      if (strcmp (msg1->message, msg2->message))
+		break;
+	      msg1 = msg1->next;
+	      msg2 = msg2->next;
+	    } while (msg1 && msg2);
+	  if (msg1 || msg2)
+	    break;
+	  iter = iter->next;
+	}
+      if (iter == NULL)
+	targ = list->targ;
+    }
 
+  iter = list;
   while (iter != NULL)
     {
       struct per_xvec_messages *next = iter->next;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-06-17 13:03 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-17 13:03 [binutils-gdb] Error messages emitted during bfd_check_format_matches Alan Modra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).