From patchwork Thu Mar 5 19:22:03 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 184233 Delivered-To: patch@linaro.org Received: by 2002:a92:1f12:0:0:0:0:0 with SMTP id i18csp6535257ile; Thu, 5 Mar 2020 11:22:22 -0800 (PST) X-Google-Smtp-Source: ADFU+vuYDDy94d9fPxx7UDhmCSsNt3kEbBxM5nPyenplivxrCwzNqQzHm3LZxbgVpHqUu5anmfEw X-Received: by 2002:a05:6808:7dd:: with SMTP id f29mr448622oij.67.1583436142385; Thu, 05 Mar 2020 11:22:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1583436142; cv=none; d=google.com; s=arc-20160816; b=w/CdLuAuE1bCkTMzy3yvNj0qiPxfx7pr1LBENV6duZENapfP+UtBvtuxqwtpSSJexk oevooQD5wsgx9GeeVbdrT8P3J0UEelNRZYNppa7pIOC2V7T0RfijP3zqUhrmMQMrXNZD OvPFk3GGy94WPUk22DlueUZQQ7OXFWVNPUb0Le3XBUIok++yrQcs2z/1V8hg6pMaF8f3 MbyvUWJZIa6awz/xozcvrQpZpIxqy2vwOckufGnMIqWPSr7HYvhOeXzFg9g8lF4cvowW HutJZCORbFKbbQPgyFSp3ofXtlknhKbVLUoy92nNwFb3Qg+9RlDpRy39ODnnElcJ67xP xfHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:date:subject:to:from:dkim-signature:delivered-to:sender :list-help:list-post:list-archive:list-subscribe:list-unsubscribe :list-id:precedence:mailing-list:dkim-signature:domainkey-signature; bh=Xzfgp7/Rzht+8qhrDq3GKuo19NhHqTgkeAENeB2lMKw=; b=yhpcWEEf8pjXYVsXaQRg3XsrOuyUy3Mzy09XIvIbtF0tnbAff05KLOJ8n7IYHdvfDu qtnbtp1xR3J6iTNLc+VdZ06YAnr87hUAexrspT5nDiDbrpuB/yBqvHGk1R9pqPRMyc/l CQJK947lPc9StZ/x8cfFiGz0T0NHppf6YArnOzzqzWwfw1wdK9mNvIYWl+l5d2CvoO2R DJEu9Wi8256wj5AKCic/iyvqxblJtJmjAxLwyeWDaAFEY/gWLMRV9wBOIhIFTtvP3GKz oxTfIJsscxe2cO7dvoXVVzDePZqBj2VKdrNYAg3x8xF4LYVg4/Zq7R5eBlXr3Yw4XSO0 TKfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=gWPW7flu; dkim=pass header.i=@linaro.org header.s=google header.b=xgtwPjDB; spf=pass (google.com: domain of libc-alpha-return-110320-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-110320-patch=linaro.org@sourceware.org"; dmarc=pass (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 z81si3927096oia.184.2020.03.05.11.22.22 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 05 Mar 2020 11:22:22 -0800 (PST) Received-SPF: pass (google.com: domain of libc-alpha-return-110320-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=gWPW7flu; dkim=pass header.i=@linaro.org header.s=google header.b=xgtwPjDB; spf=pass (google.com: domain of libc-alpha-return-110320-patch=linaro.org@sourceware.org designates 209.132.180.131 as permitted sender) smtp.mailfrom="libc-alpha-return-110320-patch=linaro.org@sourceware.org"; dmarc=pass (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=J30EBfGoLfKrf3isBXhbowJCz2dj2IgobVGRThhCs5ZOtvcUMFzHq iLyCA9Au+q41oQQpgQ5zoZRyjmXSR4kPOlPcNqeJDa/MEwhFf8DI69CeO4m+sVbH OUzYrsiYqvKsvxAm/8emrffGlVmKC9SEzu4YEplAa/STykJaxtiTDo= 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=1VIfOxKqVvNmwL5qZfu0Cgpiz5E=; b=gWPW7flu8x85HRWN1ZCnAyV9Myv1 7mRbFLzLRKIxzBdKIWstCrYIJbfLmqVVqaY7u5WfYffNcJU08//iRe4Z1f27XC6x G7XKyx3sdNh6PmLBKDtOj0k9SxfdlyPiimZiiUyfTzot3iRObkgxRZ3TYwtaR8Mr 9dqFk4V/2t+IHx0= Received: (qmail 38197 invoked by alias); 5 Mar 2020 19:22:13 -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 38184 invoked by uid 89); 5 Mar 2020 19:22:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=sk:fno-sta, sk:fnosta, tc, 92130 X-HELO: mail-qt1-f195.google.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id; bh=Xzfgp7/Rzht+8qhrDq3GKuo19NhHqTgkeAENeB2lMKw=; b=xgtwPjDBKhU9QXETPo4wX+7q42pPKIRwZLEPFsfQG9r1GI2+pLC+Edk/Gl7zMPCYuU eXLcK4PPEW2/ckPaXRz/joG8zY4hTDlest6Q7LgzYzBY+ZtKX+DJtkfRYxcSeXMH1mv7 pRKqewnOfWHwjqoqpeDkD9sgEgQb8Caat8Ue3IkNDAokC0LUYAC6FKn9N/vs1A6DISdc USYLHJ8f95mofxy7nO8S733ZWOmgpfyNQtHxsFvXaH0BFyBlrW8ZCakWF56jZiLE1bhc 07xWEF51OY8BQ1vlOFv/eV2/QApkxUPasBXGx6BR09TMrX6FI59DwrHDad/5EmQbOAWA WOLg== Return-Path: From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] sparc: Move sigreturn stub to assembly Date: Thu, 5 Mar 2020 16:22:03 -0300 Message-Id: <20200305192203.30217-1-adhemerval.zanella@linaro.org> It seems that some gcc versions might generates a stack frame for the sigreturn stub requires on sparc signal handling. For instance: $ cat test.c #define _GNU_SOURCE #include __attribute__ ((__optimize__ ("-fno-stack-protector"))) void __sigreturn_stub (void) { __asm__ ("mov %0, %%g1\n\t" "ta 0x10\n\t" : /* no outputs */ : "i" (SYS_rt_sigreturn)); } $ gcc -v [...] gcc version 9.2.1 20200224 (Debian 9.2.1-30) $ gcc -O2 -m64 test.c -S -o - [...] __sigreturn_stub: save %sp, -176, %sp #APP ! 9 "t.c" 1 mov 101, %g1 ta 0x10 ! 0 "" 2 #NO_APP .size __sigreturn_stub, .-__sigreturn_stub As indicated by kernel developers [1], the sigreturn stub can not change the register window or the stack pointer since the kernel has setup the restore frame at a precise location relative to the stack pointer when the stub is invoked. I tried to play with some compiler flags and even with _Noreturn and __builtin_unreachable after the asm does not help (and Sparc does not support naked functions). To avoid similar issues, as the stack-protector support also have stumbled, this patch moves the implementation of the sigreturn stubs to assembly. Checked on sparcv9-linux-gnu and sparc64-linux-gnu with gcc 9.2.1 and gcc 7.5.0. [1] https://lkml.org/lkml/2016/5/27/465 --- sysdeps/unix/sysv/linux/sparc/Makefile | 8 +++-- .../unix/sysv/linux/sparc/sparc32/sigaction.c | 26 ++--------------- .../sysv/linux/sparc/sparc32/sigreturn_stub.S | 29 +++++++++++++++++++ .../unix/sysv/linux/sparc/sparc64/sigaction.c | 14 ++------- .../sysv/linux/sparc/sparc64/sigreturn_stub.S | 24 +++++++++++++++ 5 files changed, 63 insertions(+), 38 deletions(-) create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc32/sigreturn_stub.S create mode 100644 sysdeps/unix/sysv/linux/sparc/sparc64/sigreturn_stub.S -- 2.17.1 diff --git a/sysdeps/unix/sysv/linux/sparc/Makefile b/sysdeps/unix/sysv/linux/sparc/Makefile index b0d182a439..1475039677 100644 --- a/sysdeps/unix/sysv/linux/sparc/Makefile +++ b/sysdeps/unix/sysv/linux/sparc/Makefile @@ -11,8 +11,12 @@ ifeq ($(subdir),sysvipc) sysdep_routines += getshmlba endif +ifeq ($(subdir),signal) +sysdep_routines += sigreturn_stub +endif + ifeq ($(subdir),nptl) # pull in __syscall_error routine -libpthread-routines += sysdep -libpthread-shared-only-routines += sysdep +libpthread-routines += sysdep sigreturn_stub +libpthread-shared-only-routines += sysdep sigreturn_stub endif diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c b/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c index 6b2f664226..938aa7aa8c 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/sigaction.c @@ -24,8 +24,8 @@ #include #include -static void __rt_sigreturn_stub (void); -static void __sigreturn_stub (void); +void __rt_sigreturn_stub (void); +void __sigreturn_stub (void); #define STUB(act, sigsetsize) \ (act) ? ((unsigned long)((act->sa_flags & SA_SIGINFO) \ @@ -35,25 +35,3 @@ static void __sigreturn_stub (void); (sigsetsize) #include - -static -inhibit_stack_protector -void -__rt_sigreturn_stub (void) -{ - __asm__ ("mov %0, %%g1\n\t" - "ta 0x10\n\t" - : /* no outputs */ - : "i" (__NR_rt_sigreturn)); -} - -static -inhibit_stack_protector -void -__sigreturn_stub (void) -{ - __asm__ ("mov %0, %%g1\n\t" - "ta 0x10\n\t" - : /* no outputs */ - : "i" (__NR_sigreturn)); -} diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/sigreturn_stub.S b/sysdeps/unix/sysv/linux/sparc/sparc32/sigreturn_stub.S new file mode 100644 index 0000000000..347cef1349 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/sigreturn_stub.S @@ -0,0 +1,29 @@ +/* Sigreturn stub function used on sa_restore field. + Copyright (C) 2020 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 + +ENTRY (__rt_sigreturn_stub) + mov __NR_rt_sigreturn, %g1 + ta 0x10 +END (__rt_sigreturn_stub) + +ENTRY (__sigreturn_stub) + mov __NR_sigreturn, %g1 + ta 0x10 +END (__sigreturn_stub) diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c b/sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c index 9c0dc2a630..4e26172321 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/sigaction.c @@ -22,21 +22,11 @@ #include #include -static void __rt_sigreturn_stub (void); +/* Defined on sigreturn_stub.S. */ +void __rt_sigreturn_stub (void); #define STUB(act, sigsetsize) \ (((unsigned long) &__rt_sigreturn_stub) - 8), \ (sigsetsize) #include - -static -inhibit_stack_protector -void -__rt_sigreturn_stub (void) -{ - __asm__ ("mov %0, %%g1\n\t" - "ta 0x6d\n\t" - : /* no outputs */ - : "i" (__NR_rt_sigreturn)); -} diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/sigreturn_stub.S b/sysdeps/unix/sysv/linux/sparc/sparc64/sigreturn_stub.S new file mode 100644 index 0000000000..6e0825fbf1 --- /dev/null +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/sigreturn_stub.S @@ -0,0 +1,24 @@ +/* Sigreturn stub function used on sa_restore field. + Copyright (C) 2020 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 + +ENTRY (__rt_sigreturn_stub) + mov __NR_rt_sigreturn, %g1 + ta 0x6d +END (__rt_sigreturn_stub)