From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id 4D6B63875DD3 for ; Fri, 15 Dec 2023 12:22:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 4D6B63875DD3 Authentication-Results: sourceware.org; dmarc=pass (p=reject dis=none) header.from=xry111.site Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=xry111.site ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 4D6B63875DD3 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=89.208.246.23 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702642976; cv=none; b=lv0xLPB86vTE5Whyt0F/szW+TxFKSN9LFjqC+9BVO93pewEKeY3OEiASlFO0jCc0gmPjOXzECrDk94/Wbc7R+MCYWc8HzETHe7QQf2NGJuGb08sPRclmu5xWrzOTDIgf6bbhC4D0ZDIUqFOlkl4ePPng7ijFBYu+fzRKFGCzGsU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1702642976; c=relaxed/simple; bh=iI6tddaMnuuxG0esujWdOIJT0dMP2r9+rvuvFe4GfMw=; h=DKIM-Signature:Message-ID:Subject:From:To:Date:MIME-Version; b=l6wih04ERuRgBD03W9nvaQLiteT6BvLRjOe33oV386LWDC3wZjvRPf9y+NfSpI0eMDoUb+S4NwM0vVH8bnx11OXOEYGEmPn3KhKtimd5ekHw3DfkadWe4iS6+/ODxhr6Ni7f2XN7sHZREAVBNGxhWV70KN43mh0we1gQTe5akTo= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1702642972; bh=iI6tddaMnuuxG0esujWdOIJT0dMP2r9+rvuvFe4GfMw=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=TtpmX8ePtOiYngN/+3paoQgdFQ6Sjy0nItIp1+AF4+B/gv60BBq0omccC76SrxCWg LP/I9a5aeCoVXlhB3wTh740b2+XNpW3K70QwfjbxB4bn0+4Pfd/ofZd3cbd7LV4ASq Yt52EnZda9CKrwBSbDWJKtdIiQzbZeIedPbnYVKw= Received: from [127.0.0.1] (unknown [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 826D666E8A; Fri, 15 Dec 2023 07:22:50 -0500 (EST) Message-ID: <5c9d7da55b80be8e6ff11894fcd0c225416859ca.camel@xry111.site> Subject: Ping: [PATCH] LoongArch: Allow la.got -> la.pcrel relaxation for shared object From: Xi Ruoyao To: binutils@sourceware.org Cc: liuzhensong@loongson.cn, mengqinggang@loongson.cn, i.swmail@xen0n.name, maskray@google.com, hejinyang@loongson.cn, cailulu@loongson.cn Date: Fri, 15 Dec 2023 20:22:47 +0800 In-Reply-To: <20231205190547.52950-1-xry111@xry111.site> References: <20231205190547.52950-1-xry111@xry111.site> Autocrypt: addr=xry111@xry111.site; prefer-encrypt=mutual; keydata=mDMEYnkdPhYJKwYBBAHaRw8BAQdAsY+HvJs3EVKpwIu2gN89cQT/pnrbQtlvd6Yfq7egugi0HlhpIFJ1b3lhbyA8eHJ5MTExQHhyeTExMS5zaXRlPoiTBBMWCgA7FiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwMFCwkIBwICIgIGFQoJCAsCBBYCAwECHgcCF4AACgkQrKrSDhnnEOPHFgD8D9vUToTd1MF5bng9uPJq5y3DfpcxDp+LD3joA3U2TmwA/jZtN9xLH7CGDHeClKZK/ZYELotWfJsqRcthOIGjsdAPuDgEYnkdPhIKKwYBBAGXVQEFAQEHQG+HnNiPZseiBkzYBHwq/nN638o0NPwgYwH70wlKMZhRAwEIB4h4BBgWCgAgFiEEkdD1djAfkk197dzorKrSDhnnEOMFAmJ5HT4CGwwACgkQrKrSDhnnEOPjXgD/euD64cxwqDIqckUaisT3VCst11RcnO5iRHm6meNIwj0BALLmWplyi7beKrOlqKfuZtCLbiAPywGfCNg8LOTt4iMD Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.50.2 MIME-Version: 1.0 X-Spam-Status: No, score=-5.5 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_STOCKGEN,LIKELY_SPAM_FROM,SPF_HELO_PASS,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: Ping. On Wed, 2023-12-06 at 03:05 +0800, Xi Ruoyao wrote: > Even in shared objects, la.got -> la.pcrel relaxation can still be > performed for symbols with hidden visibility. For example, if a.c is: >=20 > =C2=A0=C2=A0=C2=A0 extern int x; > =C2=A0=C2=A0=C2=A0 int f() { return x++; } >=20 > and b.c is: >=20 > =C2=A0=C2=A0=C2=A0 int x =3D 114514; >=20 > If compiling and linking with: >=20 > =C2=A0=C2=A0=C2=A0 gcc -shared -fPIC -O2 -fvisibility=3Dhidden a.c b.c >=20 > Then the la.got in a.o should be relaxed to la.pcrel, and the resulted f > should be like: >=20 > =C2=A0=C2=A0=C2=A0 pcaddi=C2=A0 $t0, x > =C2=A0=C2=A0=C2=A0 ldptr.w $a0, $t0, 0 > =C2=A0=C2=A0=C2=A0 addi.w=C2=A0 $t1, $a0, 1 > =C2=A0=C2=A0=C2=A0 stptr.w $t1, $t0, 0 > =C2=A0=C2=A0=C2=A0 ret >=20 > Remove bfd_link_executable from the condition of la.got -> la.pcrel > relaxation so this will really happen.=C2=A0 The SYMBOL_REFERENCES_LOCAL > check is enough not to wrongly relax preemptable symbols (for e.g. > when -fvisibility=3Dhidden is not used). >=20 > Note that on x86_64 this is also relaxed and the produced code is like: >=20 > =C2=A0=C2=A0=C2=A0 lea x(%rip), %rdx > =C2=A0=C2=A0=C2=A0 mov (%rdx), %rax > =C2=A0=C2=A0=C2=A0 lea 1(%rax), %ecx > =C2=A0=C2=A0=C2=A0 mov %ecx, (%rdx) > =C2=A0=C2=A0=C2=A0 ret >=20 > Tested by running ld test suite, bootstrapping and regtesting GCC with > the patched ld, and building and testing Glibc with the patched ld.=C2=A0= No > regression is observed. >=20 > Signed-off-by: Xi Ruoyao > --- > =C2=A0bfd/elfnn-loongarch.c | 3 +-- > =C2=A01 file changed, 1 insertion(+), 2 deletions(-) >=20 > diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c > index 024c5d4cd96..80739b817ab 100644 > --- a/bfd/elfnn-loongarch.c > +++ b/bfd/elfnn-loongarch.c > @@ -3986,8 +3986,7 @@ loongarch_elf_relax_section (bfd *abfd, asection *s= ec, > =C2=A0 =C2=A0 else > =C2=A0 =C2=A0=C2=A0=C2=A0 continue; > =C2=A0 > - =C2=A0 if (h && bfd_link_executable (info) > - =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 && SYMBOL_REFERENCES_LOCAL (info, h)) > + =C2=A0 if (h && SYMBOL_REFERENCES_LOCAL (info, h)) > =C2=A0 =C2=A0=C2=A0=C2=A0 local_got =3D true; > =C2=A0 =C2=A0 symtype =3D h->type; > =C2=A0 } --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University