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 BFEB53858D32 for ; 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 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 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 List-Id: 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 --- 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; } -- 2.43.0