From patchwork Wed Sep 30 19:55:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tulio Magno Quites Machado Filho X-Patchwork-Id: 40555 X-Patchwork-Delegate: schwab@linux-m68k.org Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CFFF53851C08; Wed, 30 Sep 2020 19:55:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CFFF53851C08 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1601495747; bh=cVzLqWfv2SjXRE3gnaxkTuhvzrT5/CSjdSGo8VyWako=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=tynWiRhzdgPS+dnRA2H5sQqJJEBFx/G8q0bv1DV46BZoYkbynuuw6aaRnu4yo55SG xZjMmFSWRiXbzz2Zz6NSP5jYrmp4JtkAPix8x4WaZWFt2CjbzoOxZvFQaA+PP9g3F6 Fn2JkidoFKCZxF/gTr7RMNs8LWlAY0VzGHkZsn7M= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) by sourceware.org (Postfix) with ESMTPS id 3553B3857C67 for ; Wed, 30 Sep 2020 19:55:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3553B3857C67 Received: from pps.filterd (m0187473.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 08UJXA1N129373 for ; Wed, 30 Sep 2020 15:55:44 -0400 Received: from pps.reinject (localhost [127.0.0.1]) by mx0a-001b2d01.pphosted.com with ESMTP id 33vvwaec88-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT) for ; Wed, 30 Sep 2020 15:55:43 -0400 Received: from m0187473.ppops.net (m0187473.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 08UJXMj5129898 for ; Wed, 30 Sep 2020 15:55:42 -0400 Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0a-001b2d01.pphosted.com with ESMTP id 33vvwaec7g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Sep 2020 15:55:42 -0400 Received: from pps.filterd (ppma05wdc.us.ibm.com [127.0.0.1]) by ppma05wdc.us.ibm.com (8.16.0.42/8.16.0.42) with SMTP id 08UJqPid002139; Wed, 30 Sep 2020 19:55:41 GMT Received: from b03cxnp07029.gho.boulder.ibm.com (b03cxnp07029.gho.boulder.ibm.com [9.17.130.16]) by ppma05wdc.us.ibm.com with ESMTP id 33sw99g6mw-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Wed, 30 Sep 2020 19:55:41 +0000 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07029.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 08UJteiR26804510 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 30 Sep 2020 19:55:40 GMT Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id CA8B278060; Wed, 30 Sep 2020 19:55:40 +0000 (GMT) Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6C0F57805C; Wed, 30 Sep 2020 19:55:40 +0000 (GMT) Received: from linux.ibm.com (unknown [9.160.164.208]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP; Wed, 30 Sep 2020 19:55:40 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCH] powerpc64: Implement TLS using PC-relative addressing Date: Wed, 30 Sep 2020 16:55:12 -0300 Message-Id: <20200930195512.724059-1-tuliom@linux.ibm.com> X-Mailer: git-send-email 2.25.4 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.235, 18.0.687 definitions=2020-09-30_10:2020-09-30, 2020-09-30 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 bulkscore=0 impostorscore=0 suspectscore=1 spamscore=0 priorityscore=1501 mlxscore=0 malwarescore=0 adultscore=0 clxscore=1015 mlxlogscore=759 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2006250000 definitions=main-2009300157 X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Tulio Magno Quites Machado Filho via Libc-alpha From: Tulio Magno Quites Machado Filho Reply-To: Tulio Magno Quites Machado Filho Cc: amodra@gmail.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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 --- 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