From patchwork Sun Aug 27 04:43:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 136968 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:a7d1:0:b0:3f2:4152:657d with SMTP id p17csp2663865vqm; Sat, 26 Aug 2023 21:43:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGQC7AgKua/6P7jsFaoAmDKbXkU3E7aHSTFYYfDF/r6VLgRCVqqqDRuSwrNRmkIjd3Lg9g8 X-Received: by 2002:a05:6512:3e1a:b0:500:b102:d1c6 with SMTP id i26-20020a0565123e1a00b00500b102d1c6mr2095977lfv.47.1693111436369; Sat, 26 Aug 2023 21:43:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1693111436; cv=none; d=google.com; s=arc-20160816; b=PZSHjhCHluBGjv5nIVpG/ItpQhj0WNE2txo+RcBqD8GM8XdRUVqW7wyNFQySziI24V 9UarUmOMnyt7YUIGD2HKYUQpwAL4o2v/ldI5NqjKJUeNksHu+h/26UaV1/1FFsH2EG/5 lu0J4wBEtcAF05jWJBhwCm3y0evIdGgETLfSHwbWpldBUnIUnVPBNxNajBBIhpcOnoI5 OAP8LugBDywe5825X8NlGo3eQXS+v2FqJJQhsCTjKhww+ITBSZFqqToCjP4/OIDEeyRn 0g8cDBcOctXOdXOK359EUHM7GSltithH6+vVRitGSSk+8ib9sm/RXe5UOOXf6tw4SZkh bKuQ== 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=qYlJ18YkKq172cfPGdcC3lSDTiyYriIqHwqfrprBtDo=; fh=NLxAvL/bDfPg4AGOtxqvQlND8vazkZrNzKLY8+LAbBY=; b=cTz98BBp3+sywT9uG+4Sn5cTBDOfYXubHJX3LL8sULu6UoZWneCkA6ynjYNhJZtwea II2RpUkmh+Sm/hqxECG2y81e/LnonPgk1NvLgF13gP2Wl71P6BrYeedN4zGuZRW9kpyi MRA+PxH8l06vbswMt0xQngdVX72J9gASZlVZ/ic3F7X6CoNJN638RYOcvdId9fubTDSE gEdckAtA+oRrf3uogFSsgBWSEpGCObeCsIbOdZ6SaaadRepKbrrXV6MU++Xg1V3KwxvZ UO5Zqb9pyyCYl7I2UfWOYiUD9qtmjKDCFLlz51XleXR5DeuGaX7GDPf0ENknIqaAqXyD ECkw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=wCcpgIlN; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id y22-20020aa7ccd6000000b005255ce1d55csi869161edt.203.2023.08.26.21.43.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Aug 2023 21:43:56 -0700 (PDT) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=wCcpgIlN; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c 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 101DB3858C41 for ; Sun, 27 Aug 2023 04:43:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 101DB3858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1693111435; bh=qYlJ18YkKq172cfPGdcC3lSDTiyYriIqHwqfrprBtDo=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=wCcpgIlNgDb55dvGuz9anCQez0PHyW7jB6uYNqbqR6R9LXHEGmgfGhm4uQ6L91fNb p60eQAzBew0EtXqdG2v5gnSQ5wa1lg79POkzO2s2tZgHaKWQ0aW7NuvwHXY0tm1Xt8 YjdawgEkudpbiqs3Lboc0SQaizmicujjcoB1bO7I= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by sourceware.org (Postfix) with ESMTPS id E84E63858D3C for ; Sun, 27 Aug 2023 04:43:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E84E63858D3C Received: by mail-pf1-x433.google.com with SMTP id d2e1a72fcca58-68a4bcf8a97so1376378b3a.1 for ; Sat, 26 Aug 2023 21:43:46 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693111425; x=1693716225; 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=qYlJ18YkKq172cfPGdcC3lSDTiyYriIqHwqfrprBtDo=; b=d3GaSQpmyEI0nsdpiE5uHC2OZmybQXjVmxQn+EbmAaZfNpbryzG0YvlAt4uvQ+juwD Rlpp6pnuqkfcCvHfsRqs06O/m3jGbGCtH5Sj6t2pO3sHl9D049brNIq0bEb5BmOFh7vg bBTXz9IA7URJKY+3IV0QiEDPQZ/B7vTqHfB9U5dYchnW/oexZQDxCsk5iYn9ez2All6V FQDhJ+RlWlHLCsz12x4stIivXFDckx/yUIKgmCr5KdSGL46vnKf2sWuuJOb+MD8MLgZQ ZoNG6lb7D061NLtR3cG16Ze1jU+xT41/wBi1VWE9cXy0ImQev2RbrE1wWy664JlNgMjG 61jg== X-Gm-Message-State: AOJu0Ywzma6LJwKmViIEKawjGQd4OEl0WO1VZzBkhsidbwp1Kv9/BTy6 fXIRCphuLkesEG/QSQ1GAiRLD3YR0w0pGA== X-Received: by 2002:a05:6a21:788d:b0:14c:c393:6af with SMTP id bf13-20020a056a21788d00b0014cc39306afmr3035489pzc.0.1693111425401; Sat, 26 Aug 2023 21:43:45 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:bd86:4b0c:f073:c134]) by smtp.gmail.com with ESMTPSA id n10-20020a170902e54a00b001b8baa83639sm4561946plf.200.2023.08.26.21.43.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 26 Aug 2023 21:43:45 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 7AC4811423CD; Sun, 27 Aug 2023 14:13:42 +0930 (ACST) Date: Sun, 27 Aug 2023 14:13:42 +0930 To: binutils@sourceware.org Subject: Confusion in coff_object_cleanup Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3033.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 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: INBOX X-GMAIL-THRID: 1775356017643940025 X-GMAIL-MSGID: 1775356017643940025 A bfd_cleanup function needs to run when only tdata is correct for the bfd. The xvec may have changed during bfd_check_format and thus the flavour may be incorrect. The format won't have changed but checking is superfluous. (In contrast to _bfd_free_cached_info or _close_and_cleanup where we do need to check things.) Not getting this correct leaked comdat_hash. Also, pe_ILF_cleanup ought to call coff_object_cleanup as do all PE files. * coffgen.c (coff_object_cleanup): Don't check bfd flavour or format. * peicode.h (pe_ILF_cleanup): Call coff_object_cleanup. diff --git a/bfd/coffgen.c b/bfd/coffgen.c index bf9633a2b33..91667267cbc 100644 --- a/bfd/coffgen.c +++ b/bfd/coffgen.c @@ -284,18 +284,15 @@ make_a_section_from_file (bfd *abfd, 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) { - 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); - if (obj_pe (abfd) && pe_data (abfd)->comdat_hash) - htab_delete (pe_data (abfd)->comdat_hash); - } + if (td->section_by_index) + htab_delete (td->section_by_index); + if (td->section_by_target_index) + htab_delete (td->section_by_target_index); + if (obj_pe (abfd) && pe_data (abfd)->comdat_hash) + htab_delete (pe_data (abfd)->comdat_hash); } } diff --git a/bfd/peicode.h b/bfd/peicode.h index 5ac6b0dc53f..e1d06606575 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -1180,6 +1180,8 @@ pe_ILF_build_a_bfd (bfd * abfd, static void pe_ILF_cleanup (bfd *abfd) { + coff_object_cleanup (abfd); + struct bfd_in_memory *bim = abfd->iostream; free (bim->buffer); free (bim);