From patchwork Fri Jan 22 01:29:31 2021 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: 41788 X-Patchwork-Delegate: azanella@linux.vnet.ibm.com 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 0BBF9398B160; Fri, 22 Jan 2021 01:29:55 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 0BBF9398B160 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1611278995; bh=5kFSRU4NcBIgpq+tVMnscSJ2c5inCLzZD0y/DxZ11rY=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=YjGIV67Y9TDYnP45Z6cst28cJUkH+mZN0tzqsqyK9bSZhH/u/qF1yQYWA9bo6Iji1 hfowAnw0z4jhPs2Om7EClsNMUX0ayM7c83AJytRDELgaol2PveGPB2uaIiBIm2boEq mgSTCmzmZ3eQ1klKv8HwESGwVsj0ZOJbo6DeNv5A= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) by sourceware.org (Postfix) with ESMTPS id 3A77A388C006 for ; Fri, 22 Jan 2021 01:29:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3A77A388C006 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 10M1BH1H017279; Thu, 21 Jan 2021 20:29:49 -0500 Received: from pps.reinject (localhost [127.0.0.1]) by mx0b-001b2d01.pphosted.com with ESMTP id 367mtv8963-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Jan 2021 20:29:49 -0500 Received: from m0098416.ppops.net (m0098416.ppops.net [127.0.0.1]) by pps.reinject (8.16.0.36/8.16.0.36) with SMTP id 10M1DvwF026684; Thu, 21 Jan 2021 20:29:49 -0500 Received: from ppma05wdc.us.ibm.com (1b.90.2fa9.ip4.static.sl-reverse.com [169.47.144.27]) by mx0b-001b2d01.pphosted.com with ESMTP id 367mtv895w-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Thu, 21 Jan 2021 20:29:49 -0500 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 10M1SoBd025247; Fri, 22 Jan 2021 01:29:48 GMT Received: from b03cxnp08025.gho.boulder.ibm.com (b03cxnp08025.gho.boulder.ibm.com [9.17.130.17]) by ppma05wdc.us.ibm.com with ESMTP id 367k0mgphb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 22 Jan 2021 01:29:48 +0000 Received: from b03ledav005.gho.boulder.ibm.com (b03ledav005.gho.boulder.ibm.com [9.17.130.236]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 10M1TlmL28508416 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Fri, 22 Jan 2021 01:29:47 GMT Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id C1378BE051; Fri, 22 Jan 2021 01:29:47 +0000 (GMT) Received: from b03ledav005.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4E515BE04F; Fri, 22 Jan 2021 01:29:46 +0000 (GMT) Received: from linux.ibm.com (unknown [9.160.92.204]) by b03ledav005.gho.boulder.ibm.com (Postfix) with ESMTP; Fri, 22 Jan 2021 01:29:45 +0000 (GMT) To: libc-alpha@sourceware.org Subject: [PATCHv2] powerpc64: Implement TLS using PC-relative addressing Date: Thu, 21 Jan 2021 22:29:31 -0300 Message-Id: <20210122012931.1354527-1-tuliom@linux.ibm.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <87r1qi2ubi.fsf@igel.home> References: <87r1qi2ubi.fsf@igel.home> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.343, 18.0.737 definitions=2021-01-21_11:2021-01-21, 2021-01-21 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 adultscore=0 lowpriorityscore=0 clxscore=1011 phishscore=0 mlxlogscore=999 suspectscore=0 spamscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 mlxscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2101220000 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_H3, RCVD_IN_MSPIKE_WL, 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: Andreas Schwab , amodra@gmail.com Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" Changes since v1: - Dropped the workaround for early GCC 10 versions. We can't get this code to work without having the macro __PCREL__. The previous code was failing if -mcpu=power10 -mno-pcrel was used. - Fixed coding style issues (added space after #defined and removed unnecessary parenthesis). ---8<--- 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..ecfa11cb95 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__ + 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..a0e5c4a832 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__ +/* 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