From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ot1-x336.google.com (mail-ot1-x336.google.com [IPv6:2607:f8b0:4864:20::336]) by sourceware.org (Postfix) with ESMTPS id 99D1D3858417 for ; Tue, 3 Jan 2023 22:00:21 +0000 (GMT) Received: by mail-ot1-x336.google.com with SMTP id y18-20020a0568301d9200b0067082cd4679so19869456oti.4 for ; Tue, 03 Jan 2023 14:00:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=Hv8D2OsEOUxGmYF19OZaxFrAcvyA23FnLCmFSf5OJoU=; b=o31I1ZVPATnAIvDlsj7vfZgvcHldR//BhwM+IL53y6TZcLqOJUE2ZUnMrKHATdUrRh voKHliWJyuJWxC/Ev/3fwkyWCyGJToqDrIV+JzmfWF0VySqUs6aa5+/vqBw3srYsNWYn vXujZsoYKyCbLDgtKeQZi1Tjd1cyo66Jx1jdCcmyh93A+kwjcshHrjlUdbw3pm0QlZ9r pLiWvdOb5pBJRRAGuq9XcoclGAUBvqeyWDHdMmMz4qUi8OtP/C25Lfavy13wSC9gBZpg gwyyREu/9siWNdyasNHBYX7OLDEyZb14FI9kFuoRf0LT/DSbfXBfnGXPawCurLp4Xp4o ijag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=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=Hv8D2OsEOUxGmYF19OZaxFrAcvyA23FnLCmFSf5OJoU=; b=vEeUk9HpQ4ncQSQ32jZUoRIsd3+7e5K5n1lDj+fYSdKflXdO0odIEBGVwbDjOqqGv6 7afPjq0b056bwCr7AHbYft1hWguJGGXb+0Lyp3mHSHe0qL4Qphez+LApZyvH1K9t2/5L RIdiNAwQrRmmLCRn5aHoJK6YxkHSYwLzVeexcc8yktnrGe/2FgFKNkmPWnpso2W++2+S g+dRlKjqSv5fgOnM4esQOuz2TFzUaH7+AJY4AsNH6+6vudIGQe6FSQgZZlmlV8H1L+Mj PHIM1TSvihhJ0l/7FlUMthu5GGBkhlxyHY3ItWvmg7Q0lkpnFUemSASMFPyrdNZzxdyM 4rDg== X-Gm-Message-State: AFqh2kpMJ90BslTL+19XwtMZ6R2V80ul1+lTV282YSpZ+sA27Q+ibScF teZ9r7JNE6oNEDNRVJeFb4D5LWEURsXRITd8n/7chZ3o X-Google-Smtp-Source: AMrXdXuwLUGgNjy76rr1Ge9zjTTbPxzjDSztmr2upTCkiM0qMxR13ia5TMR2ekf6WTmJYUIeZAaTiw2wyE0QWXqsfBs= X-Received: by 2002:a9d:6182:0:b0:678:266b:9e55 with SMTP id g2-20020a9d6182000000b00678266b9e55mr2564475otk.371.1672783220582; Tue, 03 Jan 2023 14:00:20 -0800 (PST) MIME-Version: 1.0 References: <20221227194756.448332-1-hjl.tools@gmail.com> In-Reply-To: <20221227194756.448332-1-hjl.tools@gmail.com> From: "H.J. Lu" Date: Tue, 3 Jan 2023 13:59:44 -0800 Message-ID: Subject: Re: [PATCH] x86-64: Allocate input section memory if needed To: binutils@sourceware.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-3023.4 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 List-Id: On Tue, Dec 27, 2022 at 11:47 AM H.J. Lu wrote: > > When --no-keep-memory is used, the input section memory may not be cached. > Allocate input section memory for -z pack-relative-relocs if needed. > > bfd/ > > PR ld/29939 > * elfxx-x86.c (elf_x86_size_or_finish_relative_reloc): Allocate > input section memory if needed. > > ld/ > > PR ld/29939 > * testsuite/ld-elf/dt-relr-2i.d: New test. > --- > bfd/elfxx-x86.c | 25 +++++++++++++++++++++++-- > ld/testsuite/ld-elf/dt-relr-2i.d | 17 +++++++++++++++++ > 2 files changed, 40 insertions(+), 2 deletions(-) > create mode 100644 ld/testsuite/ld-elf/dt-relr-2i.d > > diff --git a/bfd/elfxx-x86.c b/bfd/elfxx-x86.c > index 2ddca340473..ec86e75eba9 100644 > --- a/bfd/elfxx-x86.c > +++ b/bfd/elfxx-x86.c > @@ -1541,12 +1541,33 @@ elf_x86_size_or_finish_relative_reloc > } > else > { > + bfd_byte *contents; > + > if (rel.r_offset >= sec->size) > abort (); > + > + if (elf_section_data (sec)->this_hdr.contents > + != NULL) > + contents > + = elf_section_data (sec)->this_hdr.contents; > + else > + { > + if (!bfd_malloc_and_get_section (sec->owner, > + sec, > + &contents)) > + info->callbacks->einfo > + /* xgettext:c-format */ > + (_("%F%P: %pB: failed to allocate memory for section `%pA'\n"), > + info->output_bfd, sec); > + > + /* Cache the section contents for > + elf_link_input_bfd. */ > + elf_section_data (sec)->this_hdr.contents > + = contents; > + } > htab->elf_write_addend > (info->output_bfd, outrel->r_addend, > - (elf_section_data (sec)->this_hdr.contents > - + rel.r_offset)); > + contents + rel.r_offset); > } > } > } > diff --git a/ld/testsuite/ld-elf/dt-relr-2i.d b/ld/testsuite/ld-elf/dt-relr-2i.d > new file mode 100644 > index 00000000000..ed0ef9ccded > --- /dev/null > +++ b/ld/testsuite/ld-elf/dt-relr-2i.d > @@ -0,0 +1,17 @@ > +#source: dt-relr-2.s > +#ld: -e _start -pie --no-keep-memory $DT_RELR_LDFLAGS > +#readelf: -rW -d > +#target: [supports_dt_relr] > + > +#... > + 0x[0-9a-f]+ \(RELR\) +0x[0-9a-f]+ > + 0x[0-9a-f]+ \(RELRSZ\) +(8|16) \(bytes\) > + 0x[0-9a-f]+ \(RELRENT\) +(4|8) \(bytes\) > +#... > +Relocation section '\.rel(a|)\.dyn' at offset 0x[0-9a-f]+ contains 1 entry: > +#... > +[0-9a-f]+ +[0-9a-f]+ +R_.*_(RELATIVE|UADDR.*) .* > +#... > +Relocation section '\.relr\.dyn' at offset 0x[0-9a-f]+ contains 2 entries: > + 4 offsets > +#pass > -- > 2.38.1 > I am backporting it to 2.39 branch. -- H.J.