Message ID | 20231205190547.52950-1-xry111@xry111.site |
---|---|
State | Unresolved |
Headers |
Return-Path: <binutils-bounces+ouuuleilei=gmail.com@sourceware.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:bcd1:0:b0:403:3b70:6f57 with SMTP id r17csp3645759vqy; Tue, 5 Dec 2023 11:06:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IEht/ZDdAgiNuRMcpoOluuifZQvgWtSnWxnEDCpQ3YO2RvuKtba+AmGERWR0TGQVHO4O5yM X-Received: by 2002:a05:620a:8dc4:b0:77f:74d:8bb0 with SMTP id rd4-20020a05620a8dc400b0077f074d8bb0mr1574376qkn.42.1701803181464; Tue, 05 Dec 2023 11:06:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1701803181; cv=pass; d=google.com; s=arc-20160816; b=ZwO1OLPjAgzwpassu28ksKxDz07MLJoOEdoNTkRdpdFZfdCD3ZdZZP9QsxNTvXs3eE ihAqc2eUAQ5D1kIt2a0Q7TodQLicaM0nPxpOMPTXP2CLEDNrpzg1Co582RT3rm6Jwa7X QT2KKaFGL2dSttIjNmhgBHtXwZ++Uzm39VziMSd0gU05/W2DIR6vTSw+U/V4Bf3604Wz Pyfl3CJxuykte7Pn4LQ9IxMhYSlMydGUqwCakCisOieadY0icSPdxdvXUV+TFzgEDZOe 4J0PkFJGDF/KdGhyWqp7p/wScApl6mBoIlwu0WUvlaQ5F1FTHDAzMaloi/Tjm6O3vs2W 8Mqg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=7+NJeRaMDsFyiSl1rna4cboMBnOxl8hYARi6mxDGt1Y=; fh=LzBjzDrfApmgYW2b20ju57kmScS0uJ2L4k3QbAHPeZU=; b=ycM/x7Kn5Cnd2+YbRiiIDQGMkQgZp+4pPC5M7boQ0UE0zNd8QyDA0cx0lzoVcWtSCT yJUZa5dgr8ywWluFhldufEyYrApVmETRrEIkFKaKDSdw9aiiCGv/lymjjevkLJPR/LZT ffYWvEjNAiFpbD2HwvTYE5xZVsCvewAOnM+ORtQqI8sPHEj6+G2eLKFhgVzM4TILGmac QinexQxxGeZXHt80NnhjvMMRhqVFXBNTtfLujcy2iFDfxcIbPcjqOdLsNzXwbt931neY uceMARKYjfBjzTQH6WxCx27AzZGbFv4jKQIS8YEj/oYrXPNYDdX+YbncmIc1oZk3VRmX JNdA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=Mcgz9Q2s; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id u7-20020a05620a430700b0077d7a0f1d66si12850948qko.84.2023.12.05.11.06.21 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Dec 2023 11:06:21 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=Mcgz9Q2s; arc=pass (i=1); spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=xry111.site Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 302013857341 for <ouuuleilei@gmail.com>; Tue, 5 Dec 2023 19:06:21 +0000 (GMT) X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from xry111.site (xry111.site [89.208.246.23]) by sourceware.org (Postfix) with ESMTPS id BFEB53858D32 for <binutils@sourceware.org>; Tue, 5 Dec 2023 19:06:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BFEB53858D32 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 BFEB53858D32 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=1701803177; cv=none; b=KcECV7XNRffdDCHOxYWpje96LuZBUFmK8m+/UNjEMvRR1Q6mRmDGp0VbWygHWB0FSSUdoNrOnyn+BLjEdw8PduaOaV6rCWC5LE0DJBCqcsPa6KGzqjzVJvbFp+ZH57+aXIu6yE6KyTEt8skPWMbT2ePaI7ftBwpskTmKtEfcNew= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1701803177; c=relaxed/simple; bh=InVNkv87yLQ9o3X/Ty5WXuYAL6P8RkKEZ2zLK2fdMFc=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=eh6Fwl0A38qaJqeP4BCbxQy5pjd9LnIFbxcIe59b+TYKtHkxFfIAhU4hxB6jYvlJmw7qttHzjH1KovElVtks8/50TYVNMkgmRTXYuIWw4ucaSrlbfcLk2ZEw1wPZWb1LIfONKjKDUn6GymU6NM+nUMhDqnRq6ud779+3qTH7zYI= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1701803174; bh=InVNkv87yLQ9o3X/Ty5WXuYAL6P8RkKEZ2zLK2fdMFc=; h=From:To:Cc:Subject:Date:From; b=Mcgz9Q2s4Y7Hsp0W/hULZl4GuvuG4iS4MkKGxqfj7w0dSqTFFmmy1nhEwyTiZ6ORb cJCJbMSoVpJqYyKPOPQwKBRn2mpvzx0iX+ynEJkQ6WAqZqsqXu8A40ejPPodthR/P/ nKZiBrm8k8wt3+BXxTsUdpVN3BPXbHnlaCp8vlV4= Received: from stargazer.. (unknown [IPv6:240e:358:111f:6e00:dc73:854d:832e:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 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 2701666A27; Tue, 5 Dec 2023 14:06:09 -0500 (EST) From: Xi Ruoyao <xry111@xry111.site> To: binutils@sourceware.org Cc: liuzhensong@loongson.cn, mengqinggang@loongson.cn, i.swmail@xen0n.name, maskray@google.com, hejinyang@loongson.cn, cailulu@loongson.cn, Xi Ruoyao <xry111@xry111.site> Subject: [PATCH] LoongArch: Allow la.got -> la.pcrel relaxation for shared object Date: Wed, 6 Dec 2023 03:05:47 +0800 Message-ID: <20231205190547.52950-1-xry111@xry111.site> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-8.2 required=5.0 tests=BAYES_00, 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 X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Binutils mailing list <binutils.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/binutils>, <mailto:binutils-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/binutils/> List-Post: <mailto:binutils@sourceware.org> List-Help: <mailto:binutils-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/binutils>, <mailto:binutils-request@sourceware.org?subject=subscribe> Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1784469972893171369 X-GMAIL-MSGID: 1784469972893171369 |
Series |
LoongArch: Allow la.got -> la.pcrel relaxation for shared object
|
|
Checks
Context | Check | Description |
---|---|---|
snail/binutils-gdb-check | warning | Git am fail log |
Commit Message
Xi Ruoyao
Dec. 5, 2023, 7:05 p.m. UTC
Even in shared objects, la.got -> la.pcrel relaxation can still be
performed for symbols with hidden visibility. For example, if a.c is:
extern int x;
int f() { return x++; }
and b.c is:
int x = 114514;
If compiling and linking with:
gcc -shared -fPIC -O2 -fvisibility=hidden a.c b.c
Then the la.got in a.o should be relaxed to la.pcrel, and the resulted f
should be like:
pcaddi $t0, x
ldptr.w $a0, $t0, 0
addi.w $t1, $a0, 1
stptr.w $t1, $t0, 0
ret
Remove bfd_link_executable from the condition of la.got -> la.pcrel
relaxation so this will really happen. The SYMBOL_REFERENCES_LOCAL
check is enough not to wrongly relax preemptable symbols (for e.g.
when -fvisibility=hidden is not used).
Note that on x86_64 this is also relaxed and the produced code is like:
lea x(%rip), %rdx
mov (%rdx), %rax
lea 1(%rax), %ecx
mov %ecx, (%rdx)
ret
Tested by running ld test suite, bootstrapping and regtesting GCC with
the patched ld, and building and testing Glibc with the patched ld. No
regression is observed.
Signed-off-by: Xi Ruoyao <xry111@xry111.site>
---
bfd/elfnn-loongarch.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
Comments
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: > > extern int x; > int f() { return x++; } > > and b.c is: > > int x = 114514; > > If compiling and linking with: > > gcc -shared -fPIC -O2 -fvisibility=hidden a.c b.c > > Then the la.got in a.o should be relaxed to la.pcrel, and the resulted f > should be like: > > pcaddi $t0, x > ldptr.w $a0, $t0, 0 > addi.w $t1, $a0, 1 > stptr.w $t1, $t0, 0 > ret > > Remove bfd_link_executable from the condition of la.got -> la.pcrel > relaxation so this will really happen. The SYMBOL_REFERENCES_LOCAL > check is enough not to wrongly relax preemptable symbols (for e.g. > when -fvisibility=hidden is not used). > > Note that on x86_64 this is also relaxed and the produced code is like: > > lea x(%rip), %rdx > mov (%rdx), %rax > lea 1(%rax), %ecx > mov %ecx, (%rdx) > ret > > Tested by running ld test suite, bootstrapping and regtesting GCC with > the patched ld, and building and testing Glibc with the patched ld. No > regression is observed. > > Signed-off-by: Xi Ruoyao <xry111@xry111.site> > --- > bfd/elfnn-loongarch.c | 3 +-- > 1 file changed, 1 insertion(+), 2 deletions(-) > > 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 *sec, > else > continue; > > - if (h && bfd_link_executable (info) > - && SYMBOL_REFERENCES_LOCAL (info, h)) > + if (h && SYMBOL_REFERENCES_LOCAL (info, h)) > local_got = true; > symtype = h->type; > }
This patch have been merged. Thank you very much. 在 2023/12/15 下午8:22, Xi Ruoyao 写道: > 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: >> >> extern int x; >> int f() { return x++; } >> >> and b.c is: >> >> int x = 114514; >> >> If compiling and linking with: >> >> gcc -shared -fPIC -O2 -fvisibility=hidden a.c b.c >> >> Then the la.got in a.o should be relaxed to la.pcrel, and the resulted f >> should be like: >> >> pcaddi $t0, x >> ldptr.w $a0, $t0, 0 >> addi.w $t1, $a0, 1 >> stptr.w $t1, $t0, 0 >> ret >> >> Remove bfd_link_executable from the condition of la.got -> la.pcrel >> relaxation so this will really happen. The SYMBOL_REFERENCES_LOCAL >> check is enough not to wrongly relax preemptable symbols (for e.g. >> when -fvisibility=hidden is not used). >> >> Note that on x86_64 this is also relaxed and the produced code is like: >> >> lea x(%rip), %rdx >> mov (%rdx), %rax >> lea 1(%rax), %ecx >> mov %ecx, (%rdx) >> ret >> >> Tested by running ld test suite, bootstrapping and regtesting GCC with >> the patched ld, and building and testing Glibc with the patched ld. No >> regression is observed. >> >> Signed-off-by: Xi Ruoyao <xry111@xry111.site> >> --- >> bfd/elfnn-loongarch.c | 3 +-- >> 1 file changed, 1 insertion(+), 2 deletions(-) >> >> 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 *sec, >> else >> continue; >> >> - if (h && bfd_link_executable (info) >> - && SYMBOL_REFERENCES_LOCAL (info, h)) >> + if (h && SYMBOL_REFERENCES_LOCAL (info, h)) >> local_got = true; >> symtype = h->type; >> }
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 *sec, else continue; - if (h && bfd_link_executable (info) - && SYMBOL_REFERENCES_LOCAL (info, h)) + if (h && SYMBOL_REFERENCES_LOCAL (info, h)) local_got = true; symtype = h->type; }