[07/16] {dwarf,elf}reader: Don't consider no symbol table as an error

Message ID 87msxyf6ds.fsf@redhat.com
State New
Headers
Series Fixing various issues found while working on PR30309 |

Commit Message

Dodji Seketeli Sept. 7, 2023, 1:41 p.m. UTC
  Hello,

Some binaries don't have any symbol table.  Libabigail's ELF and DWARF
readers error out on those binaries, making fedabipkgdiff emitting an
error when performing the self-comparison of the package containing
those binaries.

This patch handles a binary having no symbol table almost as a binary
that has an empty symbol table, making abipkgdiff and fedabipkgdiff
not error out on those binaries anymore.

This makes the command below succeed:

    $ fedabipkgdiff --self-compare -a --from fc34 glibc

	* src/abg-dwarf-reader.cc (reader::read_corpus): Return an empty
	corpus if no symbol was found. Do not crash when no symbol table
	is found.
	* src/abg-elf-reader.cc (reader::read_corpus): Consider a corpus
	with no symbol table as being OK.
	* src/abg-reader.cc (build_elf_symbol_from_reference): Do not
	crash when no symbol table is present.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applied to master.
---
 src/abg-dwarf-reader.cc | 11 ++++++-----
 src/abg-elf-reader.cc   |  8 ++++----
 src/abg-reader.cc       | 13 ++++++++-----
 3 files changed, 18 insertions(+), 14 deletions(-)
  

Patch

diff --git a/src/abg-dwarf-reader.cc b/src/abg-dwarf-reader.cc
index 6e472d3a..2416c7f3 100644
--- a/src/abg-dwarf-reader.cc
+++ b/src/abg-dwarf-reader.cc
@@ -2072,12 +2072,12 @@  public:
     // Load the generic ELF parts of the corpus.
     elf::reader::read_corpus(status);
 
-    if ((status & STATUS_NO_SYMBOLS_FOUND)
-	|| !(status & STATUS_OK))
-      // Either we couldn't find ELF symbols or something went badly
-      // wrong.  There is nothing we can do with this ELF file.  Bail
-      // out.
+    if (!(status & STATUS_OK))
+      {
+	// Something went badly wrong.  There is nothing we can do
+	// with this ELF file.  Bail out.
       return corpus_sptr();
+      }
 
     // If we couldn't find debug info from the elf path, then say it.
     if (dwarf_debug_info() == nullptr)
@@ -2143,6 +2143,7 @@  public:
     // Get out now if no debug info is found or if the symbol table is
     // empty.
     if (!dwarf_debug_info()
+	|| !corpus()->get_symtab()
 	|| !corpus()->get_symtab()->has_symbols())
       return corpus();
 
diff --git a/src/abg-elf-reader.cc b/src/abg-elf-reader.cc
index 7884c672..f4dae766 100644
--- a/src/abg-elf-reader.cc
+++ b/src/abg-elf-reader.cc
@@ -978,12 +978,12 @@  reader::read_corpus(status& status)
   // See if we could find symbol tables.
   if (!symtab())
     {
-      status |= STATUS_NO_SYMBOLS_FOUND;
+      status |= STATUS_NO_SYMBOLS_FOUND | STATUS_OK;
       // We found no ELF symbol, so we can't handle the binary.  Note
       // that we could have found a symbol table with no defined &
-      // exported ELF symbols in it.  That case is handled as an empty
-      // corpus, which is different from this case.
-      return corpus_sptr();
+      // exported ELF symbols in it.  Both cases are handled as an
+      // empty corpus.
+      return corpus();
     }
 
   // Set symbols information to the corpus.
diff --git a/src/abg-reader.cc b/src/abg-reader.cc
index 520d158a..2b902096 100644
--- a/src/abg-reader.cc
+++ b/src/abg-reader.cc
@@ -3272,12 +3272,15 @@  build_elf_symbol_from_reference(reader& rdr, const xmlNodePtr node)
       if (name.empty())
 	return nil;
 
-      const elf_symbols& symbols =
-	  rdr.corpus()->get_symtab()->lookup_symbol(name);
+      if (rdr.corpus()->get_symtab())
+	{
+	  const elf_symbols& symbols =
+	    rdr.corpus()->get_symtab()->lookup_symbol(name);
 
-      for (const auto& symbol : symbols)
-	if (symbol->get_id_string() == sym_id)
-	  return symbol;
+	  for (const auto& symbol : symbols)
+	    if (symbol->get_id_string() == sym_id)
+	      return symbol;
+	}
     }
 
   return nil;