public inbox for libabigail@sourceware.org
 help / color / mirror / Atom feed
From: dodji@redhat.com
To: libabigail@sourceware.org
Cc: dodji@redhat.com
Subject: [PATCH 07/17] ctf-reader: Fix analyzing single kernel binaries
Date: Tue, 16 Jul 2024 16:55:18 +0200	[thread overview]
Message-ID: <20240716145541.473065-8-dodji@redhat.com> (raw)
In-Reply-To: <20240716145541.473065-1-dodji@redhat.com>

From: Dodji Seketeli <dodji@redhat.com>

Analyzing a single kernel binary has been broken for a long time, it
seems.  For the record, I mean this:

    $ abidw --ctf vmlinux > vmlinux.ctf.abi

Doesn't work.

This patch fixes ctf::reader::slurp_elf_info to make it not crash on
binaries that have no CTF sections because there is a .ctfa file in
the same directory.

Also, it fixes ctf::reader::read_corpus to support loading the CTF
archive for individual kernel binaries and not just for entire trees
(corpus groups).  In the case of individual kernel binaries, the
archive can be built from the CTF sections of the binary.

	* src/abg-ctf-reader.cc (reader::slurp_elf_info): Do not crash on
	a kernel binary that has no CTF section because the CTF
	information is in a .ctfa file in the same directory.
	(reader::read_corpus): Support loading a CTF archive for a single
	kernel binary.  Also, support loading the CTF archive from the CTF
	sections in the binary itself not necessarily from a .ctfa file in
	the same directory.

Signed-off-by: Dodji Seketeli <dodji@redhat.com>
---
 src/abg-ctf-reader.cc | 51 ++++++++++++++++++++++++-------------------
 1 file changed, 28 insertions(+), 23 deletions(-)

diff --git a/src/abg-ctf-reader.cc b/src/abg-ctf-reader.cc
index c93608ca..fd5a8a58 100644
--- a/src/abg-ctf-reader.cc
+++ b/src/abg-ctf-reader.cc
@@ -383,15 +383,6 @@ public:
     elf::reader::read_corpus(status);
 
     corpus_sptr corp = corpus();
-    if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
-	&& corpus_group())
-      {
-	// Not finding any debug info so far is expected if we are
-	// building a kABI.
-        status &= static_cast<abigail::fe_iface::status>
-                    (~STATUS_DEBUG_INFO_NOT_FOUND);
-	return;
-      }
 
     if ((status & STATUS_NO_SYMBOLS_FOUND)
 	|| !(status & STATUS_OK))
@@ -415,17 +406,29 @@ public:
       }
 
     const Elf_Scn* ctf_scn = find_ctf_section();
-    fill_ctf_section(ctf_scn, &ctf_sect);
+    if (ctf_scn)
+      fill_ctf_section(ctf_scn, &ctf_sect);
 
     const Elf_Scn* symtab_scn =
       elf_helpers::find_section_by_name(elf_handle(), symtab_name);
-    fill_ctf_section(symtab_scn, &symtab_sect);
+    if (symtab_scn)
+      fill_ctf_section(symtab_scn, &symtab_sect);
 
     const Elf_Scn* strtab_scn =
       elf_helpers::find_section_by_name(elf_handle(), strtab_name);
-    fill_ctf_section(strtab_scn, &strtab_sect);
+    if (strtab_scn)
+      fill_ctf_section(strtab_scn, &strtab_sect);
 
-    status |= fe_iface::STATUS_OK;
+    if (ctf_scn && symtab_scn && strtab_scn)
+      status |= fe_iface::STATUS_OK;
+    else if (corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
+      {
+	// Not finding any debug info so far is expected if we are
+	// building a kABI.
+        status &= static_cast<abigail::fe_iface::status>
+                    (~STATUS_DEBUG_INFO_NOT_FOUND);
+	return;
+      }
   }
 
   /// Process a CTF archive and create libabigail IR for the types,
@@ -690,8 +693,7 @@ public:
       t.start();
 
     int errp;
-    if ((corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
-	&& corpus_group())
+    if (corp->get_origin() & corpus::LINUX_KERNEL_BINARY_ORIGIN)
       {
 	if (ctfa == nullptr)
 	  {
@@ -700,14 +702,17 @@ public:
 	      ctfa = ctf_arc_open(ctfa_filename.c_str(), &errp);
 	  }
       }
-    else
-      /* Build the ctfa from the contents of the relevant ELF sections,
-	 and process the CTF archive in the read context, if any.
-	 Information about the types, variables, functions, etc contained
-	 in the archive are added to the given corpus.  */
-      if (ctfa == nullptr)
-	ctfa = ctf_arc_bufopen(&ctf_sect, &symtab_sect,
-			       &strtab_sect, &errp);
+
+    /* Build the ctfa from the contents of the relevant ELF sections,
+       and process the CTF archive in the read context, if any.
+       Information about the types, variables, functions, etc contained
+       in the archive are added to the given corpus.  */
+    if (ctfa == nullptr
+	&& ctf_sect.cts_data
+	&& symtab_sect.cts_data
+	&& strtab_sect.cts_data)
+      ctfa = ctf_arc_bufopen(&ctf_sect, &symtab_sect,
+			     &strtab_sect, &errp);
 
     if (do_log())
       {
-- 
2.43.5


  parent reply	other threads:[~2024-07-16 14:55 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-16 14:55 [PATCH 00/17] Support self comparison of vmlinux & modules using BTF/CTF dodji
2024-07-16 14:55 ` [PATCH 01/17] ir: Fix a potential crash in canonicalize_types dodji
2024-07-16 14:55 ` [PATCH 02/17] elf-based-reader: Clean up logic of elf_based_reader::read_and_add_corpus_to_group dodji
2024-07-16 14:55 ` [PATCH 03/17] tools-utils,btf-reader: Take modules into account for corpus group dodji
2024-07-16 14:55 ` [PATCH 04/17] corpus: Support adding translation units with empty path dodji
2024-07-16 14:55 ` [PATCH 05/17] ctf-reader: Do not set data member offsets for unions dodji
2024-07-16 14:55 ` [PATCH 06/17] ctf-reader: During re-initialization, only clear canonicalize-able types dodji
2024-07-16 14:55 ` dodji [this message]
2024-07-16 14:55 ` [PATCH 08/17] reader: Fix corpus group reading dodji
2024-07-16 14:55 ` [PATCH 09/17] reader: Simplify type canonicalization invocation dodji
2024-07-16 14:55 ` [PATCH 10/17] reader: Simplify logic of get_or_read_and_add_translation_unit dodji
2024-07-16 14:55 ` [PATCH 11/17] reader: Fix building of void and void pointer types dodji
2024-07-16 14:55 ` [PATCH 12/17] reader: Fix building of variadic parameter type dodji
2024-07-16 14:55 ` [PATCH 13/17] ir: Don't strip typedefs from parms and return type when comparing fns dodji
2024-07-16 14:55 ` [PATCH 14/17] ir: Rename integral_type into real_type dodji
2024-07-16 14:55 ` [PATCH 15/17] ir,comparison,default-reporter: Consider sub-ranges in array diffs dodji
2024-07-16 14:55 ` [PATCH 16/17] abidw: Support the --abidiff option for Linux Kernel trees dodji
2024-07-16 14:55 ` [PATCH 17/17] configure: Support the optional 'big-tests' sub-directory dodji

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240716145541.473065-8-dodji@redhat.com \
    --to=dodji@redhat.com \
    --cc=libabigail@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).