btf-reader: Fix re-use of the BTF reader for several binaries in a row

Message ID
State New
Series btf-reader: Fix re-use of the BTF reader for several binaries in a row |

Commit Message

Dodji Seketeli May 31, 2024, 4:29 p.m. UTC

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/ (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 <>
Applying to the master branch.
 src/ | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)


diff --git a/src/ b/src/
index 1cf92dfb..a8131fd7 100644
--- a/src/
+++ b/src/
@@ -238,8 +238,9 @@  protected:
 	     bool			load_all_types,
 	     bool			linux_kernel_mode)
-    elf_based_reader::initialize(elf_path, debug_info_root_paths);
+    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:
+    btf_handle_ = nullptr;
   /// Read the ELF information as well as the BTF type information to
@@ -346,7 +348,8 @@  public:
-    btf_handle();
+    if (!btf_handle())
+      return corpus_sptr();
     translation_unit_sptr artificial_tu
       (new translation_unit(env(), "", /*address_size=*/64));