public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] btf-reader: Fix re-use of the BTF reader for several binaries in a row
@ 2024-05-31 16:29 Dodji Seketeli
  0 siblings, 0 replies; only message in thread
From: Dodji Seketeli @ 2024-05-31 16:29 UTC (permalink / raw)
  To: libabigail

Hello,

When analyzing a Linux Kernel tree, the BTF reader needs to be reset
after each binary (vmlinux or module) read.  It turns out the reset
was not being done properly.  Fixed thus.  Also, I noticed that
reader::read_debug_info_into_corpus would not return an empty corpus
when no BTF information was found in the binary.  Fixed as well.

	* src/abg-btf-reader.cc (reader::initialize): Free the btf handle
	first thing as part of the re-initialization.
	(reader::~reader): Once the BTF handle has been freed, set it to
	nil to show that it's been deleted.
	(reader::read_debug_info_into_corpus): If no BTF handle could be
	retrieved then it means no BTF data was found on the binary.
	Thus, return an empty corpus.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
Applying to the master branch.
---
 src/abg-btf-reader.cc | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/abg-btf-reader.cc b/src/abg-btf-reader.cc
index 1cf92dfb..a8131fd7 100644
--- a/src/abg-btf-reader.cc
+++ b/src/abg-btf-reader.cc
@@ -238,8 +238,9 @@ protected:
 	     bool			load_all_types,
 	     bool			linux_kernel_mode)
   {
-    elf_based_reader::initialize(elf_path, debug_info_root_paths);
     btf__free(btf_handle_);
+    btf_handle_ = nullptr;
+    elf_based_reader::initialize(elf_path, debug_info_root_paths);
     options().load_all_types = load_all_types;
     options().load_in_linux_kernel_mode = linux_kernel_mode;
   }
@@ -305,6 +306,7 @@ public:
   ~reader()
   {
     btf__free(btf_handle_);
+    btf_handle_ = nullptr;
   }
 
   /// Read the ELF information as well as the BTF type information to
@@ -346,7 +348,8 @@ public:
   corpus_sptr
   read_debug_info_into_corpus()
   {
-    btf_handle();
+    if (!btf_handle())
+      return corpus_sptr();
 
     translation_unit_sptr artificial_tu
       (new translation_unit(env(), "", /*address_size=*/64));
-- 
2.43.0


-- 
		Dodji


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

only message in thread, other threads:[~2024-05-31 16:29 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-31 16:29 [PATCH] btf-reader: Fix re-use of the BTF reader for several binaries in a row Dodji Seketeli

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).