public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] LoongArch: Disable explicit reloc for TLS LD/GD with -mexplicit-relocs=auto
@ 2024-01-22 18:42 Xi Ruoyao
  2024-01-23  2:37 ` chenglulu
  0 siblings, 1 reply; 4+ messages in thread
From: Xi Ruoyao @ 2024-01-22 18:42 UTC (permalink / raw)
  To: gcc-patches; +Cc: chenglulu, i, xuchenghua, mengqinggang, Xi Ruoyao

Binutils 2.42 supports TLS LD/GD relaxation which requires the assembler
macro.

gcc/ChangeLog:

	* config/loongarch/loongarch.cc (loongarch_explicit_relocs_p):
	If la_opt_explicit_relocs is EXPLICIT_RELOCS_AUTO, return false
	for SYMBOL_TLS_LDM and SYMBOL_TLS_GD.
	(loongarch_call_tls_get_addr): Do not split symbols of
	SYMBOL_TLS_LDM or SYMBOL_TLS_GD if la_opt_explicit_relocs is
	EXPLICIT_RELOCS_AUTO.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c: Check
	for la.tls.ld and la.tls.gd.
---

Bootstrapped & regtested on loongarch64-linux-gnu.  Ok for trunk?

 gcc/config/loongarch/loongarch.cc                        | 9 ++++-----
 .../loongarch/explicit-relocs-auto-tls-ld-gd.c           | 3 ++-
 2 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
index 82467474288..58df0b5637d 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -1970,11 +1970,10 @@ loongarch_explicit_relocs_p (enum loongarch_symbol_type type)
     {
       case SYMBOL_TLS_IE:
       case SYMBOL_TLS_LE:
-      case SYMBOL_TLSGD:
-      case SYMBOL_TLSLDM:
       case SYMBOL_PCREL64:
-	/* The linker don't know how to relax TLS accesses or 64-bit
-	   pc-relative accesses.  */
+	/* TLS IE cannot be relaxed.  TLS LE relaxation does not require
+	   using the assembly macro.  The linker does not relax 64-bit
+	   pc-relative accesses as at now.  */
 	return true;
       case SYMBOL_GOT_DISP:
 	/* The linker don't know how to relax GOT accesses in extreme
@@ -2789,7 +2788,7 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0)
 
   start_sequence ();
 
-  if (la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE)
+  if (la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS)
     {
       /* Split tls symbol to high and low.  */
       rtx high = gen_rtx_HIGH (Pmode, copy_rtx (loc));
diff --git a/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c b/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c
index 957ff98df62..ca55fcfc53e 100644
--- a/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c
+++ b/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c
@@ -6,4 +6,5 @@ extern __thread int b __attribute__((visibility("default")));
 
 int test() { return a + b; }
 
-/* { dg-final { scan-assembler-not "la.tls" { target tls_native } } } */
+/* { dg-final { scan-assembler "la\\.tls\\.ld" { target tls_native } } } */
+/* { dg-final { scan-assembler "la\\.tls\\.gd" { target tls_native } } } */
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] LoongArch: Disable explicit reloc for TLS LD/GD with -mexplicit-relocs=auto
  2024-01-22 18:42 [PATCH] LoongArch: Disable explicit reloc for TLS LD/GD with -mexplicit-relocs=auto Xi Ruoyao
@ 2024-01-23  2:37 ` chenglulu
  2024-01-23  8:04   ` Pushed: [PATCH v2] " Xi Ruoyao
  0 siblings, 1 reply; 4+ messages in thread
From: chenglulu @ 2024-01-23  2:37 UTC (permalink / raw)
  To: Xi Ruoyao, gcc-patches; +Cc: i, xuchenghua, mengqinggang

LGTM!

Thanks!

在 2024/1/23 上午2:42, Xi Ruoyao 写道:
> Binutils 2.42 supports TLS LD/GD relaxation which requires the assembler
> macro.
>
> gcc/ChangeLog:
>
> 	* config/loongarch/loongarch.cc (loongarch_explicit_relocs_p):
> 	If la_opt_explicit_relocs is EXPLICIT_RELOCS_AUTO, return false
> 	for SYMBOL_TLS_LDM and SYMBOL_TLS_GD.
> 	(loongarch_call_tls_get_addr): Do not split symbols of
> 	SYMBOL_TLS_LDM or SYMBOL_TLS_GD if la_opt_explicit_relocs is
> 	EXPLICIT_RELOCS_AUTO.
>
> gcc/testsuite/ChangeLog:
>
> 	* gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c: Check
> 	for la.tls.ld and la.tls.gd.
> ---
>
> Bootstrapped & regtested on loongarch64-linux-gnu.  Ok for trunk?
>
>   gcc/config/loongarch/loongarch.cc                        | 9 ++++-----
>   .../loongarch/explicit-relocs-auto-tls-ld-gd.c           | 3 ++-
>   2 files changed, 6 insertions(+), 6 deletions(-)
>
> diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
> index 82467474288..58df0b5637d 100644
> --- a/gcc/config/loongarch/loongarch.cc
> +++ b/gcc/config/loongarch/loongarch.cc
> @@ -1970,11 +1970,10 @@ loongarch_explicit_relocs_p (enum loongarch_symbol_type type)
>       {
>         case SYMBOL_TLS_IE:
>         case SYMBOL_TLS_LE:
> -      case SYMBOL_TLSGD:
> -      case SYMBOL_TLSLDM:
>         case SYMBOL_PCREL64:
> -	/* The linker don't know how to relax TLS accesses or 64-bit
> -	   pc-relative accesses.  */
> +	/* TLS IE cannot be relaxed.  TLS LE relaxation does not require
> +	   using the assembly macro.  The linker does not relax 64-bit
> +	   pc-relative accesses as at now.  */
>   	return true;
>         case SYMBOL_GOT_DISP:
>   	/* The linker don't know how to relax GOT accesses in extreme
> @@ -2789,7 +2788,7 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0)
>   
>     start_sequence ();
>   
> -  if (la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE)
> +  if (la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS)
>       {
>         /* Split tls symbol to high and low.  */
>         rtx high = gen_rtx_HIGH (Pmode, copy_rtx (loc));
> diff --git a/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c b/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c
> index 957ff98df62..ca55fcfc53e 100644
> --- a/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c
> +++ b/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c
> @@ -6,4 +6,5 @@ extern __thread int b __attribute__((visibility("default")));
>   
>   int test() { return a + b; }
>   
> -/* { dg-final { scan-assembler-not "la.tls" { target tls_native } } } */
> +/* { dg-final { scan-assembler "la\\.tls\\.ld" { target tls_native } } } */
> +/* { dg-final { scan-assembler "la\\.tls\\.gd" { target tls_native } } } */


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Pushed: [PATCH v2] LoongArch: Disable explicit reloc for TLS LD/GD with -mexplicit-relocs=auto
  2024-01-23  2:37 ` chenglulu
