From patchwork Fri May 31 16:29:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 91261 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 726B2384188C for ; Fri, 31 May 2024 16:29:35 +0000 (GMT) X-Original-To: libabigail@sourceware.org Delivered-To: libabigail@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id DCD2E3858C56 for ; Fri, 31 May 2024 16:29:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DCD2E3858C56 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org DCD2E3858C56 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717172971; cv=none; b=xNk2lDX1ybXoCl4RIJ0XU5PfYcwNXoZBen/QsuW79o9S17DEBRNCBPUWD+9N4V8Guob6ojNWbQTGwO0VFqiIQiR4NttM743TRFs23lh/ALqATsLMKVM7VEy5Srno+Fbf/bsgo7CVqXEXjFlgCBbAjnrOLfEPcg8US0lX6yYx6E8= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1717172971; c=relaxed/simple; bh=tedcE9X6tX54nH3Et4yPANK1MsmL0jDVbsq3Xn7mytI=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=gceukINj4Dz5T27WT7nnJQw3UQWMbqcppkZXGBC0VbadieNMEYOdQWI7o+BjivRsklxunynoaqNPW0WHvoZkgyMJiG7hxzG2LpX9Xq7HqJJ1MJ2+Tu/Nnppa2KajcXREZii+BlvHTGPdQF/syLGcdp8Yz3WV3NV1wwwifB9iJpo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717172969; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type; bh=Dm5XcGexuH1sojuT/TrOE5fUAA1FkC2gLoH1hqRDQxU=; b=UDeowGlsjnoJV5loxZSHUNcgFHOyFZs9Kp8XdiEVyLhEtoZ9wegI9pQw9lduQ+S02Z+bqQ E9VNrDOu2SeAULWzbrAKGE0MDhM8kHH3y4wT0Zsk80pPbASfoj2qd2HbYdNZJIIvJ3/Niy W3ZWhMhZ9Du3EXV8d30YkUrt/9kZb2o= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-GzS5eJ2xNGutJHjM5AvmQg-1; Fri, 31 May 2024 12:29:28 -0400 X-MC-Unique: GzS5eJ2xNGutJHjM5AvmQg-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-792ff5345c6so191536785a.1 for ; Fri, 31 May 2024 09:29:27 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1717172967; x=1717777767; h=mime-version:user-agent:message-id:date:organization:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Dm5XcGexuH1sojuT/TrOE5fUAA1FkC2gLoH1hqRDQxU=; b=jm75r1/6fNEVMX9YaKO2AY4mjEa0gSWA+qgt8J+TtSyGR7K6zrqukdedG6+bKF5TH2 z5DD+qNAN/+Xtugyk3Eqgl2NJXVEzFRhIq0rbOl9u0WngXwWS7t8WLByWDxIKM75seHW yPLhifb2aTDDUcVBGVn4077weGWKvOdEy/7EdWL5HnfCBBzG5FOHXi8apT0f4eEFlttx p93T0sojf8JeeBwEMoP4gpkkHEeTGuWPnXBKU2YBUrIJQ47skQi03BBnPurBybuex9qd 5ww5Ba5QxUoFdFXOpbncAFZbXTwGlypDpv5/8P5SmAYbzV/1L4YejMGck8Kzh8OYXhFi belg== X-Gm-Message-State: AOJu0YypZZn8qfLbRBrrkmRtQAJ8mgeIWEmSwBiF2X6cADmjoTfTGRvV 7eiL1/1X4Ij2YCh0OVae948WXOnElBBeUHEmYT/J55r9a8MpHtjPfGpfa9CmuB+ShWdseEkOXdG e2cCNA3VRzsIJG1a6orDrrUPrF048Gxyq46jTG+dkMWJyh4JwZGP8MstoILxWe34iUYbHS4BaCR rq62s4IuFand7MwY0AP60ROBcPCE0jQaUI7g7/oA== X-Received: by 2002:a05:620a:5e09:b0:792:ffd6:1f8b with SMTP id af79cd13be357-794f5c863aemr231162685a.23.1717172966971; Fri, 31 May 2024 09:29:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH8CKmr+1IgPVSaZhW/n2L9SMuLuEYHLRxTSnRjs3t59m9ZHPcISgS6PTrfw8SMwToXh6AU3g== X-Received: by 2002:a05:620a:5e09:b0:792:ffd6:1f8b with SMTP id af79cd13be357-794f5c863aemr231159885a.23.1717172966419; Fri, 31 May 2024 09:29:26 -0700 (PDT) Received: from localhost (88-120-130-27.subs.proxad.net. [88.120.130.27]) by smtp.gmail.com with ESMTPSA id af79cd13be357-794f305f7e3sm69142585a.79.2024.05.31.09.29.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 31 May 2024 09:29:26 -0700 (PDT) Received: by localhost (Postfix, from userid 1000) id 7C51B507A61B; Fri, 31 May 2024 18:29:24 +0200 (CEST) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH] btf-reader: Fix re-use of the BTF reader for several binaries in a row Organization: Red Hat / France X-Operating-System: AlmaLinux 9.4 X-URL: http://www.redhat.com Date: Fri, 31 May 2024 18:29:24 +0200 Message-ID: <87ed9it063.fsf@redhat.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_WEB, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 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 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));