[binutils-gdb] Don't lose actual error in _bfd_generic_read_minisymbols

Alan Modra via Binutils-cvs <[email protected]>
Newsgroups gmane.comp.gnu.binutils.cvs
Message-ID <[email protected]>
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=a29213cde57c5674cbdda7f5349199a0a9779ae3

commit a29213cde57c5674cbdda7f5349199a0a9779ae3
Author: Alan Modra <[email protected]>
Date:   Thu Mar 5 09:15:17 2026 +1030

    Don't lose actual error in _bfd_generic_read_minisymbols
    
    Setting bfd_error_no_symbols in the error return loses the underlying
    reason why the function failed.  Also fix a few places where functions
    called by _bfd_generic_read_minisymbols didn't set bfd_error on failure.
    
            * syms.c (_bfd_generic_read_minisymbols): Don't bfd_set_error
            here.
            * aoutx.h (aout_get_external_symbols): Call bfd_set_error on
            error return.
            * pdp11.c (aout_get_external_symbols): Likewise.
            * ecoff.c (_bfd_ecoff_slurp_symbolic_info): Likewise.

Diff:
---
 bfd/aoutx.h | 5 ++++-
 bfd/ecoff.c | 2 +-
 bfd/pdp11.c | 5 ++++-
 bfd/syms.c  | 1 -
 4 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/bfd/aoutx.h b/bfd/aoutx.h
index f081a6c5054..cb2d9270db9 100644
--- a/bfd/aoutx.h
+++ b/bfd/aoutx.h
@@ -1289,7 +1289,10 @@ static bool
 aout_get_external_symbols (bfd *abfd)
 {
   if (bfd_get_flavour (abfd) != bfd_target_aout_flavour)
-    return false;
+    {
+      bfd_set_error (bfd_error_invalid_operation);
+      return false;
+    }
 
   if (obj_aout_external_syms (abfd) == NULL)
     {
diff --git a/bfd/ecoff.c b/bfd/ecoff.c
index 7ddce8be6d2..50e42afed18 100644
--- a/bfd/ecoff.c
+++ b/bfd/ecoff.c
@@ -650,7 +650,7 @@ _bfd_ecoff_slurp_symbolic_info (bfd *abfd,
   fraw_src = (char *) debug->external_fdr;
   /* PR 17512: file: 3372-1243-0.004.  */
   if (fraw_src == NULL && internal_symhdr->ifdMax > 0)
-    return false;
+    goto err;
   fraw_end = fraw_src + internal_symhdr->ifdMax * external_fdr_size;
   for (; fraw_src < fraw_end; fraw_src += external_fdr_size, fdr_ptr++)
     (*backend->debug_swap.swap_fdr_in) (abfd, (void *) fraw_src, fdr_ptr);
diff --git a/bfd/pdp11.c b/bfd/pdp11.c
index 6472e2741f1..d1d761d9adb 100644
--- a/bfd/pdp11.c
+++ b/bfd/pdp11.c
@@ -1265,7 +1265,10 @@ static bool
 aout_get_external_symbols (bfd *abfd)
 {
   if (bfd_get_flavour (abfd) != bfd_target_aout_flavour)
-    return false;
+    {
+      bfd_set_error (bfd_error_invalid_operation);
+      return false;
+    }
 
   if (obj_aout_external_syms (abfd) == NULL)
     {
diff --git a/bfd/syms.c b/bfd/syms.c
index f990c2b3a6a..c43ee2da00e 100644
--- a/bfd/syms.c
+++ b/bfd/syms.c
@@ -858,7 +858,6 @@ _bfd_generic_read_minisymbols (bfd *abfd,
   return symcount;
 
  error_return:
-  bfd_set_error (bfd_error_no_symbols);
   free (syms);
   return -1;
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.