From patchwork Wed Aug 9 19:50:02 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella X-Patchwork-Id: 109748 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1339606qge; Wed, 9 Aug 2017 12:50:22 -0700 (PDT) X-Received: by 10.99.175.82 with SMTP id s18mr8628429pgo.406.1502308222872; Wed, 09 Aug 2017 12:50:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502308222; cv=none; d=google.com; s=arc-20160816; b=EppgwDvNvw+VAieYpEomth4g4S01o31AJts2MZe9LiTlEdDkD8GZtt20tMQgmCeqra 6unbxEcynxuvqyh3p9jIxmNxZ/ygtMmVFxul78kuzFOpEm0pjU+1B/W5RMM+2nu7sQWO RraLlDOo28TC26VkqvZPMNFghkiYb/Ok2SbB/DwP3c6JOeRBXbgiozHRnbwMUU7qja4h Aw6Th7c6snbsJiI7/f5jDZkAbYLzqz3QiCDwqbv3I3a/5MnyIh9FI6RyPLwkt675y3FA wdOfLXSERongGBrjWyeCRhmzq+2zwQu6+k2T3lN3uNzqsLAtpgKhDq1zctTDBYDUIkiS YVRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:delivered-to:sender:list-help :list-post:list-archive:list-subscribe:list-unsubscribe:list-id :precedence:mailing-list:dkim-signature:domainkey-signature :arc-authentication-results; bh=Dqkhzzoe7Nl6k4LnBp019XySlXnQbKxhfxim0DiSpiQ=; b=WZq5s2ikL+rTTWKkjV2t+uACX1hbZls1/5U6r08ccZ1tdEcKJ3TC41akjm2DOQC66H AhddRYwPRTpowRtqK1gxhRo+880ypIcxhILcZwFW0M0I62gzB9E4b2KYUZoFxUh/k5vj B/PWQBwQuCh/K5gkqLaejo5ihEchhsUvRGP9K3WttPZxWniu3gmvqqqYJf6pWfExZp2R JEHfO/yry0xDI5ylMr3wG2eJfHi81cKsWLqhpL2/jb6WsFmVbqWG2PG++QB5SOaMCAyJ aTu8vZ4l7/vmemD4ZcCUKdjBLV6yjynu4oDID3QhMjbgx9eJ+wb9hqIutX9HKzCUfChT AmEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=lC42I365; spf=pass (google.com: domain of libc-alpha-return-82956-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-82956-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id e16si3220197pli.913.2017.08.09.12.50.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Aug 2017 12:50:22 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-return-82956-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=lC42I365; spf=pass (google.com: domain of libc-alpha-return-82956-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=libc-alpha-return-82956-patch=linaro.org@sourceware.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; q=dns; s= default; b=pLTLdrCclafMb9LTVwGZh5WimxauTkZwjyZF5430AMDqCA9VnT1cc 9Z3zTbGpU3GF7+4kLUP6DPHe/VAtznwex0VKiW4Ca/EjxWSavfM1m34nHv6aP5Ks abqZBibGPidqlUtwzOCJHsAUp0TVMZ4KCov2qiMJOveMHMx8PPKR0E= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id; s=default; bh=JEthjyBrZR34xmzSud311ds29Os=; b=lC42I365dh1gyfKihWN49tPiI8LB 4F169w6yX237eFMdH97Sf7mD7OfXGIDRP3HlZO0wb+Mf8mMDogQpGSk0Nz/rhi6G 2oqK+Yagj7+ujNObmFncc3KGiYzR9UyE7PT6nABqGX0ucbZLGO6uDM7Foi+OnM4+ rpO40AUFMYD2PpA= Received: (qmail 27088 invoked by alias); 9 Aug 2017 19:50:12 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 27008 invoked by uid 89); 9 Aug 2017 19:50:11 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-26.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=201702 X-HELO: mail-qt0-f172.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id; bh=Dqkhzzoe7Nl6k4LnBp019XySlXnQbKxhfxim0DiSpiQ=; b=Jo2GwCjukYOzmGuSMcCEAHeD6h2MihmwFDIgesTuR52zEhQ5Q9WtvrFlJdC4/2eIhz mC5CUUq1hY5s/Rn79+3OXbFsvULxsh0X0YP68CqQzDvCzKeEuZqD+Tzc0RHbjkFHZQTv llxhlGLDLFDAYV4pNwsm2DqUsDw5je/uut90xQNYm9NIlCODQ6RZxPuD56qqYcCtubHr 7J2WmrBOikJZRoNF+F2ERn2tx7RLuo8BWo9WQdGsyd9+qN4AisQT/1zENIwJTcc/26pL w8p337RyIq2/jt7RqIPJqCELUtdH1mLrEPyvNBgzzzx0imZjYVH/jFL7nLmNXfteazyk MUmg== X-Gm-Message-State: AHYfb5iDeVcpt8nMQlUbtZGuC16PC5n09FBC7afU1sVDhZtRm3l6FbHg XJ2T7/8K+tpsfdu0PlAY1A== X-Received: by 10.200.48.49 with SMTP id f46mr13129945qte.88.1502308206953; Wed, 09 Aug 2017 12:50:06 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH v4] aarch64: Add split-stack TCB field Date: Wed, 9 Aug 2017 16:50:02 -0300 Message-Id: <1502308202-23263-1-git-send-email-adhemerval.zanella@linaro.org> This is an update of my previous version [1] with symbol and ABI version adjusted to 2.27. GCC [2] and GOLD [3] patch were already submitted for review. This patch adds split-stack support pointer guard on glibc for aarch64. Different from other architectures (powerpc, s390) where the memory is placed on TCB, aarch64 one is placed before thread pointer initial position. It has an advantage over extending TCB because for aarch64 TLS variable placement take in consideration tcbhead_t size and by changing its value would require to also update the static linker (and it would also add incompatibility with glibc and older linkers). For aarch64 tcb direct access is fastest for thread local variable on all mode and related TLS access. It requires just a direct load with displacement of -8 (since thread pointer points to tcbhead_t). It also adds a loader symbol (__tcb_private_ss) to signal the existence of the split stack guard area. Checked on aarch64-linux-gnu. * sysdeps/aarch64/Makefile [$(subdir) = elf] (sysdeps-dl-routines): Add tcb-version. * sysdeps/aarch64/Versions [ld] (GLIBC_2.26): Add __libc_tcb_private_ss. * sysdeps/aarch64/nptl/tls.h (tcbprehead_t): New struct. (TLS_PRE_TCB_SIZE): Take tcbprehead_t in consideration. (TLS_DEFINE_INIT_TP): Likewise. (THREAD_SELF): Likewise. (DB_THREAD_SELF): Likewise. * sysdeps/aarch64/tcb-version.c: New file. * sysdeps/unix/sysv/linux/aarch64/ld.abilist (GLIBC_2.26): Add. (__libc_tcb_private_ss): Likewise. * sysdeps/aarch64/nptl/tcb-offsets.sym (PTHREAD_SIZEOF): Rename to PTHREAD_PRE_TCB_SIZE. * sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h [!IS_IN (libprthread) && !IS_IN (libc) (SINGLE_THREAD_P): Use PTHREAD_PRE_TCB_SIZE instead of PTHREAD_SIZEOF. [1] https://sourceware.org/ml/libc-alpha/2017-02/msg00272.html [2] https://gcc.gnu.org/ml/gcc-patches/2017-07/msg01717.html [3] https://sourceware.org/ml/binutils/2017-07/msg00362.html --- ChangeLog | 20 ++++++++++++++++++++ sysdeps/aarch64/Makefile | 2 +- sysdeps/aarch64/Versions | 8 ++++++++ sysdeps/aarch64/nptl/tcb-offsets.sym | 2 +- sysdeps/aarch64/nptl/tls.h | 25 ++++++++++++++++++++----- sysdeps/aarch64/tcb-version.c | 23 +++++++++++++++++++++++ sysdeps/unix/sysv/linux/aarch64/ld.abilist | 2 ++ sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h | 2 +- 8 files changed, 76 insertions(+), 8 deletions(-) create mode 100644 sysdeps/aarch64/tcb-version.c -- 2.7.4 diff --git a/sysdeps/aarch64/Makefile b/sysdeps/aarch64/Makefile index 562c137..0155988 100644 --- a/sysdeps/aarch64/Makefile +++ b/sysdeps/aarch64/Makefile @@ -5,7 +5,7 @@ CFLAGS-backtrace.c += -funwind-tables endif ifeq ($(subdir),elf) -sysdep-dl-routines += tlsdesc dl-tlsdesc +sysdep-dl-routines += tlsdesc dl-tlsdesc tcb-version gen-as-const-headers += dl-link.sym endif diff --git a/sysdeps/aarch64/Versions b/sysdeps/aarch64/Versions index e1aa44f..04ad5ff 100644 --- a/sysdeps/aarch64/Versions +++ b/sysdeps/aarch64/Versions @@ -3,3 +3,11 @@ libc { _mcount; } } + +ld { + GLIBC_2.27 { + # Symbol used to version control the private GLIBC TCB split-stack + # field. + __libc_tcb_private_ss; + } +} diff --git a/sysdeps/aarch64/nptl/tcb-offsets.sym b/sysdeps/aarch64/nptl/tcb-offsets.sym index 238647d..6004379 100644 --- a/sysdeps/aarch64/nptl/tcb-offsets.sym +++ b/sysdeps/aarch64/nptl/tcb-offsets.sym @@ -3,4 +3,4 @@ PTHREAD_MULTIPLE_THREADS_OFFSET offsetof (struct pthread, header.multiple_threads) PTHREAD_TID_OFFSET offsetof (struct pthread, tid) -PTHREAD_SIZEOF sizeof (struct pthread) +PTHREAD_PRE_TCB_SIZE TLS_PRE_TCB_SIZE diff --git a/sysdeps/aarch64/nptl/tls.h b/sysdeps/aarch64/nptl/tls.h index 175df39..82fca25 100644 --- a/sysdeps/aarch64/nptl/tls.h +++ b/sysdeps/aarch64/nptl/tls.h @@ -26,6 +26,7 @@ # include # include # include +# include #else /* __ASSEMBLER__ */ # include @@ -49,6 +50,12 @@ typedef struct void *private; } tcbhead_t; +typedef struct +{ + /* GCC split stack support. */ + void *__private_ss; +} tcbprehead_t; + /* This is the size of the initial TCB. */ # define TLS_INIT_TCB_SIZE sizeof (tcbhead_t) @@ -58,8 +65,14 @@ typedef struct /* This is the size of the TCB. */ # define TLS_TCB_SIZE sizeof (tcbhead_t) -/* This is the size we need before TCB. */ -# define TLS_PRE_TCB_SIZE sizeof (struct pthread) +/* This is the size we need before TCB. Check if there is room for + tcbprehead_t in struct pthread's final padding and if not add it on + required pre-tcb size. */ +# define TLS_PRE_TCB_SIZE \ + (sizeof (struct pthread) \ + + (PTHREAD_STRUCT_END_PADDING < sizeof (tcbprehead_t) \ + ? ALIGN_UP (sizeof (tcbprehead_t), __alignof__ (struct pthread)) \ + : 0)) /* Alignment requirements for the TCB. */ # define TLS_TCB_ALIGN __alignof__ (struct pthread) @@ -84,7 +97,8 @@ typedef struct ({ __asm __volatile ("msr tpidr_el0, %0" : : "r" (tcbp)); NULL; }) /* Value passed to 'clone' for initialization of the thread register. */ -# define TLS_DEFINE_INIT_TP(tp, pd) void *tp = (pd) + 1 +# define TLS_DEFINE_INIT_TP(tp, pd) \ + void *tp = (void*)((uintptr_t) (pd) + TLS_PRE_TCB_SIZE) /* Return the address of the dtv for the current thread. */ # define THREAD_DTV() \ @@ -92,11 +106,12 @@ typedef struct /* Return the thread descriptor for the current thread. */ # define THREAD_SELF \ - ((struct pthread *)__builtin_thread_pointer () - 1) + ((struct pthread *)((uintptr_t) __builtin_thread_pointer () \ + - TLS_PRE_TCB_SIZE)) /* Magic for libthread_db to know how to do THREAD_SELF. */ # define DB_THREAD_SELF \ - CONST_THREAD_AREA (64, sizeof (struct pthread)) + CONST_THREAD_AREA (64, TLS_PRE_TCB_SIZE) /* Access to data in the thread descriptor is easy. */ # define THREAD_GETMEM(descr, member) \ diff --git a/sysdeps/aarch64/tcb-version.c b/sysdeps/aarch64/tcb-version.c new file mode 100644 index 0000000..c94e5d3 --- /dev/null +++ b/sysdeps/aarch64/tcb-version.c @@ -0,0 +1,23 @@ +/* TCB field abi advertise symbols. + Copyright (C) 2017 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public License as + published by the Free Software Foundation; either version 2.1 of the + License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include + +/* Symbol used to version control the private GLIBC TCB split-stack + field. */ +long int attribute_relro __libc_tcb_private_ss; diff --git a/sysdeps/unix/sysv/linux/aarch64/ld.abilist b/sysdeps/unix/sysv/linux/aarch64/ld.abilist index ec7f617..b69883a 100644 --- a/sysdeps/unix/sysv/linux/aarch64/ld.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/ld.abilist @@ -8,3 +8,5 @@ GLIBC_2.17 calloc F GLIBC_2.17 free F GLIBC_2.17 malloc F GLIBC_2.17 realloc F +GLIBC_2.27 GLIBC_2.27 A +GLIBC_2.27 __libc_tcb_private_ss D 0x8 diff --git a/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h b/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h index 4be2259..e4ac2ba 100644 --- a/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h +++ b/sysdeps/unix/sysv/linux/aarch64/sysdep-cancel.h @@ -114,7 +114,7 @@ extern int __local_multiple_threads attribute_hidden; # else # define SINGLE_THREAD_P(R) \ mrs x##R, tpidr_el0; \ - sub x##R, x##R, PTHREAD_SIZEOF; \ + sub x##R, x##R, PTHREAD_PRE_TCB_SIZE; \ ldr w##R, [x##R, PTHREAD_MULTIPLE_THREADS_OFFSET] # endif # endif