From patchwork Thu Feb 9 09:41:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alan Modra X-Patchwork-Id: 54823 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp236043wrn; Thu, 9 Feb 2023 01:42:08 -0800 (PST) X-Google-Smtp-Source: AK7set/eHl4MMkKQkiIKevsCcpJJ5PL82sdbDuI7j5Ek7i66bcVqny9GqleJ/ZE3OZyqZ9F9J5D3 X-Received: by 2002:a50:d549:0:b0:4aa:c685:2937 with SMTP id f9-20020a50d549000000b004aac6852937mr11650686edj.13.1675935728776; Thu, 09 Feb 2023 01:42:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675935728; cv=none; d=google.com; s=arc-20160816; b=EatFtAHNexktT1lT5PL6T1fj3K8YJDQ7jfYRFw0Bo/hEYaLV+kDtse1mZKkXaRLv/R V2qtDqwZr7tWFgmDRmNvYQhUMt8Xcv3flbMiAa2yGXCHyzdoxV+inlBaqWo3Qj+MYdJg ZU0jiN7vPxwiD2vt8r6qDpXKapxJM+cnOfYSs4giw39Nikx2UFJZ3qY5si2VYpGXol3L 7NVfyIYMzOVUACrDk/FyfLCdh6y33T/F1dTLYj4LLB/OYTgeDua/t5QpWJjeG7VLxPfq zHWit6zMtSqzdsOm7d2XLTHrZOAu6LeD94fWa+O5SosRepFzbGEUpE2v4G/YY+HlNZxR fWKg== 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=TBPibgtS/BD0SQ8jtXSZDtdwMJRF5svtZVywvIJIR+A=; b=SEcRw5/HYwubULkEl7mXokGJM1fBkhrV3yAWufFvd4hiPBF45GefUiHWgeCuijTnDM nsyDBevijCKMsCnvWhu4R8obL8KH++wLr6OhA9Xtot4+KTyN9EEiUT1Lxe2fSNRFDbAV btGFd6+gyDg5eSG2NLxQXc7vNQO2seDhOpwXAKzmqOmq7x37cTxIKc8RJe6pRN60XGK/ oCq8cM/SnhwIBZrxMsmtYD9rTtpTdkHz4fba/haFMliYApLCWJ7tcbsXQDbJVTcVY3tL 5fCZKqrupaTiJn0DulWtbcbFcQnP8uaDsT4j06DDf+nDNzt3zuHquZ9ju02MESWMmCEr m13Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=pIF+Jnkt; 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 m18-20020a056402051200b004a0a8e3b41dsi1688002edv.145.2023.02.09.01.42.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 01:42:08 -0800 (PST) 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=pIF+Jnkt; 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 B67AD3858C74 for ; Thu, 9 Feb 2023 09:42:07 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B67AD3858C74 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1675935727; bh=TBPibgtS/BD0SQ8jtXSZDtdwMJRF5svtZVywvIJIR+A=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pIF+JnkthC37RyxBL52AGnWfQSh2rb1dkpZqhES076y/A/JR2VThHByOggrWCiHOy xJzdFPj8IEqKBuwHK1fCjv0PDHJvhaAUPvmmzHsX1F4XcgwyXYV5rgyDxancrNmP96 21NeUOuwhAJf+16qHxuoP3gy+oQiI+ubhVbipPz0= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by sourceware.org (Postfix) with ESMTPS id CF1793858C50 for ; Thu, 9 Feb 2023 09:41:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org CF1793858C50 Received: by mail-pj1-x102f.google.com with SMTP id mi9so1546021pjb.4 for ; Thu, 09 Feb 2023 01:41:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=TBPibgtS/BD0SQ8jtXSZDtdwMJRF5svtZVywvIJIR+A=; b=Tx5s8VKyxTQxraK+IrWaijLf0iIvaiupzQeghscBxxe+5SC6FqaKB6iZZzJgiytpOS 5Rm6LdHRyi5DDgbIxCDAiHil1hv/p3qEv6tcjumCO94m+NxoPg27ut+94sPF9IQfHCKI 5M7ZEhbrlo0MKnEjlbYlDcwj3Mj5dEplFhIIuLHXMdy0M17sKtegZQ0jABh0XpSVfnZk XSY/rXjQPP0oGs6ahswwSKMamXCID9RasQsWIz7q3kAmxBEX49/96LVZ3MwDiGW6W5If 1aDhBXO1qZHXo8kwdCPriXnjS2rj2PYJKFuRTMLrbF+u5kCT6IEHrAP321HrXWbnv7AJ 6uww== X-Gm-Message-State: AO0yUKWs8vZ0wVCyK+9GWDbhHzV/UD3/sxwY67kyepmwwhMt4oGYdgJL mUZqMZktXaCZtlJM9tBVs5iec4hNtRU= X-Received: by 2002:a05:6a20:7d89:b0:c1:2038:c8e8 with SMTP id v9-20020a056a207d8900b000c12038c8e8mr13045401pzj.36.1675935716413; Thu, 09 Feb 2023 01:41:56 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:2c19:e063:cb3b:da4]) by smtp.gmail.com with ESMTPSA id n20-20020a637214000000b004faf33e2758sm941248pgc.40.2023.02.09.01.41.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Feb 2023 01:41:55 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id 9643B11404B1; Thu, 9 Feb 2023 20:11:53 +1030 (ACDT) Date: Thu, 9 Feb 2023 20:11:53 +1030 To: binutils@sourceware.org Subject: coff keep_relocs and keep_contents Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-3035.0 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: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757345983057314795?= X-GMAIL-MSGID: =?utf-8?q?1757345983057314795?= keep_relocs is set by pe_ILF_save_relocs but not used anywhere in the coff/pe code. It is tested by the xcoff backend but not set. keep_contents is only used by the xcoff backend when dealing with the .loader section, and it's easy enough to dispense with it there. keep_contents is set in various places but that's fairly useless when the contents aren't freed anyway until later linker support functions, add_dynamic_symbols and check_dynamic_ar_symbols. There the contents were freed if keep_contents wasn't set. I reckon we can free them unconditionally. * coff-bfd.h (struct coff_section_tdata): Delete keep_relocs and keep_contents. * peicode.h (pe_ILF_save_relocs): Don't set keep_relocs. * xcofflink.c (xcoff_get_section_contents): Cache contents. Return the contents. Update callers. (_bfd_xcoff_canonicalize_dynamic_symtab): Don't set keep_contents for .loader. (xcoff_link_add_dynamic_symbols): Free .loader contents unconditionally. (xcoff_link_check_dynamic_ar_symbols): Likewise. diff --git a/bfd/coff-bfd.h b/bfd/coff-bfd.h index a4e44460056..133ccadc41f 100644 --- a/bfd/coff-bfd.h +++ b/bfd/coff-bfd.h @@ -43,12 +43,8 @@ struct coff_section_tdata { /* The relocs, swapped into COFF internal form. This may be NULL. */ struct internal_reloc *relocs; - /* If this is TRUE, the relocs entry may not be freed. */ - bool keep_relocs; /* The section contents. This may be NULL. */ bfd_byte *contents; - /* If this is TRUE, the contents entry may not be freed. */ - bool keep_contents; /* Information cached by coff_find_nearest_line. */ bool saved_bias; bfd_signed_vma bias; diff --git a/bfd/peicode.h b/bfd/peicode.h index fef7d0dd69b..43226caf00e 100644 --- a/bfd/peicode.h +++ b/bfd/peicode.h @@ -526,7 +526,6 @@ pe_ILF_save_relocs (pe_ILF_vars * vars, abort (); coff_section_data (vars->abfd, sec)->relocs = vars->int_reltab; - coff_section_data (vars->abfd, sec)->keep_relocs = true; sec->relocation = vars->reltab; sec->reloc_count = vars->relcount; diff --git a/bfd/xcofflink.c b/bfd/xcofflink.c index 0bf06035313..b3ab78013ad 100644 --- a/bfd/xcofflink.c +++ b/bfd/xcofflink.c @@ -216,7 +216,7 @@ static bool xcoff_mark (struct bfd_link_info *, asection *); /* Read the contents of a section. */ -static bool +static bfd_byte * xcoff_get_section_contents (bfd *abfd, asection *sec) { if (coff_section_data (abfd, sec) == NULL) @@ -225,22 +225,22 @@ xcoff_get_section_contents (bfd *abfd, asection *sec) sec->used_by_bfd = bfd_zalloc (abfd, amt); if (sec->used_by_bfd == NULL) - return false; + return NULL; } - if (coff_section_data (abfd, sec)->contents == NULL) + bfd_byte *contents = coff_section_data (abfd, sec)->contents; + if (contents == NULL) { - bfd_byte *contents; - - if (! bfd_malloc_and_get_section (abfd, sec, &contents)) + if (bfd_malloc_and_get_section (abfd, sec, &contents)) + coff_section_data (abfd, sec)->contents = contents; + else { free (contents); - return false; + contents = NULL; } - coff_section_data (abfd, sec)->contents = contents; } - return true; + return contents; } /* Get the size required to hold the dynamic symbols. */ @@ -265,9 +265,9 @@ _bfd_xcoff_get_dynamic_symtab_upper_bound (bfd *abfd) return -1; } - if (! xcoff_get_section_contents (abfd, lsec)) + contents = xcoff_get_section_contents (abfd, lsec); + if (!contents) return -1; - contents = coff_section_data (abfd, lsec)->contents; bfd_xcoff_swap_ldhdr_in (abfd, (void *) contents, &ldhdr); @@ -299,11 +299,9 @@ _bfd_xcoff_canonicalize_dynamic_symtab (bfd *abfd, asymbol **psyms) return -1; } - if (! xcoff_get_section_contents (abfd, lsec)) + contents = xcoff_get_section_contents (abfd, lsec); + if (!contents) return -1; - contents = coff_section_data (abfd, lsec)->contents; - - coff_section_data (abfd, lsec)->keep_contents = true; bfd_xcoff_swap_ldhdr_in (abfd, contents, &ldhdr); @@ -386,9 +384,9 @@ _bfd_xcoff_get_dynamic_reloc_upper_bound (bfd *abfd) return -1; } - if (! xcoff_get_section_contents (abfd, lsec)) + contents = xcoff_get_section_contents (abfd, lsec); + if (!contents) return -1; - contents = coff_section_data (abfd, lsec)->contents; bfd_xcoff_swap_ldhdr_in (abfd, (struct external_ldhdr *) contents, &ldhdr); @@ -421,9 +419,9 @@ _bfd_xcoff_canonicalize_dynamic_reloc (bfd *abfd, return -1; } - if (! xcoff_get_section_contents (abfd, lsec)) + contents = xcoff_get_section_contents (abfd, lsec); + if (!contents) return -1; - contents = coff_section_data (abfd, lsec)->contents; bfd_xcoff_swap_ldhdr_in (abfd, contents, &ldhdr); @@ -915,9 +913,9 @@ xcoff_link_add_dynamic_symbols (bfd *abfd, struct bfd_link_info *info) return false; } - if (! xcoff_get_section_contents (abfd, lsec)) + contents = xcoff_get_section_contents (abfd, lsec); + if (!contents) return false; - contents = coff_section_data (abfd, lsec)->contents; /* Remove the sections from this object, so that they do not get included in the link. */ @@ -1044,11 +1042,8 @@ xcoff_link_add_dynamic_symbols (bfd *abfd, struct bfd_link_info *info) } } - if (contents != NULL && ! coff_section_data (abfd, lsec)->keep_contents) - { - free (coff_section_data (abfd, lsec)->contents); - coff_section_data (abfd, lsec)->contents = NULL; - } + free (contents); + coff_section_data (abfd, lsec)->contents = NULL; /* Record this file in the import files. */ n = bfd_alloc (abfd, (bfd_size_type) sizeof (struct xcoff_import_file)); @@ -2306,8 +2301,7 @@ xcoff_link_add_symbols (bfd *abfd, struct bfd_link_info *info) /* If we are not keeping memory, free the reloc information. */ if (! info->keep_memory - && coff_section_data (abfd, o) != NULL - && ! coff_section_data (abfd, o)->keep_relocs) + && coff_section_data (abfd, o) != NULL) { free (coff_section_data (abfd, o)->relocs); coff_section_data (abfd, o)->relocs = NULL; @@ -2383,9 +2377,9 @@ xcoff_link_check_dynamic_ar_symbols (bfd *abfd, /* There are no symbols, so don't try to include it. */ return true; - if (! xcoff_get_section_contents (abfd, lsec)) + contents = xcoff_get_section_contents (abfd, lsec); + if (!contents) return false; - contents = coff_section_data (abfd, lsec)->contents; bfd_xcoff_swap_ldhdr_in (abfd, contents, &ldhdr); @@ -2434,12 +2428,9 @@ xcoff_link_check_dynamic_ar_symbols (bfd *abfd, } } - /* We do not need this shared object. */ - if (contents != NULL && ! coff_section_data (abfd, lsec)->keep_contents) - { - free (coff_section_data (abfd, lsec)->contents); - coff_section_data (abfd, lsec)->contents = NULL; - } + /* We do not need this shared object's .loader section. */ + free (contents); + coff_section_data (abfd, lsec)->contents = NULL; return true; } @@ -3142,8 +3133,7 @@ xcoff_mark (struct bfd_link_info *info, asection *sec) } if (! info->keep_memory - && coff_section_data (sec->owner, sec) != NULL - && ! coff_section_data (sec->owner, sec)->keep_relocs) + && coff_section_data (sec->owner, sec) != NULL) { free (coff_section_data (sec->owner, sec)->relocs); coff_section_data (sec->owner, sec)->relocs = NULL;