Bug 29692 - Support binaries with empty symbol table
authorDodji Seketeli <dodji@redhat.com>
Wed, 22 Mar 2023 12:50:20 +0000 (13:50 +0100)
committerDodji Seketeli <dodji@redhat.com>
Wed, 22 Mar 2023 14:32:10 +0000 (15:32 +0100)
Some binaries can have a symbol table in which no symbol is actually
defined and exported.  That binary would thus have an empty ABI
corpus.

Interestingly, Libabigail's DWARF reader is emits an error when
it encounters such binaries.

This patch adds the support for those binaries.

* src/abg-dwarf-reader.cc (reader::read_debug_info_into_corpus):
Get out early also upon having an empty symbol table.
* src/abg-elf-reader.cc (reader::read_corpus): Error out only if
there is no symbol table for the binary.  If an empty symbol table
is found however, that is not an error.
* tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0:
New binary test input.
* tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0.abi:
New expected abixml file.
* tests/data/Makefile.am: Add the new input test files to source
distribution.
* tests/test-read-dwarf.cc (in_out_specs): Add the new test inputs
above to this test harness.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
src/abg-dwarf-reader.cc
src/abg-elf-reader.cc
tests/data/Makefile.am
tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0 [new file with mode: 0755]
tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0.abi [new file with mode: 0644]
tests/test-read-dwarf.cc

index 66b99fd5a9843016515ca5473fb107892082051f..d842d25b53866b99171f558114e8cffcbf4901f5 100644 (file)
@@ -2130,8 +2130,10 @@ public:
     // Set symbols information to the corpus.
     corpus()->set_symtab(symtab());
 
-    // Get out now if no debug info is found.
-    if (!dwarf_debug_info())
+    // Get out now if no debug info is found or if the symbol table is
+    // empty.
+    if (!dwarf_debug_info()
+       || !corpus()->get_symtab()->has_symbols())
       return corpus();
 
     uint8_t address_size = 0;
index 57e7f2dcf6bf7be96922b85afc46b4c70d78daf6..101df0dc07832ba23b2a85cf4dab42cc99e22332 100644 (file)
@@ -958,10 +958,13 @@ reader::read_corpus(status& status)
   corpus()->set_architecture_name(elf_architecture());
 
   // See if we could find symbol tables.
-  if (!symtab() || !symtab()->has_symbols())
+  if (!symtab())
     {
       status |= STATUS_NO_SYMBOLS_FOUND;
-      // We found no ELF symbol, so we can't handle the binary.
+      // 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();
     }
 
index aafa41de1d487f9a9d017694e90c3b9d23d50a31..f2d0c0ca81d80c55ae490e038ec83afc12a278ea 100644 (file)
@@ -666,6 +666,8 @@ test-read-dwarf/PR29443-missing-xx.o.abi \
 test-read-dwarf/test-fallback.abi      \
 test-read-dwarf/test-fallback.c                \
 test-read-dwarf/test-fallback.o                \
+test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0 \
+test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0.abi \
 \
 test-read-ctf/test0            \
 test-read-ctf/test0.abi                \
diff --git a/tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0 b/tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0
new file mode 100755 (executable)
index 0000000..b92f4ef
Binary files /dev/null and b/tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0 differ
diff --git a/tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0.abi b/tests/data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0.abi
new file mode 100644 (file)
index 0000000..e2b3e14
--- /dev/null
@@ -0,0 +1,2 @@
+<abi-corpus version='2.1' soname='libkjava.so.1'>
+</abi-corpus>
index 5a00e14ef36117e5fd78e8dfc9c6d8ec8e11c59a..d2d2ec6d32267b366fe630891cc6bcfd5c8b2fe9 100644 (file)
@@ -550,6 +550,15 @@ static InOutSpec in_out_specs[] =
     "output/test-read-dwarf/PR29443-missing-xx.o.abi",
     NULL,
   },
+  {
+    "data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0",
+    "",
+    "",
+    SEQUENCE_TYPE_ID_STYLE,
+    "data/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0.abi",
+    "output/test-read-dwarf/PR29692-kdelibs3-libkjava.so.1.0.0.abi",
+    NULL,
+  },
   // DWARF fallback feature.
   {
     "data/test-read-dwarf/test-fallback.o",