Message ID | alpine.DEB.2.22.394.2010281956370.233090@digraph.polyomino.org.uk |
---|---|
State | Committed |
Commit | 2098d4034d398cbde6ccd4a2aaac52c518374698 |
Headers |
Return-Path: <libc-alpha-bounces@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 04BFD3973008; Wed, 28 Oct 2020 19:57:21 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from esa1.mentor.iphmx.com (esa1.mentor.iphmx.com [68.232.129.153]) by sourceware.org (Postfix) with ESMTPS id 71A0939724A0 for <libc-alpha@sourceware.org>; Wed, 28 Oct 2020 19:57:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 71A0939724A0 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=codesourcery.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=joseph_myers@mentor.com IronPort-SDR: x3upv/vUMdwWgJSQL7MAwa1M0aEBFCPwgV0sakTcznHniNYl724lYaI2XawCR6MIp2RJEjl3Dj zmKLp43zE7si8ivmGxpINaeevK8kfgsjJrat1F52bNbc7SrFDLhWqpXcfeQL3jRi8Ot1bM9D2N Nikx+IiX9MQvXMPXob+DJ5945Bu6XiCadBEAQrI/2c0ScPwt836z7lc6Pk8KhkMbbyp8DhGP8A IUdw1JG5TIMkh5Vm1aXQdfHRpyQiydigBPO0iwLungwxUGfFctDEDerChuMVZMaLtjWL3jQul2 zD0= X-IronPort-AV: E=Sophos;i="5.77,427,1596528000"; d="scan'208";a="56734218" Received: from orw-gwy-01-in.mentorg.com ([192.94.38.165]) by esa1.mentor.iphmx.com with ESMTP; 28 Oct 2020 11:57:16 -0800 IronPort-SDR: 3mk3HdHawbwLYNCKHhcToyR8KMXuWOpad1icXHgl4pO4zcvfH9oH3bCeLbeYvSyDrgXGBSmPpw Oga7AGMSD3FCiMOY4R77LuESw4+eKwV3XjJEkAzUNSRlISBKErwzm/szRyLpaTcuMbsoLTUwNi bUXiGoPox7mySKnEEWmYhQYvO+lI/IyYfhYsFtIf4yEaesOTgUM6GAsRoRqU/+KXLPZfiyXnDp XqItq/nMjykL2B4fvULPv+qvHy0HnrRj6N4Vrh08eJBnp9+fs9j1wfI2m4oexnwurfFX+OrBVk lSA= Date: Wed, 28 Oct 2020 19:57:11 +0000 From: Joseph Myers <joseph@codesourcery.com> X-X-Sender: jsm28@digraph.polyomino.org.uk To: <libc-alpha@sourceware.org> Subject: Disable spurious -Wstringop-overflow for setjmp/longjmp (bug 26647) Message-ID: <alpine.DEB.2.22.394.2010281956370.233090@digraph.polyomino.org.uk> User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" X-Originating-IP: [137.202.0.90] X-ClientProxiedBy: svr-ies-mbx-05.mgc.mentorg.com (139.181.222.5) To svr-ies-mbx-01.mgc.mentorg.com (139.181.222.1) X-Spam-Status: No, score=-3131.9 required=5.0 tests=BAYES_00, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, KAM_DMARC_STATUS, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list <libc-alpha.sourceware.org> List-Unsubscribe: <https://sourceware.org/mailman/options/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=unsubscribe> List-Archive: <https://sourceware.org/pipermail/libc-alpha/> List-Post: <mailto:libc-alpha@sourceware.org> List-Help: <mailto:libc-alpha-request@sourceware.org?subject=help> List-Subscribe: <https://sourceware.org/mailman/listinfo/libc-alpha>, <mailto:libc-alpha-request@sourceware.org?subject=subscribe> Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" <libc-alpha-bounces@sourceware.org> |
Series |
Disable spurious -Wstringop-overflow for setjmp/longjmp (bug 26647)
|
|
Commit Message
Joseph Myers
Oct. 28, 2020, 7:57 p.m. UTC
Building glibc with GCC 11 fails with (among other warnings) spurious -Wstringop-overflow warnings from calls to setjmp and longjmp with a pointer to a pthread_unwind_buf that is smaller than jmp_buf. As discussed in bug 26647, the warning in libc-start.c is a false positive, because setjmp and longjmp do not access anything (the signal mask) beyond the common prefix of the two structures, so this patch disables the warning for that call to setjmp, as well as for two calls in NPTL code that produce the same warning and look like false positives for the same reason. Tested with build-many-glibcs.py for arm-linux-gnueabi, where this allows the build to get further.
Comments
Also, similar errors appear in the testsuite from __sigsetjmp calls in the installed pthread.h, and presumably would apply in user programs that use these pthread.h macros. Should we apply a change like this one (with appropriate version conditionals and comments; as an installed header, it can't use libc-diag.h) to address such errors both for the glibc testsuite and for user programs? (With this and the other three patches I've posted today, both glibc and its testsuite build OK for arm-linux-gnueabi.) diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h index d4194da..ec77949 100644 --- a/sysdeps/nptl/pthread.h +++ b/sysdeps/nptl/pthread.h @@ -658,8 +658,11 @@ __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ + _Pragma ("GCC diagnostic push"); \ + _Pragma ("GCC diagnostic ignored \"-Wstringop-overflow=\""); \ int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ __cancel_buf.__cancel_jmp_buf, 0); \ + _Pragma ("GCC diagnostic pop"); \ if (__glibc_unlikely (__not_first_call)) \ { \ __cancel_routine (__cancel_arg); \ @@ -693,8 +696,11 @@ extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ + _Pragma ("GCC diagnostic push"); \ + _Pragma ("GCC diagnostic ignored \"-Wstringop-overflow=\""); \ int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ __cancel_buf.__cancel_jmp_buf, 0); \ + _Pragma ("GCC diagnostic pop"); \ if (__glibc_unlikely (__not_first_call)) \ { \ __cancel_routine (__cancel_arg); \
* Joseph Myers: > Also, similar errors appear in the testsuite from __sigsetjmp calls in the > installed pthread.h, and presumably would apply in user programs that use > these pthread.h macros. Should we apply a change like this one (with > appropriate version conditionals and comments; as an installed header, it > can't use libc-diag.h) to address such errors both for the glibc testsuite > and for user programs? (With this and the other three patches I've posted > today, both glibc and its testsuite build OK for arm-linux-gnueabi.) I do not think we can assume _Pragma support in this context. Do we have to declare the first argument of __sigsetjmp as struct __jmp_buf_tag __env[1]? Thanks, Florian
On Okt 29 2020, Florian Weimer via Libc-alpha wrote: > * Joseph Myers: > >> Also, similar errors appear in the testsuite from __sigsetjmp calls in the >> installed pthread.h, and presumably would apply in user programs that use >> these pthread.h macros. Should we apply a change like this one (with >> appropriate version conditionals and comments; as an installed header, it >> can't use libc-diag.h) to address such errors both for the glibc testsuite >> and for user programs? (With this and the other three patches I've posted >> today, both glibc and its testsuite build OK for arm-linux-gnueabi.) > > I do not think we can assume _Pragma support in this context. > > Do we have to declare the first argument of __sigsetjmp as > struct __jmp_buf_tag __env[1]? How about exporting an alias with the expected signature? Andreas.
On Thu, 29 Oct 2020, Florian Weimer via Libc-alpha wrote: > * Joseph Myers: > > > Also, similar errors appear in the testsuite from __sigsetjmp calls in the > > installed pthread.h, and presumably would apply in user programs that use > > these pthread.h macros. Should we apply a change like this one (with > > appropriate version conditionals and comments; as an installed header, it > > can't use libc-diag.h) to address such errors both for the glibc testsuite > > and for user programs? (With this and the other three patches I've posted > > today, both glibc and its testsuite build OK for arm-linux-gnueabi.) > > I do not think we can assume _Pragma support in this context. This would of course need appropriate version conditionals (on the expectation that compilers not supporting the pragma also don't have the warning in question). > Do we have to declare the first argument of __sigsetjmp as > struct __jmp_buf_tag __env[1]? This is for consistency with the declaration in <setjmp.h> (inconsistent declarations produce other warnings, and the version with the array, and the warnings, are perfectly appropriate for normal user code).
On Thu, 29 Oct 2020, Andreas Schwab wrote: > On Okt 29 2020, Florian Weimer via Libc-alpha wrote: > > > * Joseph Myers: > > > >> Also, similar errors appear in the testsuite from __sigsetjmp calls in the > >> installed pthread.h, and presumably would apply in user programs that use > >> these pthread.h macros. Should we apply a change like this one (with > >> appropriate version conditionals and comments; as an installed header, it > >> can't use libc-diag.h) to address such errors both for the glibc testsuite > >> and for user programs? (With this and the other three patches I've posted > >> today, both glibc and its testsuite build OK for arm-linux-gnueabi.) > > > > I do not think we can assume _Pragma support in this context. > > > > Do we have to declare the first argument of __sigsetjmp as > > struct __jmp_buf_tag __env[1]? > > How about exporting an alias with the expected signature? Like this (which also works to fix the testsuite build problems, given the three other patches posted to fix the build of glibc itself)? diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h index d4194da..6632eae 100644 --- a/sysdeps/nptl/pthread.h +++ b/sysdeps/nptl/pthread.h @@ -658,8 +658,9 @@ __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ - int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ - __cancel_buf.__cancel_jmp_buf, 0); \ + int __not_first_call \ + = __sigsetjmp_cancel ((struct __jmp_buf_tag *) (void *) \ + __cancel_buf.__cancel_jmp_buf, 0); \ if (__glibc_unlikely (__not_first_call)) \ { \ __cancel_routine (__cancel_arg); \ @@ -693,8 +694,9 @@ extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ - int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ - __cancel_buf.__cancel_jmp_buf, 0); \ + int __not_first_call \ + = __sigsetjmp_cancel ((struct __jmp_buf_tag *) (void *) \ + __cancel_buf.__cancel_jmp_buf, 0); \ if (__glibc_unlikely (__not_first_call)) \ { \ __cancel_routine (__cancel_arg); \ @@ -730,9 +732,22 @@ extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) ; #endif -/* Function used in the macros. */ +/* Function used in the macros. Calling __sigsetjmp, with its first + argument declared as an array, results in a -Wstringop-overflow + warning because struct pthread_unwind_buf is smaller than jmp_buf. + The calls from the macros have __SAVEMASK set to 0, so nothing + beyond the common prefix is used and this warning is a false + positive. Use an alias with its first argument declared as a + pointer if possible to avoid this warning. */ +#ifdef __REDIRECT_NTHNL +extern int __REDIRECT_NTHNL (__sigsetjmp_cancel, + (struct __jmp_buf_tag *__env, int __savemask), + __sigsetjmp); +#else +# define __sigsetjmp_cancel __sigsetjmp extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL; +#endif /* Mutex handling. */
On Okt 29 2020, Joseph Myers wrote: > Like this (which also works to fix the testsuite build problems, given the > three other patches posted to fix the build of glibc itself)? > > diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h > index d4194da..6632eae 100644 > --- a/sysdeps/nptl/pthread.h > +++ b/sysdeps/nptl/pthread.h > @@ -658,8 +658,9 @@ __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) > __pthread_unwind_buf_t __cancel_buf; \ > void (*__cancel_routine) (void *) = (routine); \ > void *__cancel_arg = (arg); \ > - int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ > - __cancel_buf.__cancel_jmp_buf, 0); \ > + int __not_first_call \ > + = __sigsetjmp_cancel ((struct __jmp_buf_tag *) (void *) \ > + __cancel_buf.__cancel_jmp_buf, 0); \ Why not just using the type of __cancel_jmp_buf directly? Andreas.
On Thu, 29 Oct 2020, Andreas Schwab wrote: > On Okt 29 2020, Joseph Myers wrote: > > > Like this (which also works to fix the testsuite build problems, given the > > three other patches posted to fix the build of glibc itself)? > > > > diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h > > index d4194da..6632eae 100644 > > --- a/sysdeps/nptl/pthread.h > > +++ b/sysdeps/nptl/pthread.h > > @@ -658,8 +658,9 @@ __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) > > __pthread_unwind_buf_t __cancel_buf; \ > > void (*__cancel_routine) (void *) = (routine); \ > > void *__cancel_arg = (arg); \ > > - int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ > > - __cancel_buf.__cancel_jmp_buf, 0); \ > > + int __not_first_call \ > > + = __sigsetjmp_cancel ((struct __jmp_buf_tag *) (void *) \ > > + __cancel_buf.__cancel_jmp_buf, 0); \ > > Why not just using the type of __cancel_jmp_buf directly? Here is a patch that (gives that type a name and) does that. I haven't seen any comments on the three patches to fix the build of glibc. diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h index d4194da..bcea530 100644 --- a/sysdeps/nptl/pthread.h +++ b/sysdeps/nptl/pthread.h @@ -512,13 +512,15 @@ extern void pthread_testcancel (void); /* Cancellation handling with integration into exception handling. */ +struct __cancel_jmp_buf_tag +{ + __jmp_buf __cancel_jmp_buf; + int __mask_was_saved; +}; + typedef struct { - struct - { - __jmp_buf __cancel_jmp_buf; - int __mask_was_saved; - } __cancel_jmp_buf[1]; + struct __cancel_jmp_buf_tag __cancel_jmp_buf[1]; void *__pad[4]; } __pthread_unwind_buf_t __attribute__ ((__aligned__)); @@ -658,8 +660,8 @@ __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ - int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ - __cancel_buf.__cancel_jmp_buf, 0); \ + int __not_first_call = __sigsetjmp_cancel (__cancel_buf.__cancel_jmp_buf, \ + 0); \ if (__glibc_unlikely (__not_first_call)) \ { \ __cancel_routine (__cancel_arg); \ @@ -693,8 +695,8 @@ extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ - int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ - __cancel_buf.__cancel_jmp_buf, 0); \ + int __not_first_call = __sigsetjmp_cancel (__cancel_buf.__cancel_jmp_buf, \ + 0); \ if (__glibc_unlikely (__not_first_call)) \ { \ __cancel_routine (__cancel_arg); \ @@ -730,9 +732,24 @@ extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) ; #endif -/* Function used in the macros. */ +/* Function used in the macros. Calling __sigsetjmp, with its first + argument declared as an array, results in a -Wstringop-overflow + warning because struct pthread_unwind_buf is smaller than jmp_buf. + The calls from the macros have __SAVEMASK set to 0, so nothing + beyond the common prefix is used and this warning is a false + positive. Use an alias with its first argument declared to use the + type in the macros if possible to avoid this warning. */ +#ifdef __REDIRECT_NTHNL +extern int __REDIRECT_NTHNL (__sigsetjmp_cancel, + (struct __cancel_jmp_buf_tag __env[1], + int __savemask), + __sigsetjmp); +#else +# define __sigsetjmp_cancel(env, savemask) \ + __sigsetjmp ((struct __jmp_buf_tag *) (void *) (env), (savemask)) extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL; +#endif /* Mutex handling. */
On Okt 29 2020, Joseph Myers wrote: > @@ -730,9 +732,24 @@ extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) > ; > #endif > > -/* Function used in the macros. */ > +/* Function used in the macros. Calling __sigsetjmp, with its first > + argument declared as an array, results in a -Wstringop-overflow > + warning because struct pthread_unwind_buf is smaller than jmp_buf. > + The calls from the macros have __SAVEMASK set to 0, so nothing > + beyond the common prefix is used and this warning is a false > + positive. Use an alias with its first argument declared to use the > + type in the macros if possible to avoid this warning. */ > +#ifdef __REDIRECT_NTHNL > +extern int __REDIRECT_NTHNL (__sigsetjmp_cancel, > + (struct __cancel_jmp_buf_tag __env[1], > + int __savemask), > + __sigsetjmp); Does that actually need to be declared returns_twice? Andreas.
On Thu, 29 Oct 2020, Andreas Schwab wrote: > > +extern int __REDIRECT_NTHNL (__sigsetjmp_cancel, > > + (struct __cancel_jmp_buf_tag __env[1], > > + int __savemask), > > + __sigsetjmp); > > Does that actually need to be declared returns_twice? Here's a version doing that. That leaves the question of compilers (e.g. GCC 4.0 and earlier) without the returns_twice attribute but which support asm redirection and understand the returns_twice semantics of __sigsetjmp; to avoid regressing those, this patch uses a condition __GNUC_PREREQ (11, 0) for use of __sigsetjmp_cancel as a function alias rather than a macro, but __GNUC_PREREQ (4, 1) could be used just as well. diff --git a/misc/sys/cdefs.h b/misc/sys/cdefs.h index 6b9763a..86906c2 100644 --- a/misc/sys/cdefs.h +++ b/misc/sys/cdefs.h @@ -563,4 +563,12 @@ _Static_assert (0, "IEEE 128-bits long double requires redirection on this platf # define __attr_access(x) #endif +/* Specify that a function such as setjmp or vfork may return + twice. */ +#if __GNUC_PREREQ (4, 1) +# define __attribute_returns_twice__ __attribute__ ((__returns_twice__)) +#else +# define __attribute_returns_twice__ /* Ignore. */ +#endif + #endif /* sys/cdefs.h */ diff --git a/sysdeps/nptl/pthread.h b/sysdeps/nptl/pthread.h index d4194da..3a34d82 100644 --- a/sysdeps/nptl/pthread.h +++ b/sysdeps/nptl/pthread.h @@ -512,13 +512,15 @@ extern void pthread_testcancel (void); /* Cancellation handling with integration into exception handling. */ +struct __cancel_jmp_buf_tag +{ + __jmp_buf __cancel_jmp_buf; + int __mask_was_saved; +}; + typedef struct { - struct - { - __jmp_buf __cancel_jmp_buf; - int __mask_was_saved; - } __cancel_jmp_buf[1]; + struct __cancel_jmp_buf_tag __cancel_jmp_buf[1]; void *__pad[4]; } __pthread_unwind_buf_t __attribute__ ((__aligned__)); @@ -658,8 +660,8 @@ __pthread_cleanup_routine (struct __pthread_cleanup_frame *__frame) __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ - int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ - __cancel_buf.__cancel_jmp_buf, 0); \ + int __not_first_call = __sigsetjmp_cancel (__cancel_buf.__cancel_jmp_buf, \ + 0); \ if (__glibc_unlikely (__not_first_call)) \ { \ __cancel_routine (__cancel_arg); \ @@ -693,8 +695,8 @@ extern void __pthread_unregister_cancel (__pthread_unwind_buf_t *__buf) __pthread_unwind_buf_t __cancel_buf; \ void (*__cancel_routine) (void *) = (routine); \ void *__cancel_arg = (arg); \ - int __not_first_call = __sigsetjmp ((struct __jmp_buf_tag *) (void *) \ - __cancel_buf.__cancel_jmp_buf, 0); \ + int __not_first_call = __sigsetjmp_cancel (__cancel_buf.__cancel_jmp_buf, \ + 0); \ if (__glibc_unlikely (__not_first_call)) \ { \ __cancel_routine (__cancel_arg); \ @@ -730,9 +732,24 @@ extern void __pthread_unwind_next (__pthread_unwind_buf_t *__buf) ; #endif -/* Function used in the macros. */ +/* Function used in the macros. Calling __sigsetjmp, with its first + argument declared as an array, results in a -Wstringop-overflow + warning from GCC 11 because struct pthread_unwind_buf is smaller + than jmp_buf. The calls from the macros have __SAVEMASK set to 0, + so nothing beyond the common prefix is used and this warning is a + false positive. Use an alias with its first argument declared to + use the type in the macros if possible to avoid this warning. */ +#if __GNUC_PREREQ (11, 0) +extern int __REDIRECT_NTHNL (__sigsetjmp_cancel, + (struct __cancel_jmp_buf_tag __env[1], + int __savemask), + __sigsetjmp) __attribute_returns_twice__; +#else +# define __sigsetjmp_cancel(env, savemask) \ + __sigsetjmp ((struct __jmp_buf_tag *) (void *) (env), (savemask)) extern int __sigsetjmp (struct __jmp_buf_tag __env[1], int __savemask) __THROWNL; +#endif /* Mutex handling. */
Why can't we do this instead, given that's an internal function? - extern int __sigsetjmp (struct __jmp_buf_tag __env[1], + extern int __sigsetjmp (struct __jmp_buf_tag __env *, Or doesn't this remove the warning? Thanks, Florian
On Fri, 30 Oct 2020, Florian Weimer via Libc-alpha wrote: > Why can't we do this instead, given that's an internal function? > > - extern int __sigsetjmp (struct __jmp_buf_tag __env[1], > + extern int __sigsetjmp (struct __jmp_buf_tag __env *, > > Or doesn't this remove the warning? It's not really an internal function, the installed setjmp.h does: # define sigsetjmp(env, savemask) __sigsetjmp (env, savemask) And the declarations in setjmp.h and pthread.h need to be consistent in use of array or pointer to avoid the warnings about inconsistency there. So declaring as a pointer would lose the checks that make sense for user code.
diff --git a/csu/libc-start.c b/csu/libc-start.c index 4005caf..2d4d2ed 100644 --- a/csu/libc-start.c +++ b/csu/libc-start.c @@ -21,6 +21,7 @@ #include <unistd.h> #include <ldsodefs.h> #include <exit-thread.h> +#include <libc-diag.h> #include <libc-internal.h> #include <elf/libc-early-init.h> #include <stdbool.h> @@ -298,7 +299,16 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), struct pthread_unwind_buf unwind_buf; int not_first_call; + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (7, 0) + /* This call results in a -Wstringop-overflow warning because struct + pthread_unwind_buf is smaller than jmp_buf. setjmp and longjmp + do not use anything beyond the common prefix (they never access + the saved signal mask), so that is a false positive. */ + DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow="); +#endif not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf); + DIAG_POP_NEEDS_COMMENT; if (__glibc_likely (! not_first_call)) { struct pthread *self = THREAD_SELF; diff --git a/nptl/pthread_create.c b/nptl/pthread_create.c index 2cba3da..447f005 100644 --- a/nptl/pthread_create.c +++ b/nptl/pthread_create.c @@ -26,6 +26,7 @@ #include <hp-timing.h> #include <ldsodefs.h> #include <atomic.h> +#include <libc-diag.h> #include <libc-internal.h> #include <resolv.h> #include <kernel-features.h> @@ -400,7 +401,16 @@ START_THREAD_DEFN struct pthread_unwind_buf unwind_buf; int not_first_call; + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (7, 0) + /* This call results in a -Wstringop-overflow warning because struct + pthread_unwind_buf is smaller than jmp_buf. setjmp and longjmp + do not use anything beyond the common prefix (they never access + the saved signal mask), so that is a false positive. */ + DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow="); +#endif not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf); + DIAG_POP_NEEDS_COMMENT; /* No previous handlers. NB: This must be done after setjmp since the private space in the unwind jump buffer may overlap space used by diff --git a/nptl/unwind.c b/nptl/unwind.c index 35ed2a7..8f157e4 100644 --- a/nptl/unwind.c +++ b/nptl/unwind.c @@ -23,6 +23,7 @@ #include <string.h> #include <unistd.h> #include "pthreadP.h" +#include <libc-diag.h> #include <jmpbuf-unwind.h> #ifdef _STACK_GROWS_DOWN @@ -90,8 +91,17 @@ unwind_stop (int version, _Unwind_Action actions, } } + DIAG_PUSH_NEEDS_COMMENT; +#if __GNUC_PREREQ (7, 0) + /* This call results in a -Wstringop-overflow warning because struct + pthread_unwind_buf is smaller than jmp_buf. setjmp and longjmp + do not use anything beyond the common prefix (they never access + the saved signal mask), so that is a false positive. */ + DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow="); +#endif if (do_longjump) __libc_unwind_longjmp ((struct __jmp_buf_tag *) buf->cancel_jmp_buf, 1); + DIAG_POP_NEEDS_COMMENT; return _URC_NO_REASON; }