public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: soeren@soeren-tempel.net, richard.sandiford@arm.com,
	gcc-patches@gcc.gnu.org
Subject: [PATCH v2] x86: Properly disable -fsplit-stack support on non-glibc targets
Date: Fri, 21 Jan 2022 13:57:57 -0800	[thread overview]
Message-ID: <YessZWWDQr48TLP1@gmail.com> (raw)
In-Reply-To: <20220121214203.GL2646553@tucnak>

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 <http://www.gnu.org/licenses/>.
> > > >     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 <soeren@soeren-tempel.net>
> > 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 <soeren@soeren-tempel.net>
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 <http://www.gnu.org/licenses/>.
    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
-- 
2.34.1


  reply	other threads:[~2022-01-21 21:57 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-18 10:43 [PATCH] Disable " soeren
2021-12-18 10:54 ` Andrew Pinski
2021-12-18 11:13   ` Sören Tempel
2021-12-18 11:22     ` Andrew Pinski
2021-12-18 12:19       ` [PATCH v2] " soeren
2022-01-20 20:45         ` Sören Tempel
2022-01-20 22:52         ` Richard Sandiford
2022-01-21  7:32           ` Andreas Krebbel
2022-01-21  8:17           ` Uros Bizjak
2022-01-21 19:16           ` [PATCH v3] " soeren
2022-01-21 19:23             ` Richard Sandiford
2022-01-21 19:47               ` H.J. Lu
2022-01-21 20:09                 ` H.J. Lu
2022-01-21 20:18             ` Jakub Jelinek
2022-01-21 21:31               ` [PATCH] x86: Properly disable " H.J. Lu
2022-01-21 21:42                 ` Jakub Jelinek
2022-01-21 21:57                   ` H.J. Lu [this message]
2022-01-21 22:14                     ` [PATCH v2] " Jakub Jelinek
2022-01-21 19:53         ` [PATCH v2] Disable " H.J. Lu
2022-01-21 20:43           ` Sören Tempel
2022-01-22  9:32 ` [PATCH] " Martin Liška
2022-01-22  9:35   ` Jakub Jelinek
2022-01-22 12:16   ` Jakub Jelinek
2022-01-22 18:03     ` Jakub Jelinek
2022-01-23  9:06       ` Uros Bizjak
2022-01-23 10:06         ` Jakub Jelinek
2022-01-24  9:33       ` Jakub Jelinek
2022-01-24 10:09         ` Richard Biener

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=YessZWWDQr48TLP1@gmail.com \
    --to=hjl.tools@gmail.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=richard.sandiford@arm.com \
    --cc=soeren@soeren-tempel.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).