From patchwork Tue Jul 16 14:55:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 93999 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 47609384477B for ; Tue, 16 Jul 2024 14:56:35 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by sourceware.org (Postfix) with ESMTPS id 5DABA3846425 for ; Tue, 16 Jul 2024 14:55:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5DABA3846425 Authentication-Results: sourceware.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=seketeli.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 5DABA3846425 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=217.70.183.197 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721141750; cv=none; b=DG8ehgOGYHZpah3QxY+gJHJDbEqp4ySN3gArHf95yh3gZsH34cVAkv2np7f0AvcwxElTBMmSYEHOwqic9pchMJ4F2jHgqTD7f8ymvk2ACbETxurSdvzzHYWDxQKC0c4jsLFX8t8izzT3haxsgNhAuuFT09iyvci7lRjgWNJCD9w= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1721141750; c=relaxed/simple; bh=FlPKcopuWeazEXjnHAb9tDOpmBxdoRCR5WGXSlVBnEo=; h=From:To:Subject:Date:Message-ID:MIME-Version; b=bhU77zH5kkqSOZc2iPWaN5VLMbB7XRzNEvwHsWWDoNGD1jSac+jCjoWq1meoWSQM9F7alV7mCr6AY8X4OVpuFcKeFDBBBKKr4kK4JlgtvaOFGJpiXdh3t5OWrqkXYLWZ+cWIFZEAQ0+ksLkfTylrru/AvaTnPyc/beURSvijbxA= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail.gandi.net (Postfix) with ESMTPSA id 1893C1C0008; Tue, 16 Jul 2024 14:55:42 +0000 (UTC) Received: by localhost (Postfix, from userid 1000) id 400FCC1B7B49; Tue, 16 Jul 2024 16:55:41 +0200 (CEST) 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 Message-ID: <20240716145541.473065-8-dodji@redhat.com> X-Mailer: git-send-email 2.43.5 In-Reply-To: <20240716145541.473065-1-dodji@redhat.com> References: <20240716145541.473065-1-dodji@redhat.com> MIME-Version: 1.0 X-GND-Sasl: dodj@seketeli.org X-Spam-Status: No, score=-11.6 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libabigail@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Mailing list of the Libabigail project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libabigail-bounces~patchwork=sourceware.org@sourceware.org From: Dodji Seketeli 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 --- 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 - (~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 + (~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()) {