From: Tulio Magno Quites Machado Filho <tuliom@linux.ibm.com>
To: libc-alpha@sourceware.org
Cc: amodra@gmail.com
Subject: [PATCH] powerpc64: Implement TLS using PC-relative addressing
Date: Wed, 30 Sep 2020 16:55:12 -0300 [thread overview]
Message-ID: <20200930195512.724059-1-tuliom@linux.ibm.com> (raw)
As the TOC pointer becomes optional on POWER, TLS access has to be
modified in order to use PC-relative addressing instead of depending on
the TOC pointer availability.
This patch also changes old TLS code to use the new syntax. It's a
purely aesthetical change: the old code still works and the new syntax
helps to move the argument setup instruction away from the call, which
is not used in an inline assembly.
Suggested-by: Alan Modra <amodra@gmail.com>
---
sysdeps/powerpc/mod-tlsopt-powerpc.c | 7 ++++
sysdeps/powerpc/powerpc64/tls-macros.h | 54 ++++++++++++++++++++++----
2 files changed, 53 insertions(+), 8 deletions(-)
diff --git a/sysdeps/powerpc/mod-tlsopt-powerpc.c b/sysdeps/powerpc/mod-tlsopt-powerpc.c
index ee0db12a73..5856dab60b 100644
--- a/sysdeps/powerpc/mod-tlsopt-powerpc.c
+++ b/sysdeps/powerpc/mod-tlsopt-powerpc.c
@@ -24,7 +24,14 @@ tls_get_addr_opt_test (void)
tls_index *tls_arg;
#ifdef __powerpc64__
register unsigned long thread_pointer __asm__ ("r13");
+ /* PC-relative addressing is available when compiling with -mpcrel.
+ The first releases of GCC 10 do support -mpcrel, but do not export
+ __PCREL__. */
+# if defined(__PCREL__) || __GNUC__ <= 10 && defined(_ARCH_PWR10)
+ asm ("pla %0,foo@got@tlsgd@pcrel" : "=r" (tls_arg));
+# else
asm ("addi %0,2,foo@got@tlsgd" : "=r" (tls_arg));
+# endif
#else
register unsigned long thread_pointer __asm__ ("r2");
asm ("bcl 20,31,1f\n1:\t"
diff --git a/sysdeps/powerpc/powerpc64/tls-macros.h b/sysdeps/powerpc/powerpc64/tls-macros.h
index 79a0b2579c..955f8e88da 100644
--- a/sysdeps/powerpc/powerpc64/tls-macros.h
+++ b/sysdeps/powerpc/powerpc64/tls-macros.h
@@ -9,20 +9,56 @@
: "=b" (__result) ); \
__result; \
})
-/* PowerPC64 Initial Exec TLS access. */
-#define TLS_IE(x) \
+
+/* PC-relative addressing is available when compiling with -mpcrel.
+ The first releases of GCC 10 do support -mpcrel, but do not export
+ __PCREL__. */
+#if defined(__PCREL__) || __GNUC__ <= 10 && defined(_ARCH_PWR10)
+/* PowerPC64 Initial Exec TLS access, PC-relative addressing. */
+# define TLS_IE(x) \
({ int * __result; \
- asm ("ld %0," #x "@got@tprel(2)\n\t" \
- "add %0,%0," #x "@tls" \
+ asm ("pld %0," #x "@got@tprel@pcrel\n\t" \
+ "add %0,%0," #x "@tls@pcrel" \
: "=r" (__result) ); \
__result; \
})
+/* PowerPC64 Local Dynamic TLS access, PC-relative addressing. */
+# define TLS_LD(x) \
+ ({ int * __result; \
+ asm ("pla 3, " #x "@got@tlsld@pcrel\n\t" \
+ "bl __tls_get_addr@notoc(" #x "@tlsld)\n\t" \
+ "addis %0,3," #x "@dtprel@ha\n\t" \
+ "addi %0,%0," #x "@dtprel@l" \
+ : "=b" (__result) : \
+ : "3", __TLS_CALL_CLOBBERS); \
+ __result; \
+ })
+
+/* PowerPC64 General Dynamic TLS access, PC-relative addressing. */
+# define TLS_GD(x) \
+ ({ register int *__result __asm__ ("r3"); \
+ asm ("pla 3," #x "@got@tlsgd@pcrel\n\t" \
+ "bl __tls_get_addr@notoc(" #x "@tlsgd)" \
+ : "=r" (__result) : \
+ : __TLS_CALL_CLOBBERS); \
+ __result; \
+ })
+#else
+/* PowerPC64 Initial Exec TLS access. */
+# define TLS_IE(x) \
+ ({ int * __result; \
+ asm ("ld %0," #x "@got@tprel(2)\n\t" \
+ "add %0,%0," #x "@tls" \
+ : "=r" (__result) ); \
+ __result; \
+ })
+
/* PowerPC64 Local Dynamic TLS access. */
-#define TLS_LD(x) \
+# define TLS_LD(x) \
({ int * __result; \
asm ("addi 3,2," #x "@got@tlsld\n\t" \
- "bl __tls_get_addr\n\t" \
+ "bl __tls_get_addr(" #x "@tlsld)\n\t" \
"nop \n\t" \
"addis %0,3," #x "@dtprel@ha\n\t" \
"addi %0,%0," #x "@dtprel@l" \
@@ -30,13 +66,15 @@
: "3", __TLS_CALL_CLOBBERS); \
__result; \
})
+
/* PowerPC64 General Dynamic TLS access. */
-#define TLS_GD(x) \
+# define TLS_GD(x) \
({ register int *__result __asm__ ("r3"); \
asm ("addi 3,2," #x "@got@tlsgd\n\t" \
- "bl __tls_get_addr\n\t" \
+ "bl __tls_get_addr(" #x "@tlsgd)\n\t" \
"nop " \
: "=r" (__result) : \
: __TLS_CALL_CLOBBERS); \
__result; \
})
+#endif
--
2.25.4
next reply other threads:[~2020-09-30 19:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-30 19:55 Tulio Magno Quites Machado Filho [this message]
2020-10-01 8:49 ` Florian Weimer
2020-10-01 11:15 ` Alan Modra
2020-10-01 9:01 ` Andreas Schwab
2021-01-22 1:29 ` [PATCHv2] " Tulio Magno Quites Machado Filho
2021-01-25 15:20 ` Tulio Magno Quites Machado Filho
2021-01-25 17:13 ` Adhemerval Zanella
2021-01-25 20:22 ` Tulio Magno Quites Machado Filho
2021-01-27 11:16 ` Alan Modra
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=20200930195512.724059-1-tuliom@linux.ibm.com \
--to=tuliom@linux.ibm.com \
--cc=amodra@gmail.com \
--cc=libc-alpha@sourceware.org \
/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).