From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-x633.google.com (mail-pl1-x633.google.com [IPv6:2607:f8b0:4864:20::633]) by sourceware.org (Postfix) with ESMTPS id 972A13858D35 for ; Wed, 28 Dec 2022 22:07:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 972A13858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-x633.google.com with SMTP id t2so17239744ply.2 for ; Wed, 28 Dec 2022 14:07:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=563Q4DHtlOc3/RKnYWQoYMY7liqtdwV7G9n8nDh3B4o=; b=Sq1ZoXyPppf18WqFY71dP+QcjU+NggTyxVNqT5YSuG5o8wQqyoxiBuXHMDt0aB34yw mWF2RxCz2n5aKFNdXmBIQ0BlGuwHC6JA94CO045z6wiOoe7m0W5w25jh+kHXH/G1pFR2 mH72ddiFdnj+aRuwStPkEmL2zek2eK2/HJmLTaaw2BvVUX/E04LZ1eUY+bnsNAdAoNJA OtdxcB+kGbhwcQGAEFLJCY9nZ4LegLE8S7t/v8ZHHOZL8woCn3iCM3dQYbOgSpUiqLcq ubp3lyeoKgE/5tw0EH6sHDE2BmDRn2mnbb1nswf92CslWICHmJUuTGW3FXonsNjBV1GH ZuMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=563Q4DHtlOc3/RKnYWQoYMY7liqtdwV7G9n8nDh3B4o=; b=xYWdeRT/thDa29sE4aY+UteHHImRbz0usw3KegqFRZfOZgIbDs/6R9vJZ/8JbpTLmi m25cygfZYyIuj0rES8glqpfNdbmQFe27XNySzTCeG0KO44n/tmLEdzZsgclx2jObupzh rKSI+hWzA8nMxbxeCBj/XWz72FCT6VG4Z8JL7PnyzM6ToeSQANYJPwAwgBzvom8l50Fo 8LUHJBXcidOoA8mBVukkIFqhG7t8jFpQnZsl/RKhpnTaRPLqOhv/HzlKa5B8tRVwiYBb ron17wD7BLARQdMr+tfwT0FujFgr+bE/2pkW1B9nN4M+god9YJc+vgXjk7HliOsk3Htg Ezmg== X-Gm-Message-State: AFqh2kqIpfn/+e6t+IPkYTdVi1My98iXvt6bhX4lxYxOspVfBoIM2sGx +Edida1wtwsOMw7Xz/FqCUQOSypiq0Q= X-Google-Smtp-Source: AMrXdXtuWMiCPEeq1GZE9K/koNzRX/RUoEV/9o7NNa7ZoRmui4ZrkF1rbMQ7Es/bogjL/y3Vtd8WIw== X-Received: by 2002:a17:902:d3cc:b0:192:9141:ace5 with SMTP id w12-20020a170902d3cc00b001929141ace5mr5621700plb.13.1672265221701; Wed, 28 Dec 2022 14:07:01 -0800 (PST) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:4f2e:2e9d:2590:ba25]) by smtp.gmail.com with ESMTPSA id q6-20020a170902dac600b00185402cfedesm1890622plx.246.2022.12.28.14.07.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Dec 2022 14:07:01 -0800 (PST) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id DE90A114078C; Thu, 29 Dec 2022 08:36:58 +1030 (ACDT) Date: Thu, 29 Dec 2022 08:36:58 +1030 From: Alan Modra To: "H.J. Lu" Cc: binutils@sourceware.org Subject: Re: [PATCH] x86-64: Allocate input section memory if needed Message-ID: References: <20221227194756.448332-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-3027.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,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 List-Id: On Wed, Dec 28, 2022 at 09:23:21AM -0800, H.J. Lu wrote: > On Tue, Dec 27, 2022 at 5:16 PM Alan Modra wrote: > > > > On Tue, Dec 27, 2022 at 11:47:56AM -0800, H.J. Lu via Binutils wrote: > > > + /* Cache the section contents for > > > + elf_link_input_bfd. */ > > > + elf_section_data (sec)->this_hdr.contents > > > + = contents; > > > > You shouldn't really be caching unaltered section contents when > > !info->keep_memory. I'm not saying the patch is wrong, but please fix > > this when you have some time. > > > > -- > > Alan Modra > > Australia Development Lab, IBM > > elf_x86_64_scan_relocs has > > if (elf_section_data (sec)->this_hdr.contents != contents) > { > if (!converted && !_bfd_link_keep_memory (info)) > free (contents); > else > { > /* Cache the section contents for elf_link_input_bfd if any > load is converted or --no-keep-memory isn't used. */ > elf_section_data (sec)->this_hdr.contents = contents; > info->cache_size += sec->size; > } > } > > Are you suggesting that it should be No, the code above is correct and how it should be in elf_x86_size_or_finish_relative_reloc. Of course it is a little more complicated there due to handling multiple sections. > > if (elf_section_data (sec)->this_hdr.contents != contents) > { > if (!converted) > free (contents); > else > { > /* Cache the section contents for elf_link_input_bfd if any > load is converted. */ > elf_section_data (sec)->this_hdr.contents = contents; > info->cache_size += sec->size; > } > } This would be wrong as it ignores info->keep_memory. -- Alan Modra Australia Development Lab, IBM