public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
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
Subject: Ping: [PATCH] LoongArch: Allow la.got -> la.pcrel relaxation for shared object
Date: Fri, 15 Dec 2023 20:22:47 +0800	[thread overview]
Message-ID: <5c9d7da55b80be8e6ff11894fcd0c225416859ca.camel@xry111.site> (raw)
In-Reply-To: <20231205190547.52950-1-xry111@xry111.site>

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;
>  	}

-- 
Xi Ruoyao <xry111@xry111.site>
School of Aerospace Science and Technology, Xidian University

  reply	other threads:[~2023-12-15 12:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05 19:05 Xi Ruoyao
2023-12-15 12:22 ` Xi Ruoyao [this message]
2023-12-19  7:48   ` Ping: " mengqinggang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5c9d7da55b80be8e6ff11894fcd0c225416859ca.camel@xry111.site \
    --to=xry111@xry111.site \
    --cc=binutils@sourceware.org \
    --cc=cailulu@loongson.cn \
    --cc=hejinyang@loongson.cn \
    --cc=i.swmail@xen0n.name \
    --cc=liuzhensong@loongson.cn \
    --cc=maskray@google.com \
    --cc=mengqinggang@loongson.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).