@ 2024-01-23  8:04   ` Xi Ruoyao
  2024-01-23  8:35     ` chenglulu
  0 siblings, 1 reply; 4+ messages in thread
From: Xi Ruoyao @ 2024-01-23  8:04 UTC (permalink / raw)
  To: chenglulu, gcc-patches; +Cc: i, xuchenghua, mengqinggang

[-- Attachment #1: Type: text/plain, Size: 316 bytes --]

On Tue, 2024-01-23 at 10:37 +0800, chenglulu wrote:
> LGTM!
> 
> Thanks!

Pushed v2 as attached.  The only change is in the comment: Qinggang told
me TLE LE relaxation actually *requires* explicit relocs.


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

[-- Attachment #2: v2-0001-LoongArch-Disable-explicit-reloc-for-TLS-LD-GD-wi.patch --]
[-- Type: text/x-patch, Size: 2897 bytes --]

From f12317306ee714aed0ca7ed01cafa520296b4c4c Mon Sep 17 00:00:00 2001
From: Xi Ruoyao <xry111@xry111.site>
Date: Mon, 22 Jan 2024 18:07:42 +0800
Subject: [PATCH v2] LoongArch: Disable explicit reloc for TLS LD/GD with
 -mexplicit-relocs=auto

Binutils 2.42 supports TLS LD/GD relaxation which requires the assembler
macro.

gcc/ChangeLog:

	* config/loongarch/loongarch.cc (loongarch_explicit_relocs_p):
	If la_opt_explicit_relocs is EXPLICIT_RELOCS_AUTO, return false
	for SYMBOL_TLS_LDM and SYMBOL_TLS_GD.
	(loongarch_call_tls_get_addr): Do not split symbols of
	SYMBOL_TLS_LDM or SYMBOL_TLS_GD if la_opt_explicit_relocs is
	EXPLICIT_RELOCS_AUTO.

gcc/testsuite/ChangeLog:

	* gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c: Check
	for la.tls.ld and la.tls.gd.
---
 gcc/config/loongarch/loongarch.cc                      | 10 +++++-----
 .../loongarch/explicit-relocs-auto-tls-ld-gd.c         |  3 ++-
 2 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/gcc/config/loongarch/loongarch.cc b/gcc/config/loongarch/loongarch.cc
index 82467474288..072c68d97e3 100644
--- a/gcc/config/loongarch/loongarch.cc
+++ b/gcc/config/loongarch/loongarch.cc
@@ -1970,11 +1970,11 @@ loongarch_explicit_relocs_p (enum loongarch_symbol_type type)
     {
       case SYMBOL_TLS_IE:
       case SYMBOL_TLS_LE:
-      case SYMBOL_TLSGD:
-      case SYMBOL_TLSLDM:
       case SYMBOL_PCREL64:
-	/* The linker don't know how to relax TLS accesses or 64-bit
-	   pc-relative accesses.  */
+	/* TLS IE cannot be relaxed.  TLS LE relaxation is different from
+	   the normal R_LARCH_RELAX-based relaxation and it **requires**
+	   using the explicit %le_{lo12,hi20,add}_r relocs.  The linker
+	   does not relax 64-bit pc-relative accesses as at now.  */
 	return true;
       case SYMBOL_GOT_DISP:
 	/* The linker don't know how to relax GOT accesses in extreme
@@ -2789,7 +2789,7 @@ loongarch_call_tls_get_addr (rtx sym, enum loongarch_symbol_type type, rtx v0)
 
   start_sequence ();
 
-  if (la_opt_explicit_relocs != EXPLICIT_RELOCS_NONE)
+  if (la_opt_explicit_relocs == EXPLICIT_RELOCS_ALWAYS)
     {
       /* Split tls symbol to high and low.  */
       rtx high = gen_rtx_HIGH (Pmode, copy_rtx (loc));
diff --git a/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c b/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c
index 957ff98df62..ca55fcfc53e 100644
--- a/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c
+++ b/gcc/testsuite/gcc.target/loongarch/explicit-relocs-auto-tls-ld-gd.c
@@ -6,4 +6,5 @@ extern __thread int b __attribute__((visibility("default")));
 
 int test() { return a + b; }
 
-/* { dg-final { scan-assembler-not "la.tls" { target tls_native } } } */
+/* { dg-final { scan-assembler "la\\.tls\\.ld" { target tls_native } } } */
+/* { dg-final { scan-assembler "la\\.tls\\.gd" { target tls_native } } } */
-- 
2.43.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Pushed: [PATCH v2] LoongArch: Disable explicit reloc for TLS LD/GD with -mexplicit-relocs=auto
  2024-01-23  8:04   ` Pushed: [PATCH v2] " Xi Ruoyao
@ 2024-01-23  8:35     ` chenglulu
  0 siblings, 0 replies; 4+ messages in thread
From: chenglulu @ 2024-01-23  8:35 UTC (permalink / raw)
  To: Xi Ruoyao, gcc-patches; +Cc: i, xuchenghua, mengqinggang


在 2024/1/23 下午4:04, Xi Ruoyao 写道:
> On Tue, 2024-01-23 at 10:37 +0800, chenglulu wrote:
>> LGTM!
>>
>> Thanks!
> Pushed v2 as attached.  The only change is in the comment: Qinggang told
> me TLE LE relaxation actually *requires* explicit relocs.
>
>
I think one of the reasons is also because we cannot properly use a 
macro to describe TLS LE relaxation.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-23  8:35 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-22 18:42 [PATCH] LoongArch: Disable explicit reloc for TLS LD/GD with -mexplicit-relocs=auto Xi Ruoyao
2024-01-23  2:37 ` chenglulu
2024-01-23  8:04   ` Pushed: [PATCH v2] " Xi Ruoyao
2024-01-23  8:35     ` chenglulu

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).