From patchwork Thu Jun 1 00:31:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 101627 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp797534rwl; Wed, 31 May 2023 17:31:48 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4FgvfDk8wSDvX35ZnlFaM/bugaP5t8A8jGo66H+2vsvoDtJNVPPeIwjTzX7RPtxASwhfTm X-Received: by 2002:a17:907:7f13:b0:973:7ee0:e641 with SMTP id qf19-20020a1709077f1300b009737ee0e641mr5710395ejc.72.1685579508362; Wed, 31 May 2023 17:31:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685579508; cv=none; d=google.com; s=arc-20160816; b=DeKFJ4P7FSXap5wvrPj0Kw3yFuuG5KWBQEplmr7XQrYtWYVRMskW0fncm4dSRM/11p x0GWrmse+N+nL+TpXGvXdKWBQh6jYMgCz+5Wv5Nu9h/ejxhrC10AXI5ErNgYxdPZyizl DuUBmur98uulCPXGxUO9gKQN1Hac1obMhfkFBcMuyCkaDkCBcrSE3tFHlyCb1JDeuXrI ENgfMq3I0COUlc+MypQZPbDfX1BvpeJUFl/930J6iQHykv0MmvrCnSLeWbhzBUtJ9xNO er5M3t0XB65b8cUt1pL+YBhPbSz/4zTft+I4ke7jnqa3F5JXWFN3w/miartEc2XNdoSE 4Xlg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=IbzWhDbxh01h5+D2fxigWXrAYSPiVcTTERE4VZN8Xc0=; b=g1A0dI6upuJtNR3sGTTqHNHBbe4fGVjXgjr3Ac9XDs8A2QCKjVxJWtRgieuUPCyOCC QZAVQqhewR+Qi/HutJCBynChH2T138wJdzp6Y3bhy8LkH23lfwMNE9OezqGx0epXD+ez tcn4ZcI/hzWH2aITVZxh6nXc6Ged194Vq5nd6oh6+C3/6B/98jeLBziS2RzXShvLrR0b 1fHqs4zhdIocVrpXYabCdcX/+ZLhoUF+bqG36PiNqttmY3+ugb9kDAP9snKrFJtTr9wt H3P+31wrnQVsO+B+qKlyuuJl7GfT8XIQk+7/6LdItemmuDzQh7j03wglSE7AOsw+hCyF EzUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=WR4WJvXn; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ss8-20020a170907c00800b009618d4710f6si2319714ejc.552.2023.05.31.17.31.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 17:31:48 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=WR4WJvXn; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 461B63857C66 for ; Thu, 1 Jun 2023 00:31:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 461B63857C66 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685579507; bh=IbzWhDbxh01h5+D2fxigWXrAYSPiVcTTERE4VZN8Xc0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=WR4WJvXn8QkXsP6HWoQ4m640VfiCF0rYxmIXrh5YIkOgJsJ7s4xArRhU+J6RTv52j TaU4tFwqpziBdS+ocTqbo/yqLbP/o8r4vwR0nBZiHNYaL5Iw1Xst9TtD5osN2IJBAa j6E79RR4MuSp4eJyeE31ecKDavHh6p/KhDgEOlEs= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-oi1-x22d.google.com (mail-oi1-x22d.google.com [IPv6:2607:f8b0:4864:20::22d]) by sourceware.org (Postfix) with ESMTPS id DDCE53858D20 for ; Thu, 1 Jun 2023 00:31:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org DDCE53858D20 Received: by mail-oi1-x22d.google.com with SMTP id 5614622812f47-39a3f2668bdso128977b6e.2 for ; Wed, 31 May 2023 17:31:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685579499; x=1688171499; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IbzWhDbxh01h5+D2fxigWXrAYSPiVcTTERE4VZN8Xc0=; b=GopsVpy5gCe1iiJfBEe7Ze+ReGbN/cO8TOfjiJtbgVf3H1wg88E+GXYfOHVg6hiDV+ 6Nh93jiLirAkBqNisG806/pod9dpZFrbhzPCQ7RnIpGwgRYjOh78NRx0r5f4Ori/0C/v 2mS4tyZBFB+//nxPnf4sTcabJUD0i8EztTrtxj949aItUVsizb02Xz3RTTyWbtwo3ax0 KRKM3OFLyVx2o9MNHiwnbJpu6DkWiOIxQ3SqRl7eu2aAKrYlxncLIBYwCzqI4ibkV8d2 mt+/YsTnHOccAAKL9CT4uUW/kJhjLeLh1m2Sj2UWoFcZsNyO9QgtiRoI/GbGwy0q3z9h 8QgA== X-Gm-Message-State: AC+VfDxouieOhamOZTW577TrONGmmHSsrZVp/PVSyuf6RdjDbmOuRPA9 D0eicqNEyka+hHDIHcgQKkmXic+N0zw= X-Received: by 2002:aca:6155:0:b0:397:f86d:3024 with SMTP id v82-20020aca6155000000b00397f86d3024mr5278399oib.15.1685579498811; Wed, 31 May 2023 17:31:38 -0700 (PDT) Received: from squeak.grove.modra.org (158.106.96.58.static.exetel.com.au. [58.96.106.158]) by smtp.gmail.com with ESMTPSA id f4-20020aa78b04000000b0063d2cd02d69sm3885301pfd.54.2023.05.31.17.31.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 17:31:38 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id B2C90114209E; Thu, 1 Jun 2023 10:01:35 +0930 (ACST) Date: Thu, 1 Jun 2023 10:01:35 +0930 To: binutils@sourceware.org Subject: bfd_close and target free_cached_memory Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3034.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Alan Modra via Binutils From: Alan Modra Reply-To: Alan Modra Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767458218463583629?= X-GMAIL-MSGID: =?utf-8?q?1767458218463583629?= bfd_free_cached_info is used in just one place in archive.c, which means most times we reach bfd_close the function isn't called. On the other hand, if bfd_free_cached_info is called we can't do much on the bfd since it loses all its obj_alloc memory. This restricts what can be done in a target _close_and_cleanup. In particular you can't look at sections, which leads to duplication of code in target close_and_cleanup and free_cached_info, eg. elfnn-aarch64.c. * opncls.c (_bfd_delete_bfd): Call bfd_free_cached_info. * elfnn-aarch64.c (elfNN_aarch64_close_and_cleanup): Delete. (bfd_elfNN_close_and_cleanup): Don't define. * som.c (som_bfd_free_cached_info): Don't call _bfd_generic_close_and_cleanup here. (som_close_and_cleanup): Define as _bfd_generic_close_and_cleanup. diff --git a/bfd/elfnn-aarch64.c b/bfd/elfnn-aarch64.c index 32799b6b009..3ad5cb95b40 100644 --- a/bfd/elfnn-aarch64.c +++ b/bfd/elfnn-aarch64.c @@ -8735,16 +8735,6 @@ unrecord_section_via_map_over_sections (bfd *abfd ATTRIBUTE_UNUSED, unrecord_section_with_aarch64_elf_section_data (sec); } -static bool -elfNN_aarch64_close_and_cleanup (bfd *abfd) -{ - if (abfd->sections) - bfd_map_over_sections (abfd, - unrecord_section_via_map_over_sections, NULL); - - return _bfd_elf_close_and_cleanup (abfd); -} - static bool elfNN_aarch64_bfd_free_cached_info (bfd *abfd) { @@ -10263,9 +10253,6 @@ const struct elf_size_info elfNN_aarch64_size_info = #define ELF_MAXPAGESIZE 0x10000 #define ELF_COMMONPAGESIZE 0x1000 -#define bfd_elfNN_close_and_cleanup \ - elfNN_aarch64_close_and_cleanup - #define bfd_elfNN_bfd_free_cached_info \ elfNN_aarch64_bfd_free_cached_info diff --git a/bfd/opncls.c b/bfd/opncls.c index f0064954bf3..b0c23b4201c 100644 --- a/bfd/opncls.c +++ b/bfd/opncls.c @@ -156,6 +156,11 @@ _bfd_new_bfd_contained_in (bfd *obfd) static void _bfd_delete_bfd (bfd *abfd) { + /* Give the target _bfd_free_cached_info a chance to free memory. */ + if (abfd->memory) + bfd_free_cached_info (abfd); + + /* The target _bfd_free_cached_info may not have done anything.. */ if (abfd->memory) { bfd_hash_table_free (&abfd->section_htab); diff --git a/bfd/som.c b/bfd/som.c index 0780b235e0e..ef1f6dc3eb6 100644 --- a/bfd/som.c +++ b/bfd/som.c @@ -6813,7 +6813,9 @@ som_bfd_free_cached_info (bfd *abfd) #undef FREE } - return _bfd_generic_close_and_cleanup (abfd); + /* Do not call _bfd_free_cached_info here. som_write_armap needs + to access the bfd obj_alloc memory. */ + return true; } /* End of miscellaneous support functions. */ @@ -6828,7 +6830,7 @@ som_bfd_link_split_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec) #define som_find_line _bfd_nosymbols_find_line #define som_get_symbol_version_string _bfd_nosymbols_get_symbol_version_string -#define som_close_and_cleanup som_bfd_free_cached_info +#define som_close_and_cleanup _bfd_generic_close_and_cleanup #define som_read_ar_hdr _bfd_generic_read_ar_hdr #define som_write_ar_hdr _bfd_generic_write_ar_hdr #define som_openr_next_archived_file bfd_generic_openr_next_archived_file