From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-oo1-xc33.google.com (mail-oo1-xc33.google.com [IPv6:2607:f8b0:4864:20::c33]) by sourceware.org (Postfix) with ESMTPS id 508AE3858D20 for ; Thu, 1 Jun 2023 04:35:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 508AE3858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=rivosinc.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=rivosinc.com Received: by mail-oo1-xc33.google.com with SMTP id 006d021491bc7-55825988b7bso108236eaf.1 for ; Wed, 31 May 2023 21:35:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20221208.gappssmtp.com; s=20221208; t=1685594117; x=1688186117; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=SpYuKfdoUs7TYKof1Qzk7+DAEDluNK6G+mZrLyS8Xt4=; b=WZ4JCyPnJlTsNIAw9uHKgW0VaIp67mjL6P+RVP7TQVOg9VwdgWx3u24o7p2KcOeQ05 s4TbZlbveYOOoTKGyXhBaKIugnZfaP162nnt03QoPffsO1Hd4q2Ynvh5GZMdq8XLIS+j As+8DLFIqHfp2vZM+OJNMivsQF+MzObad1y14kP3gbFD8QL5jon+qE2qMcAJNy9rNo2M kaCnc0I132AfX+8Vfx7g9mGNBCdniSgzgRD2QzMEOSIWLGCGxx+sRDW0DVR9TPOBLAdP TCrF+BCN/tQV0BzuzmbBLcRpE285E74jJiMU9St4IRdzDauTSKKloXrxKFwfXlK5h6Zj +F1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685594117; x=1688186117; 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=SpYuKfdoUs7TYKof1Qzk7+DAEDluNK6G+mZrLyS8Xt4=; b=df1V5tL17njxVjDHLskREUGxkP8lrnXZHWXLDw6HuBqmUNH3pquKrm73O2sIyw4CEn HfUWJlKxMfVRQNJ+hzVN1iLfrg7Fl9NQ98KTEhzeh2H3Wj5OkDd2FxMQSJ7hJ9XKVj+8 rUqfdMur+0vKIub/ClVqO8pVdfQ5dOFeuWzO2H36c30829AzVCUCNVWYjIkuJn/dEH50 kHoM832/Bq6AwMaGNKEJc59aqfDsETii8boVsxSyC1PRvUlHxZ7o10hcqX1JEdwVNqDA kCs0UtkJAoXf2p2VZEXqt8fKXYN8yZuNxJ4KZjMfQ0M7iWBPeyNoQz+3LzmevTVqJMxH nBrA== X-Gm-Message-State: AC+VfDym+AcXiA1CaSdsyOnGefEG/lD5i00rXXkL54/5ckqjdx/iAZyQ IJZm8gzzjsHuLTnoDhL2wNOU9Q7hQpOZwY6pRlTlogxfttNnk9VrqFA= X-Google-Smtp-Source: ACHHUZ6xP/jAE5ILRBT42QLic3583PiqRzSBY0vdBaGpizT1FWUDW1OQ+PhpWXJz6mDmn36t5VjFngYjGFeo7UuRaFg= X-Received: by 2002:a4a:2cc2:0:b0:555:48c0:cc63 with SMTP id o185-20020a4a2cc2000000b0055548c0cc63mr2976580ooo.2.1685594117334; Wed, 31 May 2023 21:35:17 -0700 (PDT) MIME-Version: 1.0 References: <20230527013620.65127-1-nelson@rivosinc.com> In-Reply-To: <20230527013620.65127-1-nelson@rivosinc.com> From: Nelson Chu Date: Thu, 1 Jun 2023 12:35:06 +0800 Message-ID: Subject: Re: [PATCH] [PR ld/22263] RISC-V: Avoid spurious R_RISCV_NONE for pr22263-1 test. To: binutils@sourceware.org, jim.wilson.gcc@gmail.com, palmer@dabbelt.com, andrew@sifive.com Content-Type: multipart/alternative; boundary="000000000000997fe805fd09f639" X-Spam-Status: No, score=-9.2 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,GIT_PATCH_0,HTML_MESSAGE,KAM_STOCKGEN,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE 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: --000000000000997fe805fd09f639 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Committed since passed the riscv-gnu-toolchain gcc/binutils regressions. Thanks Nelson On Sat, May 27, 2023 at 9:36=E2=80=AFAM Nelson Chu wr= ote: > For TLS GD/IE, add the same condition with the relocate_section in the > allocate_dynrelocs, to make sure we won't reserve redundant spaces > for dynamic relocations since the conservative estimatation. > > After applying this patch, ld seems no longer generate the spurious > R_RISCV_NONE for pr22263-1 test. > > bfd/ > PR ld/22263 > * elfnn-riscv.c (RISCV_TLS_GD_IE_NEED_DYN_RELOC): New defined. > Set NEED_RELOC to true if TLS GD/IE needs dynamic relocations, > and INDX will be the dynamic index. > (allocate_dynrelocs): Don't reserve extra spaces in the rela.got > if RISCV_TLS_GD_IE_NEED_DYN_RELOC set need_reloc to false. This > condition needs to be same as relocate_section. > (relocate_section): Likewise, use the same condition as > allocate_dynrelocs. > --- > bfd/elfnn-riscv.c | 41 ++++++++++++++++++++++++++++------------- > 1 file changed, 28 insertions(+), 13 deletions(-) > > diff --git a/bfd/elfnn-riscv.c b/bfd/elfnn-riscv.c > index 762ea231c0b..30d2faa405d 100644 > --- a/bfd/elfnn-riscv.c > +++ b/bfd/elfnn-riscv.c > @@ -111,6 +111,25 @@ > || (bfd_link_pic (INFO) \ > && SYMBOL_REFERENCES_LOCAL ((INFO), (H)))) > > +/* Set NEED_RELOC to true if TLS GD/IE needs dynamic relocations, and > INDX will > + be the dynamic index. PR22263, use the same check in > allocate_dynrelocs and > + riscv_elf_relocate_section for TLS GD/IE. */ > +#define RISCV_TLS_GD_IE_NEED_DYN_RELOC(INFO, DYN, H, INDX, NEED_RELOC) \ > + do \ > + { \ > + if ((H) !=3D NULL \ > + && (H)->dynindx !=3D -1 \ > + && WILL_CALL_FINISH_DYNAMIC_SYMBOL ((DYN), bfd_link_pic (INFO), > (H)) \ > + && (bfd_link_dll (INFO) || !SYMBOL_REFERENCES_LOCAL ((INFO), > (H)))) \ > + (INDX) =3D (H)->dynindx; \ > + if ((bfd_link_dll (INFO) || (INDX) !=3D 0) \ > + && ((H) =3D=3D NULL \ > + || ELF_ST_VISIBILITY ((H)->other) =3D=3D STV_DEFAULT \ > + || (H)->root.type !=3D bfd_link_hash_undefweak)) \ > + (NEED_RELOC) =3D true; \ > + } \ > + while (0) > + > /* Internal relocations used exclusively by the relaxation pass. */ > #define R_RISCV_DELETE (R_RISCV_max + 1) > > @@ -1297,18 +1316,24 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, > void *inf) > dyn =3D htab->elf.dynamic_sections_created; > if (tls_type & (GOT_TLS_GD | GOT_TLS_IE)) > { > + int indx =3D 0; > + bool need_reloc =3D false; > + RISCV_TLS_GD_IE_NEED_DYN_RELOC(info, dyn, h, indx, need_reloc); > + > /* TLS_GD needs two dynamic relocs and two GOT slots. */ > if (tls_type & GOT_TLS_GD) > { > s->size +=3D 2 * RISCV_ELF_WORD_BYTES; > - htab->elf.srelgot->size +=3D 2 * sizeof (ElfNN_External_Rel= a); > + if (need_reloc) > + htab->elf.srelgot->size +=3D 2 * sizeof > (ElfNN_External_Rela); > } > > /* TLS_IE needs one dynamic reloc and one GOT slot. */ > if (tls_type & GOT_TLS_IE) > { > s->size +=3D RISCV_ELF_WORD_BYTES; > - htab->elf.srelgot->size +=3D sizeof (ElfNN_External_Rela); > + if (need_reloc) > + htab->elf.srelgot->size +=3D sizeof (ElfNN_External_Rela); > } > } > else > @@ -2882,20 +2907,10 @@ riscv_elf_relocate_section (bfd *output_bfd, > abort (); > > bool dyn =3D elf_hash_table (info)->dynamic_sections_create= d; > - if (h !=3D NULL > - && h->dynindx !=3D -1 > - && WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, bfd_link_pic > (info), h) > - && (bfd_link_dll (info) || !SYMBOL_REFERENCES_LOCAL > (info, h))) > - indx =3D h->dynindx; > + RISCV_TLS_GD_IE_NEED_DYN_RELOC (info, dyn, h, indx, > need_relocs); > > /* The GOT entries have not been initialized yet. Do it > now, and emit any relocations. */ > - if ((bfd_link_dll (info) || indx !=3D 0) > - && (h =3D=3D NULL > - || ELF_ST_VISIBILITY (h->other) =3D=3D STV_DEFAULT > - || h->root.type !=3D bfd_link_hash_undefweak)) > - need_relocs =3D true; > - > if (tls_type & GOT_TLS_GD) > { > if (need_relocs) > -- > 2.39.2 (Apple Git-143) > > --000000000000997fe805fd09f639--