public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
From: Alan Modra <amodra@gmail.com>
To: binutils@sourceware.org
Subject: Downgrade nm fatal errors to non-fatal
Date: Mon, 6 Mar 2023 13:58:47 +1030	[thread overview]
Message-ID: <ZAVd75QsC9WDKjib@squeak.grove.modra.org> (raw)

Many of the fatal errors in nm ought to be recoverable.  This patch
downgrades most of them.  The ones that are left are most likely due
to memory allocation failures.

	* nm.c (print_symdef_entry): Don't bomb with a fatal error
	on a corrupted archive symbol table.
	(filter_symbols): Silently omit symbols that return NULL
	from bfd_minisymbol_to_symbol rather than giving a fatal
	error.
	(display_rel_file): Don't give a fatal error on
	bfd_read_minisymbols returning an error, or on not being able
	to read dynamic symbols for synth syms.
	(display_archive): Downgrade bfd_openr_next_archived_file
	error.
	(display_file): Don't bomb on a bfd_close failure.

diff --git a/binutils/nm.c b/binutils/nm.c
index 2c428d20fdf..8b6b249a951 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -736,19 +736,19 @@ print_symdef_entry (bfd *abfd)
        idx != BFD_NO_MORE_SYMBOLS;
        idx = bfd_get_next_mapent (abfd, idx, &thesym))
     {
-      bfd *elt;
       if (!everprinted)
 	{
 	  printf (_("\nArchive index:\n"));
 	  everprinted = true;
 	}
-      elt = bfd_get_elt_at_index (abfd, idx);
-      if (elt == NULL)
-	bfd_fatal ("bfd_get_elt_at_index");
-      if (thesym->name != (char *) NULL)
+      if (thesym->name != NULL)
 	{
 	  print_symname ("%s", NULL, thesym->name, abfd);
-	  printf (" in %s\n", bfd_get_filename (elt));
+	  bfd *elt = bfd_get_elt_at_index (abfd, idx);
+	  if (elt)
+	    printf (" in %s\n", bfd_get_filename (elt));
+	  else
+	    printf ("\n");
 	}
     }
 }
@@ -781,9 +781,9 @@ filter_symbols (bfd *abfd, bool is_dynamic, void *minisyms,
       int keep = 0;
       asymbol *sym;
 
-      sym = bfd_minisymbol_to_symbol (abfd, is_dynamic, (const void *) from, store);
+      sym = bfd_minisymbol_to_symbol (abfd, is_dynamic, from, store);
       if (sym == NULL)
-	bfd_fatal (bfd_get_filename (abfd));
+	continue;
 
       if (sym->name != NULL
 	  && sym->name[0] == '_'
@@ -1405,19 +1405,7 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
     }
 
   symcount = bfd_read_minisymbols (abfd, dynamic, &minisyms, &size);
-  if (symcount < 0)
-    {
-      if (dynamic && bfd_get_error () == bfd_error_no_symbols)
-	{
-	  if (!quiet)
-	    non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
-	  return;
-	}
-
-      bfd_fatal (bfd_get_filename (abfd));
-    }
-
-  if (symcount == 0)
+  if (symcount <= 0)
     {
       if (!quiet)
 	non_fatal (_("%s: no symbols"), bfd_get_filename (abfd));
@@ -1449,7 +1437,7 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
 	      dyn_syms = (asymbol **) xmalloc (storage);
 	      dyn_count = bfd_canonicalize_dynamic_symtab (abfd, dyn_syms);
 	      if (dyn_count < 0)
-		bfd_fatal (bfd_get_filename (abfd));
+		dyn_count = 0;
 	    }
 	}
 
@@ -1588,7 +1576,7 @@ display_archive (bfd *file)
       if (arfile == NULL)
 	{
 	  if (bfd_get_error () != bfd_error_no_more_archived_files)
-	    bfd_fatal (bfd_get_filename (file));
+	    bfd_nonfatal (bfd_get_filename (file));
 	  break;
 	}
 
@@ -1664,7 +1652,7 @@ display_file (char *filename)
 
   free_lineno_cache (file);
   if (!bfd_close (file))
-    bfd_fatal (filename);
+    retval = false;
 
   return retval;
 }

-- 
Alan Modra
Australia Development Lab, IBM

                 reply	other threads:[~2023-03-06  3:28 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZAVd75QsC9WDKjib@squeak.grove.modra.org \
    --to=amodra@gmail.com \
    --cc=binutils@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).