public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Downgrade nm fatal errors to non-fatal
@ 2023-03-06  3:28 Alan Modra
  0 siblings, 0 replies; only message in thread
From: Alan Modra @ 2023-03-06  3:28 UTC (permalink / raw)
  To: binutils

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

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

only message in thread, other threads:[~2023-03-06  3:28 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-06  3:28 Downgrade nm fatal errors to non-fatal 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).