From patchwork Fri Jan 21 21:57:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1582848 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=AWU822TR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4JgYDg0F5pz9t25 for ; Sat, 22 Jan 2022 08:58:57 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 6BB35385800A for ; Fri, 21 Jan 2022 21:58:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6BB35385800A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1642802334; bh=u1m0+9Vc8Lc+NQCstgT08ryl2FQDaEJVbpRLs+YafiY=; h=Date:To:Subject:References:In-Reply-To:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=AWU822TRIaPRrx7aTfCJvDqr2wl5UVNVxBuIk/9Shnk0eZyoF6pMu7gLIrKSMpEuk cN2XmIhagY8UDrOBcnA21xY5IjO9ZXV/4bJILpYSL+yxPNixK7UZsWnajnbT04Xj8s S/BZkcI8T19ZyOFbafmv8g1DZjlrOSuypk3+s4hQ= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) by sourceware.org (Postfix) with ESMTPS id EFB403858419 for ; Fri, 21 Jan 2022 21:57:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EFB403858419 Received: by mail-pl1-x62e.google.com with SMTP id d1so9839685plh.10 for ; Fri, 21 Jan 2022 13:57:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=u1m0+9Vc8Lc+NQCstgT08ryl2FQDaEJVbpRLs+YafiY=; b=vvrgmH9P2BnhnnEDLo8bG8tnyuUbKoJ+EqHQaOA/kfrZPhqLR7j5YbgoGe+IVoz5w8 plGsED4ApFRtjXrhAa4Wj02pS+T3bWb8s6BsppLc0Yc0Z86nWg1lupbnc4RB2VguhI6R lIUzQRBgwKCB+m/M4tesVHk+vyCStwCxOqHtLNI4adkm0PR2F9xnW+L8IO2zrdwwLUqk +UiHIDE4klIkg4gmS4GU3Gn+hpZ3HwCWJB4APIjufah2A9siMdJIgbBfPDJa86yUwlJ8 Gl2X9c9ca7oCMe8sSC2sUemYCkgUuJJgp8LmxGGiflBD9OwXrAWcZNmo3F9iquUTLNaE sBnA== X-Gm-Message-State: AOAM532JLFM6qHkYqk8s88NduREBMz6jalo2AkX7KW0T2CAczptz4DUt +zJPbO30M7e9esTNxqivyk8= X-Google-Smtp-Source: ABdhPJz8wyPyOkxQW7lKzJRc/mQz4bBxSm8zV3VnpgngPf22/JLG8a6CPyshZiZkMIjgFu2jLYBTZw== X-Received: by 2002:a17:90a:588f:: with SMTP id j15mr2604265pji.242.1642802278914; Fri, 21 Jan 2022 13:57:58 -0800 (PST) Received: from gnu-tgl-3.localdomain ([172.58.35.133]) by smtp.gmail.com with ESMTPSA id j15sm8717322pfj.102.2022.01.21.13.57.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jan 2022 13:57:58 -0800 (PST) Received: by gnu-tgl-3.localdomain (Postfix, from userid 1000) id 60F7BC14F1; Fri, 21 Jan 2022 13:57:57 -0800 (PST) Date: Fri, 21 Jan 2022 13:57:57 -0800 To: Jakub Jelinek Subject: [PATCH v2] x86: Properly disable -fsplit-stack support on non-glibc targets Message-ID: References: <20220121191610.8305-1-soeren@soeren-tempel.net> <20220121201841.GK2646553@tucnak> <20220121214203.GL2646553@tucnak> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20220121214203.GL2646553@tucnak> X-Spam-Status: No, score=-3028.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: "H.J. Lu via Gcc-patches" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: richard.sandiford@arm.com, gcc-patches@gcc.gnu.org, soeren@soeren-tempel.net Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" On Fri, Jan 21, 2022 at 10:42:03PM +0100, Jakub Jelinek wrote: > On Fri, Jan 21, 2022 at 01:31:32PM -0800, H.J. Lu wrote: > > On Fri, Jan 21, 2022 at 09:18:41PM +0100, Jakub Jelinek via Gcc-patches wrote: > > > On Fri, Jan 21, 2022 at 08:16:11PM +0100, soeren--- via Gcc-patches wrote: > > > > gcc/ChangeLog: > > > > > > > > * common/config/s390/s390-common.c (s390_supports_split_stack): > > > > Only support split-stack on glibc targets. > > > > * config/i386/gnu-user-common.h (STACK_CHECK_STATIC_BUILTIN): Ditto. > > > > * config/i386/gnu.h (defined): Ditto. > > > > > > Besides breaking bootstrap, this doesn't do what it talks about: > > > > > > > --- a/gcc/config/i386/gnu.h > > > > +++ b/gcc/config/i386/gnu.h > > > > @@ -35,7 +35,10 @@ along with GCC. If not, see . > > > > crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" > > > > #endif > > > > > > > > -#ifdef TARGET_LIBC_PROVIDES_SSP > > > > +/* -fsplit-stack uses a field in the TCB at a fixed offset. This > > > > + field is only available for glibc. Disable -fsplit-stack for > > > > + other libc implementations to avoid silent TCB corruptions. */ > > > > +#if defined (TARGET_LIBC_PROVIDES_SSP) && OPTION_GLIBC > > > > > > > > /* i386 glibc provides __stack_chk_guard in %gs:0x14. */ > > > > #define TARGET_THREAD_SSP_OFFSET 0x14 > > > > > > Because this doesn't disable just -fsplit-stack support, but also > > > -fstack-protector*. > > > Does that one work on musl? > > > I think common/config/i386/i386-common.c (ix86_supports_split_stack) > > > should have been changed instead of the config/i386/gnu*.h headers. > > > > > > > Like this? > > > > > > H.J. > > --- > > Revert x86 changes in > > > > commit c163647ffbc9a20c8feb6e079dbecccfe016c82e > > Author: Soren Tempel > > Date: Fri Jan 21 19:22:46 2022 +0000 > > > > Disable -fsplit-stack support on non-glibc targets > > > > and change ix86_supports_split_stack to return true only on glibc. > > > > PR bootstrap/104170 > > * common/config/i386/i386-common.cc (ix86_supports_split_stack): > > Return true only on glibc. > > * config/i386/gnu-user-common.h (STACK_CHECK_STATIC_BUILTIN): > > Revert commit c163647ffbc. > > * config/i386/gnu.h (TARGET_LIBC_PROVIDES_SSP): Likewise. > > --- > > gcc/common/config/i386/i386-common.cc | 4 ++-- > > gcc/config/i386/gnu-user-common.h | 5 ++--- > > gcc/config/i386/gnu.h | 5 +---- > > 3 files changed, 5 insertions(+), 9 deletions(-) > > > > diff --git a/gcc/common/config/i386/i386-common.cc b/gcc/common/config/i386/i386-common.cc > > index cae0b880d79..78e6ff730aa 100644 > > --- a/gcc/common/config/i386/i386-common.cc > > +++ b/gcc/common/config/i386/i386-common.cc > > @@ -1715,9 +1715,9 @@ ix86_option_init_struct (struct gcc_options *opts) > > > > static bool > > ix86_supports_split_stack (bool report ATTRIBUTE_UNUSED, > > - struct gcc_options *opts ATTRIBUTE_UNUSED) > > + struct gcc_options *opts) > > { > > - bool ret = true; > > + bool ret = opts->x_linux_libc == LIBC_GLIBC; > > > > #ifndef TARGET_THREAD_SPLIT_STACK_OFFSET > > if (report) > > Almost. > I'd think you should honor report and drop ATTRIBUTE_UNUSED from both args. > > So instead: > bool ret = true; > > if (opts->x_linux_libc != LIBC_GLIBC) > { > if (report) > error ("%<-fsplit-stack%> currently only supported on GNU/Linux"); > return false; > } > #ifndef TARGET_THREAD_SPLIT_STACK_OFFSET > ... > Here is the v2 patch. H.J. --- Revert x86 changes in commit c163647ffbc9a20c8feb6e079dbecccfe016c82e Author: Soren Tempel Date: Fri Jan 21 19:22:46 2022 +0000 Disable -fsplit-stack support on non-glibc targets and change ix86_supports_split_stack to return true only on glibc. PR bootstrap/104170 * common/config/i386/i386-common.cc (ix86_supports_split_stack): Return true only on glibc. * config/i386/gnu-user-common.h (STACK_CHECK_STATIC_BUILTIN): Revert commit c163647ffbc. * config/i386/gnu.h (TARGET_LIBC_PROVIDES_SSP): Likewise. --- gcc/common/config/i386/i386-common.cc | 17 +++++++++++------ gcc/config/i386/gnu-user-common.h | 5 ++--- gcc/config/i386/gnu.h | 5 +---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/gcc/common/config/i386/i386-common.cc b/gcc/common/config/i386/i386-common.cc index cae0b880d79..7496d179892 100644 --- a/gcc/common/config/i386/i386-common.cc +++ b/gcc/common/config/i386/i386-common.cc @@ -1714,16 +1714,21 @@ ix86_option_init_struct (struct gcc_options *opts) field in the TCB, so they cannot be used together. */ static bool -ix86_supports_split_stack (bool report ATTRIBUTE_UNUSED, +ix86_supports_split_stack (bool report, struct gcc_options *opts ATTRIBUTE_UNUSED) { +#ifdef TARGET_THREAD_SPLIT_STACK_OFFSET + if (opts->x_linux_libc != LIBC_GLIBC) +#endif + { + if (report) + error ("%<-fsplit-stack%> currently only supported on GNU/Linux"); + return false; + } + bool ret = true; -#ifndef TARGET_THREAD_SPLIT_STACK_OFFSET - if (report) - error ("%<-fsplit-stack%> currently only supported on GNU/Linux"); - ret = false; -#else +#ifdef TARGET_THREAD_SPLIT_STACK_OFFSET if (!HAVE_GAS_CFI_PERSONALITY_DIRECTIVE) { if (report) diff --git a/gcc/config/i386/gnu-user-common.h b/gcc/config/i386/gnu-user-common.h index 7525f788a9c..23b54c5be52 100644 --- a/gcc/config/i386/gnu-user-common.h +++ b/gcc/config/i386/gnu-user-common.h @@ -66,8 +66,7 @@ along with GCC; see the file COPYING3. If not see #define STACK_CHECK_STATIC_BUILTIN 1 /* We only build the -fsplit-stack support in libgcc if the - assembler has full support for the CFI directives and - targets glibc. */ -#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE && OPTION_GLIBC + assembler has full support for the CFI directives. */ +#if HAVE_GAS_CFI_PERSONALITY_DIRECTIVE #define TARGET_CAN_SPLIT_STACK #endif diff --git a/gcc/config/i386/gnu.h b/gcc/config/i386/gnu.h index daa505a5d45..401e60c9a02 100644 --- a/gcc/config/i386/gnu.h +++ b/gcc/config/i386/gnu.h @@ -35,10 +35,7 @@ along with GCC. If not, see . crti.o%s %{static:crtbeginT.o%s;shared|pie:crtbeginS.o%s;:crtbegin.o%s}" #endif -/* -fsplit-stack uses a field in the TCB at a fixed offset. This - field is only available for glibc. Disable -fsplit-stack for - other libc implementations to avoid silent TCB corruptions. */ -#if defined (TARGET_LIBC_PROVIDES_SSP) && OPTION_GLIBC +#ifdef TARGET_LIBC_PROVIDES_SSP /* i386 glibc provides __stack_chk_guard in %gs:0x14. */ #define TARGET_THREAD_SSP_OFFSET 0x14