From patchwork Thu Jun 1 00:30:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 101626 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:6358:3046:b0:115:7a1d:dabb with SMTP id p6csp796866rwl; Wed, 31 May 2023 17:30:20 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4LR1GG30N8ynNOoa2UuiwnLm/tQijy6hc/C1WanLcAf5K+LeCVqogXICk/Tt16vIhMkYYh X-Received: by 2002:a19:f60e:0:b0:4d5:8306:4e9a with SMTP id x14-20020a19f60e000000b004d583064e9amr307641lfe.46.1685579420416; Wed, 31 May 2023 17:30:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685579420; cv=none; d=google.com; s=arc-20160816; b=oeKnSFxtlT/3IEiBpQyVbdvLXKFU20s5Uj9qQjgT4fiqgWxOZVAAyEx5GipYdMiNXI Gs3OsR7ml4aFQDAwxD27NLgjwQmqmyHj0Qe3f2QuuB7bOaZrIUXCma9bEX3vcK2xTveQ 30IOVqgye8/ILMhPRCj4aJmhtXlqouRUEJJN97hmmiQhtFTzoE2cBdmoOkuv0fty08Zk AiBn9Icsqm/PJK1sCosTKlvf0n1BC5QRG1ool9ZYGB/fos/NUqcl8kBeshLQDeSUdhHk CTSXQ8f/w1qA1em6TzahYnPRORpeDh9ylYIMqdaUVDdCgdJHi+wht5rs80ZiKARs3GVk A4lQ== 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=64E0v/2ZLalWf6lHuISe43ksi/1AwKBW2Bl1Zg3UIV0=; b=zL1ijOOfMq9xMFW5v90+VIUPaEH7EHW4abozKBG98EAheZjNHtrgfstjFEJIQxaUh+ gYqC4JTvG3DzpHroumGYU3SuE9OwDu3ElFDxVZSnYCNkl7aB6eM7NfGsUS0BMMRkzI2C xFX9dx4Nj6Jixb8J8a2mlmUCKz5THJVa/g4s18CCVYwchOjiHYdxHHKi1TzBFxCC26KM Nxq7Bb7OqXLzd79JWYL61xiNzq1DXOBQgKi55fooFcyKy2zJvCsIagzYm/0bXFyBbK0D FNLmIyK5BGBwGcSvfCPEWf/rciC3o8IZwXZyQxn3cfVgh+3HWPmhS29+4hICXFBeq9BH 2dkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=kPPpT6pJ; 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 d21-20020a056402079500b00514b1b04bf1si232324edy.318.2023.05.31.17.30.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 17:30:20 -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=kPPpT6pJ; 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 49F9A3858423 for ; Thu, 1 Jun 2023 00:30:19 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49F9A3858423 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1685579419; bh=64E0v/2ZLalWf6lHuISe43ksi/1AwKBW2Bl1Zg3UIV0=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kPPpT6pJgZLzdbtXDv0kZxxI3lev3vDqdo4XwOD5NcgLNUU0xEUNwYwmO0vjitvbD c53ECEaAxzzYQwgH4utvmZnultoz87ceSEAQ/0Vhe0LSlCUaJxSvHmhf7o0g0ZITai rjMJpxERDMVyHuxapipl3WLDWetGn3suKO5nVU5E= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-oi1-x233.google.com (mail-oi1-x233.google.com [IPv6:2607:f8b0:4864:20::233]) by sourceware.org (Postfix) with ESMTPS id F17523858D20 for ; Thu, 1 Jun 2023 00:30:09 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org F17523858D20 Received: by mail-oi1-x233.google.com with SMTP id 5614622812f47-38dec65ab50so116306b6e.2 for ; Wed, 31 May 2023 17:30:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685579409; x=1688171409; 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=64E0v/2ZLalWf6lHuISe43ksi/1AwKBW2Bl1Zg3UIV0=; b=JRqJsYRCPerS3MaOH6nolyKQ+m+B3edofMw7GsslJKh94/lfAFmy4ZH9XENxTsGsyb j08t7PwKdtmEIYCpLdUngU+cMrR+ueBPiTpSTeo39jMvtYa38FyZEzXIIh5ScTKCkHCe qPLa3BsggLM0ic/JLHl1H4RWOl67fe90XnmnwvvgusWDpj7vejibKHobsL9iBv55cz0U dr5rzhC4AOtLSiMOjx39QwCaiZp5xeXrMRtcbr/IJJhED8TJGkW2ygxJ+ONONrLgLnQo 2DHNVicVAyyI+AS+uDbtj2KMH0vNtG11OjwnZVPDtgLwl1A3FAdMpxfVBw6X5WROt3bE +dhQ== X-Gm-Message-State: AC+VfDxFA0d0C6aO/A9nU4BLvubxBjblP7Vz60Vx7YLt92TR77mLcVT1 SkDgE9gFlTx9IpNQ+XgMyNevcXs8prM= X-Received: by 2002:a05:6808:302a:b0:398:43a3:cde4 with SMTP id ay42-20020a056808302a00b0039843a3cde4mr6173441oib.27.1685579408714; Wed, 31 May 2023 17:30:08 -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 u7-20020aa78487000000b0064358d032a4sm3977667pfn.145.2023.05.31.17.30.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 May 2023 17:30:08 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 6FD83114209E; Thu, 1 Jun 2023 10:00:05 +0930 (ACST) Date: Thu, 1 Jun 2023 10:00:05 +0930 To: binutils@sourceware.org Subject: section_by_target_index memory leak 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?1767458126159391085?= X-GMAIL-MSGID: =?utf-8?q?1767458126159391085?= The rs6000 backend can call coff_section_from_bfd_index from its object_p function via coff_set_alignment_hook. If the object doesn't match, or another target matches too, then the hash table needs to be freed via a cleanup. * coffgen.c (coff_object_cleanup): New function. (coff_real_object_p): Return coff_object_cleanup, and call on failure path. Move declaration to.. * libcoff-in.h: ..here. (coff_object_cleanup): Declare. * coff-stgo32.c (go32exe_cleanup): Call coff_object_cleanup. (go32exe_check_format): Adjust assertion. * libcoff.h: Regenerate. diff --git a/bfd/coff-stgo32.c b/bfd/coff-stgo32.c index f443a30c7b1..707b80963da 100644 --- a/bfd/coff-stgo32.c +++ b/bfd/coff-stgo32.c @@ -248,6 +248,7 @@ static void go32exe_cleanup (bfd *abfd) { abfd->origin = 0; + coff_object_cleanup (abfd); free (go32exe_temp_stub); go32exe_temp_stub = NULL; @@ -323,7 +324,7 @@ go32exe_check_format (bfd *abfd) bfd_cleanup cleanup = coff_object_p (abfd); if (cleanup == NULL) goto fail; - BFD_ASSERT (cleanup == _bfd_no_cleanup); + BFD_ASSERT (cleanup == coff_object_cleanup); return go32exe_cleanup; diff --git a/bfd/coffgen.c b/bfd/coffgen.c index c81f67c1711..afc663c056f 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -281,14 +281,25 @@ make_a_section_from_file (bfd *abfd, return result; } +void +coff_object_cleanup (bfd *abfd) +{ + if (bfd_family_coff (abfd) && bfd_get_format (abfd) == bfd_object) + { + struct coff_tdata *td = coff_data (abfd); + if (td != NULL) + { + if (td->section_by_index) + htab_delete (td->section_by_index); + if (td->section_by_target_index) + htab_delete (td->section_by_target_index); + } + } +} + /* Read in a COFF object and make it into a BFD. This is used by ECOFF as well. */ bfd_cleanup -coff_real_object_p (bfd *, - unsigned, - struct internal_filehdr *, - struct internal_aouthdr *); -bfd_cleanup coff_real_object_p (bfd *abfd, unsigned nscns, struct internal_filehdr *internal_f, @@ -358,9 +369,10 @@ coff_real_object_p (bfd *abfd, } _bfd_coff_free_symbols (abfd); - return _bfd_no_cleanup; + return coff_object_cleanup; fail: + coff_object_cleanup (abfd); _bfd_coff_free_symbols (abfd); bfd_release (abfd, tdata); fail2: diff --git a/bfd/libcoff-in.h b/bfd/libcoff-in.h index 24a950dedd4..96f44512ac5 100644 --- a/bfd/libcoff-in.h +++ b/bfd/libcoff-in.h @@ -331,6 +331,10 @@ struct decoration_hash_entry }; /* Functions in coffgen.c. */ +extern void coff_object_cleanup + (bfd *); +extern bfd_cleanup coff_real_object_p + (bfd *, unsigned, struct internal_filehdr *, struct internal_aouthdr *); extern bfd_cleanup coff_object_p (bfd *); extern struct bfd_section *coff_section_from_bfd_index diff --git a/bfd/libcoff.h b/bfd/libcoff.h index c5d15a13f7b..61561c5a471 100644 --- a/bfd/libcoff.h +++ b/bfd/libcoff.h @@ -335,6 +335,10 @@ struct decoration_hash_entry }; /* Functions in coffgen.c. */ +extern void coff_object_cleanup + (bfd *); +extern bfd_cleanup coff_real_object_p + (bfd *, unsigned, struct internal_filehdr *, struct internal_aouthdr *); extern bfd_cleanup coff_object_p (bfd *); extern struct bfd_section *coff_section_from_bfd_index