From patchwork Tue Jan 16 09:00:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dodji Seketeli X-Patchwork-Id: 84167 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 D3F863858D38 for ; Tue, 16 Jan 2024 09:00:52 +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.133.124]) by sourceware.org (Postfix) with ESMTPS id 6076D3858C29 for ; Tue, 16 Jan 2024 09:00:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 6076D3858C29 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 6076D3858C29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705395632; cv=none; b=FP/skDsus+cSfwueW4OvdHlofQ5c8QFQOZAGU2+abnVScekrjpCQnWpXARvkewfg86rPsZgsI0qpTTsXQ6xWTj2INoY/52TW8fQdvCjWlgp5+/Nc2P2w2+1pvpT7r9aTdw5WU1eQCv9pTmIS1V/xyfMhp1e7fwLACeBPsRU11is= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1705395632; c=relaxed/simple; bh=BK6z71ClrKG0wMmxc6tT9lKFUkeRpHLAdaF1oJezzOs=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=VyCBPocpj2aBOd8LfQmziLc3E016hHWj/2klhxpF4EuydO1eQkQ3SEGpAK/4XyTGrRWk3x4iMHqjSVCEQaEbNuG9Ss8wryhsG7jVNYmFD4sWuYmNHK5VX1AAPf21K2ZKAzh++nJXjSwLGawgl7QOXxSIynT6OKE3V3ky87wGWXs= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1705395614; 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=OuewmqAES6+PUjYjALS+AHSjZK7TJtNkdej5Xe3q3eE=; b=GPczmabSiL9BoYGLKmUnVP6vIgMj/xo6E07RGXwBGMYQeaulGNR8BK/AvDMdp7jboitKGP C5hcwYf9nx7fcFK1NoTzR4apzJgrnbKmmJlESSuQmDSo8r3WRGYX/3lULofLLOLMTHkrvg xmU4vahRitPStJYCcdZQfWThyoy44tU= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-etjpiDKAMrCcA5GgNmylWA-1; Tue, 16 Jan 2024 04:00:12 -0500 X-MC-Unique: etjpiDKAMrCcA5GgNmylWA-1 Received: by mail-qk1-f200.google.com with SMTP id af79cd13be357-78315f41c6cso1373835085a.1 for ; Tue, 16 Jan 2024 01:00:12 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1705395612; x=1706000412; 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=OuewmqAES6+PUjYjALS+AHSjZK7TJtNkdej5Xe3q3eE=; b=gWZUXjYaagifEix8+OVx0S7e5stKJIVJ54z5UyzPd78Loq/CUp7VbfogAcn8h+mwok 32ecYTV84DXnDNSkshXCmE3n5pn3DsMeNYTKtq1IAj7yINx+diC2fywsFXu6HNWYZ8uM Ox7IT4IWJQgvL1HGuRskg7bHjV5V89/KXtqBJup/0mJlKyC5/J4ahmLlyTWN2OdEmBDf D4Corut4Z/UH5RxVjxL32gC4YpNJBHLFNWTPydyXJG/o+UrJzT5VGUvY6iNakHdEaxEE aHk6xYuUbSBJMRAr5GwQnwreRfh8NKsCKJb3tBtnQROxiVqI+XhwdpenTNAa8RFzkMul A0LQ== X-Gm-Message-State: AOJu0YyoSsAvrWlvrjCrRLK6R2U9Ylb8BfXG1HEfrIyXRC+gFeEljZ0P 3cP/vS3G+mGS6wHdjplCWCbhKPebhzRAvB+RVBk7MBTNwllnzXDzH3yBvn/aU5PlNH//pZoVbZE j4Ca9J8A1uil7o48I/zkIbaJZbUahSAA7p/FfMzIlIPmh+ubIGbX7bcfiaBsWDzzfXVgC7kssLP 7mgBVAvsCe X-Received: by 2002:a05:620a:558c:b0:781:5b96:537f with SMTP id vq12-20020a05620a558c00b007815b96537fmr6940408qkn.114.1705395611965; Tue, 16 Jan 2024 01:00:11 -0800 (PST) X-Google-Smtp-Source: AGHT+IHoESGgRuSjd489KL1KCc7OoJGQeqxtqlNcYTbp0adMpcSlmZJQaqac0ea5UbUpTSmWrUypxQ== X-Received: by 2002:a05:620a:558c:b0:781:5b96:537f with SMTP id vq12-20020a05620a558c00b007815b96537fmr6940396qkn.114.1705395611596; Tue, 16 Jan 2024 01:00:11 -0800 (PST) Received: from localhost (88-120-130-27.subs.proxad.net. [88.120.130.27]) by smtp.gmail.com with ESMTPSA id a22-20020a05620a103600b0078314f2144bsm3573084qkk.44.2024.01.16.01.00.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Jan 2024 01:00:11 -0800 (PST) Received: by localhost (Postfix, from userid 1000) id 73C465077C47; Tue, 16 Jan 2024 10:00:08 +0100 (CET) From: Dodji Seketeli To: libabigail@sourceware.org Subject: [PATCH, applied] Bug 31236 - Fix removing a member declaration from its scope Organization: Red Hat / France X-Operating-System: AlmaLinux 9.3 X-URL: http://www.redhat.com Date: Tue, 16 Jan 2024 10:00:08 +0100 Message-ID: <87le8pr6uf.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=-12.8 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_H3, RCVD_IN_MSPIKE_WL, 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, In some C++ binaries, DWARF can represent a member variable using a global variable /definition/ DIE not having a reference attribute pointing back to the member variable declaration DIE. The only way we know that the global variable is a definition DIE for a member variable is because its linkage name demangles to "foo::bar::var_name", with foo::bar being a class name. So, for each translation unit, when the DWARF reader reads a global variable DIE, it builds a variable IR node for it and stashes it on the side. Then, when the translation unit is built, the DWARF reader looks at all the stashed global variables, detects those that are actually member variables and adds them to their class. But then, before adding a (former global) variable to its class, the reader has first to remove it from its global scope. This removal is done by the function remove_decl_from_scope, which calls scope_decl::remove_member_decl. The issue here is that remove_decl_from_scope forgets to unset the translation unit property of the global variable. Then, in the particular case of this problem report, when scope_decl::add_member_decl is called to add the variable to its class, it detects that the variable belongs to /another/ translation unit and (rightfully) aborts. Ooops. This patch fixes the issue by making remove_decl_from_scope remove the variable from its translation unit too, not just from its scope. The patch actually delegates the scope & translation unit resetting to scope_decl::remove_member_decl because it appears to me that this is where these ought to be handled. To ensure that the issue is fixed, one needs to unpack the package webkit2gtk3-2.40.5-1.el9_3.1.x86_64.rpm and run abidw on the binary $prefix/usr/lib64/libwebkit2gtk-4.0.so.37 like: $ abidw --noout $prefix/usr/lib64/libwebkit2gtk-4.0.so.37 Given the size of the library, this takes three hours and a half as well as ~50GB of ram to complete on my system using a non-optimized debug build of libabigail. We definitely need to invest in more speed optimizations to handle webkit. That would be for another day, I guess. * src/abg-ir.cc (scope_decl::remove_member_decl): Reset the translation unit and the scope of the removed decl. (remove_decl_from_scope): Do not reset the scope of the removed decl here as it's now done above. Signed-off-by: Dodji Seketeli Applied to master. --- src/abg-ir.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/abg-ir.cc b/src/abg-ir.cc index 56d71465..81549bbf 100644 --- a/src/abg-ir.cc +++ b/src/abg-ir.cc @@ -8288,6 +8288,9 @@ scope_decl::remove_member_decl(decl_base_sptr member) } } } + + member->set_scope(nullptr); + member->set_translation_unit(nullptr); } /// Return the hash value for the current instance of scope_decl. @@ -8526,7 +8529,6 @@ remove_decl_from_scope(decl_base_sptr decl) scope_decl* scope = decl->get_scope(); scope->remove_member_decl(decl); - decl->set_scope(0); } /// Inserts a declaration into a given scope, before a given IR child