Message ID | 20231006053106.8484-1-sebastian.huber@embedded-brains.de |
---|---|
State | New |
Headers |
Return-Path: <newlib-bounces+patchwork=sourceware.org@sourceware.org> 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 BAE4E3857716 for <patchwork@sourceware.org>; Fri, 6 Oct 2023 05:31:41 +0000 (GMT) X-Original-To: newlib@sourceware.org Delivered-To: newlib@sourceware.org Received: from dedi548.your-server.de (dedi548.your-server.de [85.10.215.148]) by sourceware.org (Postfix) with ESMTPS id AFCD43858CDA for <newlib@sourceware.org>; Fri, 6 Oct 2023 05:31:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AFCD43858CDA Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=embedded-brains.de Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=embedded-brains.de Received: from sslproxy06.your-server.de ([78.46.172.3]) by dedi548.your-server.de with esmtpsa (TLS1.3) tls TLS_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from <sebastian.huber@embedded-brains.de>) id 1qodQb-000DJc-I6 for newlib@sourceware.org; Fri, 06 Oct 2023 07:31:09 +0200 Received: from [82.100.198.138] (helo=mail.embedded-brains.de) by sslproxy06.your-server.de with esmtpsa (TLSv1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from <sebastian.huber@embedded-brains.de>) id 1qodQb-000UEv-EU for newlib@sourceware.org; Fri, 06 Oct 2023 07:31:09 +0200 Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id 2210F48017D for <newlib@sourceware.org>; Fri, 6 Oct 2023 07:31:09 +0200 (CEST) Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavis, port 10032) with ESMTP id s4WPqzoYVk80 for <newlib@sourceware.org>; Fri, 6 Oct 2023 07:31:08 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by mail.embedded-brains.de (Postfix) with ESMTP id DFBCF480182 for <newlib@sourceware.org>; Fri, 6 Oct 2023 07:31:08 +0200 (CEST) X-Virus-Scanned: amavis at zimbra.eb.localhost Received: from mail.embedded-brains.de ([127.0.0.1]) by localhost (zimbra.eb.localhost [127.0.0.1]) (amavis, port 10026) with ESMTP id PHIJSeMOrFXa for <newlib@sourceware.org>; Fri, 6 Oct 2023 07:31:08 +0200 (CEST) Received: from zimbra.eb.localhost (unknown [192.168.96.179]) by mail.embedded-brains.de (Postfix) with ESMTPSA id C379448017D for <newlib@sourceware.org>; Fri, 6 Oct 2023 07:31:08 +0200 (CEST) From: Sebastian Huber <sebastian.huber@embedded-brains.de> To: newlib@sourceware.org Subject: [PATCH] sparc: Improve setjmp() Date: Fri, 6 Oct 2023 07:31:06 +0200 Message-Id: <20231006053106.8484-1-sebastian.huber@embedded-brains.de> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authenticated-Sender: smtp-embedded@poldi-networks.de X-Virus-Scanned: Clear (ClamAV 0.103.10/27052/Thu Oct 5 09:38:26 2023) X-Spam-Status: No, score=-11.3 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Newlib mailing list <newlib.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/newlib>, <mailto:newlib-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/newlib/> List-Post: <mailto:newlib@sourceware.org> List-Help: <mailto:newlib-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/newlib>, <mailto:newlib-request@sourceware.org?subject=subscribe> Errors-To: newlib-bounces+patchwork=sourceware.org@sourceware.org Sender: "Newlib" <newlib-bounces+patchwork=sourceware.org@sourceware.org> |
Series |
sparc: Improve setjmp()
|
|
Commit Message
Sebastian Huber
Oct. 6, 2023, 5:31 a.m. UTC
Flush the windows in setjmp(). This helps if the stack is changed after the setjmp() and we want to jump back to the original stack using longjmp(). --- newlib/libc/machine/sparc/setjmp.S | 2 ++ 1 file changed, 2 insertions(+)
Comments
On 06.10.23 07:31, Sebastian Huber wrote: > Flush the windows in setjmp(). This helps if the stack is changed after > the setjmp() and we want to jump back to the original stack using > longjmp(). > --- > newlib/libc/machine/sparc/setjmp.S | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/newlib/libc/machine/sparc/setjmp.S b/newlib/libc/machine/sparc/setjmp.S > index 613df2ba2..d7185be4c 100644 > --- a/newlib/libc/machine/sparc/setjmp.S > +++ b/newlib/libc/machine/sparc/setjmp.S > @@ -110,6 +110,8 @@ > > ENTRY(setjmp) > ENTRY(_setjmp) > + ta 0x03 /* Flush registers, just in case another stack > + is used after the setjmp(). */ > st %sp, [%o0] /* caller's stack pointer */ > st %i7, [%o0+4] /* caller's return pc */ > st %fp, [%o0+8] /* store caller's frame pointer */ I am not sure if there is anyone left being able to review this change.
Hi Sebastian, I am not familiar with sparc to comment, but Corinna has performed maintenance on the setjmp.S file if you want to wait for her to look at the change. Otherwise, if you have a test case that verifies the change, feel free to merge and you can confirm with Corinna when she is back. -- Jeff J. On Thu, Oct 12, 2023 at 5:39 AM Sebastian Huber < sebastian.huber@embedded-brains.de> wrote: > On 06.10.23 07:31, Sebastian Huber wrote: > > Flush the windows in setjmp(). This helps if the stack is changed after > > the setjmp() and we want to jump back to the original stack using > > longjmp(). > > --- > > newlib/libc/machine/sparc/setjmp.S | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/newlib/libc/machine/sparc/setjmp.S > b/newlib/libc/machine/sparc/setjmp.S > > index 613df2ba2..d7185be4c 100644 > > --- a/newlib/libc/machine/sparc/setjmp.S > > +++ b/newlib/libc/machine/sparc/setjmp.S > > @@ -110,6 +110,8 @@ > > > > ENTRY(setjmp) > > ENTRY(_setjmp) > > + ta 0x03 /* Flush registers, just in case > another stack > > + is used after the setjmp(). */ > > st %sp, [%o0] /* caller's stack pointer */ > > st %i7, [%o0+4] /* caller's return pc */ > > st %fp, [%o0+8] /* store caller's frame pointer */ > > I am not sure if there is anyone left being able to review this change. > > -- > embedded brains GmbH > Herr Sebastian HUBER > Dornierstr. 4 > 82178 Puchheim > Germany > email: sebastian.huber@embedded-brains.de > phone: +49-89-18 94 741 - 16 > fax: +49-89-18 94 741 - 08 > > Registergericht: Amtsgericht München > Registernummer: HRB 157899 > Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler > Unsere Datenschutzerklärung finden Sie hier: > https://embedded-brains.de/datenschutzerklaerung/ > >
Hello Jeff, On 12.10.23 16:50, Jeff Johnston wrote: > Hi Sebastian, > > I am not familiar with sparc to comment, but Corinna has performed > maintenance on the setjmp.S file if > you want to wait for her to look at the change. Otherwise, if you have > a test case that > verifies the change, feel free to merge and you can confirm with Corinna > when she is back. the glibc version does also the window flush. I noticed the issue by testing compiler builtins which on some systems result in a trap, for example: volatile int64_t n; volatile int64_t d; n = INT64_C( 0 ); d = INT64_C( 0 ); do_longjmp = true; if ( setjmp( exception_return_context ) == 0 ) { n = n % d; } In RTEMS, we use a processor-specific stack to handle synchronous exceptions. If you want to jump back to the thread from the exception handler, then you have to change back to the original thread stack. This works only if you flush the windows in the setjmp(). > > -- Jeff J. > > > On Thu, Oct 12, 2023 at 5:39 AM Sebastian Huber > <sebastian.huber@embedded-brains.de > <mailto:sebastian.huber@embedded-brains.de>> wrote: > > On 06.10.23 07:31, Sebastian Huber wrote: > > Flush the windows in setjmp(). This helps if the stack is > changed after > > the setjmp() and we want to jump back to the original stack using > > longjmp(). > > --- > > newlib/libc/machine/sparc/setjmp.S | 2 ++ > > 1 file changed, 2 insertions(+) > > > > diff --git a/newlib/libc/machine/sparc/setjmp.S > b/newlib/libc/machine/sparc/setjmp.S > > index 613df2ba2..d7185be4c 100644 > > --- a/newlib/libc/machine/sparc/setjmp.S > > +++ b/newlib/libc/machine/sparc/setjmp.S > > @@ -110,6 +110,8 @@ > > > > ENTRY(setjmp) > > ENTRY(_setjmp) > > + ta 0x03 /* Flush registers, just in case > another stack > > + is used after the setjmp(). */ > > st %sp, [%o0] /* caller's stack pointer */ > > st %i7, [%o0+4] /* caller's return pc */ > > st %fp, [%o0+8] /* store caller's frame pointer */ > > I am not sure if there is anyone left being able to review this change. > > -- > embedded brains GmbH > Herr Sebastian HUBER > Dornierstr. 4 > 82178 Puchheim > Germany > email: sebastian.huber@embedded-brains.de > <mailto:sebastian.huber@embedded-brains.de> > phone: +49-89-18 94 741 - 16 > fax: +49-89-18 94 741 - 08 > > Registergericht: Amtsgericht München > Registernummer: HRB 157899 > Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler > Unsere Datenschutzerklärung finden Sie hier: > https://embedded-brains.de/datenschutzerklaerung/ > <https://embedded-brains.de/datenschutzerklaerung/> >
On 2023-10-12 03:39, Sebastian Huber wrote: > On 06.10.23 07:31, Sebastian Huber wrote: >> Flush the windows in setjmp(). This helps if the stack is changed after >> the setjmp() and we want to jump back to the original stack using >> longjmp(). >> --- >> newlib/libc/machine/sparc/setjmp.S | 2 ++ >> 1 file changed, 2 insertions(+) >> >> diff --git a/newlib/libc/machine/sparc/setjmp.S >> b/newlib/libc/machine/sparc/setjmp.S >> index 613df2ba2..d7185be4c 100644 >> --- a/newlib/libc/machine/sparc/setjmp.S >> +++ b/newlib/libc/machine/sparc/setjmp.S >> @@ -110,6 +110,8 @@ >> ENTRY(setjmp) >> ENTRY(_setjmp) >> + ta 0x03 /* Flush registers, just in case another stack >> + is used after the setjmp(). */ >> st %sp, [%o0] /* caller's stack pointer */ >> st %i7, [%o0+4] /* caller's return pc */ >> st %fp, [%o0+8] /* store caller's frame pointer */ > > I am not sure if there is anyone left being able to review this change. Hopefully someone is, but as a former SunOS/Sparc guy (sysadmin/board swapper but not assembler there) I got interested, and found one related discussion on the sparclinux list: https://lore.kernel.org/sparclinux/20111007232209.GA11892@wooyd.org/t/#u which seems to indicate that you are DTRT; also for comparison: https://gcc.gnu.org/onlinedocs/gcc/Nonlocal-Gotos.html and $ info gcc 'nonlocal gotos' although: https://stackoverflow.com/questions/72711501/special-treatment-of-setjmp-longjmp-by-compilers https://gcc.gnu.org/legacy-ml/gcc/2018-03/msg00032.html https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83368 and some threads about LLVM enhancing and dropping Sparc __builtin_set/longjmp. But as Knuth said about some code: "I have proved it correct, but not tested it.", which is the proof of the pudding: issue before patch; no issues after patch?
On Thu, Oct 12, 2023 at 10:55 AM Sebastian Huber < sebastian.huber@embedded-brains.de> wrote: > Hello Jeff, > > On 12.10.23 16:50, Jeff Johnston wrote: > > Hi Sebastian, > > > > I am not familiar with sparc to comment, but Corinna has performed > > maintenance on the setjmp.S file if > > you want to wait for her to look at the change. Otherwise, if you have > > a test case that > > verifies the change, feel free to merge and you can confirm with Corinna > > when she is back. > > the glibc version does also the window flush. I noticed the issue by > testing compiler builtins which on some systems result in a trap, for > example: > Then by all means go ahead and check it in. -- Jeff J. > > volatile int64_t n; > volatile int64_t d; > > n = INT64_C( 0 ); > d = INT64_C( 0 ); > do_longjmp = true; > > if ( setjmp( exception_return_context ) == 0 ) { > n = n % d; > } > > In RTEMS, we use a processor-specific stack to handle synchronous > exceptions. If you want to jump back to the thread from the exception > handler, then you have to change back to the original thread stack. This > works only if you flush the windows in the setjmp(). > > > > > -- Jeff J. > > > > > > On Thu, Oct 12, 2023 at 5:39 AM Sebastian Huber > > <sebastian.huber@embedded-brains.de > > <mailto:sebastian.huber@embedded-brains.de>> wrote: > > > > On 06.10.23 07:31, Sebastian Huber wrote: > > > Flush the windows in setjmp(). This helps if the stack is > > changed after > > > the setjmp() and we want to jump back to the original stack using > > > longjmp(). > > > --- > > > newlib/libc/machine/sparc/setjmp.S | 2 ++ > > > 1 file changed, 2 insertions(+) > > > > > > diff --git a/newlib/libc/machine/sparc/setjmp.S > > b/newlib/libc/machine/sparc/setjmp.S > > > index 613df2ba2..d7185be4c 100644 > > > --- a/newlib/libc/machine/sparc/setjmp.S > > > +++ b/newlib/libc/machine/sparc/setjmp.S > > > @@ -110,6 +110,8 @@ > > > > > > ENTRY(setjmp) > > > ENTRY(_setjmp) > > > + ta 0x03 /* Flush registers, just in case > > another stack > > > + is used after the setjmp(). > */ > > > st %sp, [%o0] /* caller's stack pointer */ > > > st %i7, [%o0+4] /* caller's return pc */ > > > st %fp, [%o0+8] /* store caller's frame pointer > */ > > > > I am not sure if there is anyone left being able to review this > change. > > > > -- > > embedded brains GmbH > > Herr Sebastian HUBER > > Dornierstr. 4 > > 82178 Puchheim > > Germany > > email: sebastian.huber@embedded-brains.de > > <mailto:sebastian.huber@embedded-brains.de> > > phone: +49-89-18 94 741 - 16 > > fax: +49-89-18 94 741 - 08 > > > > Registergericht: Amtsgericht München > > Registernummer: HRB 157899 > > Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas > Dörfler > > Unsere Datenschutzerklärung finden Sie hier: > > https://embedded-brains.de/datenschutzerklaerung/ > > <https://embedded-brains.de/datenschutzerklaerung/> > > > > -- > embedded brains GmbH > Herr Sebastian HUBER > Dornierstr. 4 > 82178 Puchheim > Germany > email: sebastian.huber@embedded-brains.de > phone: +49-89-18 94 741 - 16 > fax: +49-89-18 94 741 - 08 > > Registergericht: Amtsgericht München > Registernummer: HRB 157899 > Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler > Unsere Datenschutzerklärung finden Sie hier: > https://embedded-brains.de/datenschutzerklaerung/ > >
diff --git a/newlib/libc/machine/sparc/setjmp.S b/newlib/libc/machine/sparc/setjmp.S index 613df2ba2..d7185be4c 100644 --- a/newlib/libc/machine/sparc/setjmp.S +++ b/newlib/libc/machine/sparc/setjmp.S @@ -110,6 +110,8 @@ ENTRY(setjmp) ENTRY(_setjmp) + ta 0x03 /* Flush registers, just in case another stack + is used after the setjmp(). */ st %sp, [%o0] /* caller's stack pointer */ st %i7, [%o0+4] /* caller's return pc */ st %fp, [%o0+8] /* store caller's frame pointer */