From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 3358C3858D35 for ; Wed, 28 Dec 2022 23:45:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 3358C3858D35 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-ot1-x330.google.com with SMTP id m7-20020a9d73c7000000b00683e2f36c18so5647359otk.0 for ; Wed, 28 Dec 2022 15:45:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=pF3v7FVU2vIhbYNiErkif0OFk1rPnibMZP33v+5Sgqg=; b=AFpnnLXaK4OpFGf1uyqmLW1mlL7t18ApH6Oba/1kzv0SDlNrnApcMP7FxZ7ViPluCO w/AfLWUmtR++ocXtS4l4kRABpW4JZa8JxWbNIINi4jPwIBaONrlPzE+VEXXmPVeA/d3K J2c86mqJHo5P58vHXi2eiZ7TIJsdsh9K0aQw+v7QpQD310rBUlsIs4THknY0AyQGh2lv dEuxyov7HdYReo7JYbL2D6Kc72w8LwChiL2AOqATjHJI4FtoZAgRf0L0nviIggABU73p BygksE6IhNKWZnkAbH7HlNxgXdWdx8hxSvheXcGEY53ZXLK31ox8F3VP8joyh+8zuEJU KXmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=pF3v7FVU2vIhbYNiErkif0OFk1rPnibMZP33v+5Sgqg=; b=VCPjkC/RTdW5igmHI89eKpL4Hffp3Qy9WtEy0rnr31yWxOfth+WhQUOISqetaMXsus ztgze6ZWzSz3to60pN0DLrPB0/IgU3YqC3u0oZt21en0Bdg5/ORGEyiCEq5JuguxqVTA nmiKLMpqtHwtcMLTC5SvhcOFUit3nO2OXcOy3KPtx+IB0pIvz09uBU8A2EFgsInsobAS 1ARI2OoRnVG6vZ/GoVdqQx6tIh2Mo79T+wWGSvGRQ/NJFvM7oLeHteiVZVs4f2MQ+FJL ZKcydbysLl4ipVRumSVu5Cd+Cb0L7I68gLPXNoU8+JU8InxlHWEJaxALhXFnSs5YLsSV YhWw== X-Gm-Message-State: AFqh2krKYifbnJh0pKWZqi4zX1zf8XXLeK7bkkc7t7ALhKaZsp2jqi03 3rq1pDsIZiuBA3TtBy//q9fxuF9eLLV97sjnG/k= X-Google-Smtp-Source: AMrXdXsSTl92omWJjIMJKVFWdRL7tMjiZ5yYON1BgbkHSGardnCLeHJsl46jgHxvA3DOpYOSnZpE7WemiXEkVpBxvhw= X-Received: by 2002:a9d:6182:0:b0:678:266b:9e55 with SMTP id g2-20020a9d6182000000b00678266b9e55mr1539395otk.371.1672271131440; Wed, 28 Dec 2022 15:45:31 -0800 (PST) MIME-Version: 1.0 References: <20221227194756.448332-1-hjl.tools@gmail.com> In-Reply-To: From: "H.J. Lu" Date: Wed, 28 Dec 2022 15:44:55 -0800 Message-ID: Subject: Re: [PATCH] x86-64: Allocate input section memory if needed To: Alan Modra Cc: binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3017.2 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 2:07 PM Alan Modra wrote: > > 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 But elf_x86_size_or_finish_relative_reloc modifies the section contents by storing r_addend in it. > 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 -- H.J.