* [binutils-gdb] LoongArch: Allow la.got -> la.pcrel relaxation for shared object
@ 2023-12-19 7:42 liu & zhensong
0 siblings, 0 replies; only message in thread
From: liu & zhensong @ 2023-12-19 7:42 UTC (permalink / raw)
To: bfd-cvs
https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=15aacf324fb871871e2162ea8769a9f82c043909
commit 15aacf324fb871871e2162ea8769a9f82c043909
Author: Xi Ruoyao <xry111@xry111.site>
Date: Wed Dec 6 03:05:47 2023 +0800
LoongArch: Allow la.got -> la.pcrel relaxation for shared object
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>
Diff:
---
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 aa88ee8f928..87eb65ab9f7 100644
--- a/bfd/elfnn-loongarch.c
+++ b/bfd/elfnn-loongarch.c
@@ -3993,8 +3993,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;
}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-12-19 7:42 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-19 7:42 [binutils-gdb] LoongArch: Allow la.got -> la.pcrel relaxation for shared object liu & zhensong
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).