Disable spurious -Wstringop-overflow for setjmp/longjmp (bug 26647)

Message ID alpine.DEB.2.22.394.2010281956370.233090@digraph.polyomino.org.uk
State Committed
Commit 2098d4034d398cbde6ccd4a2aaac52c518374698
Headers
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

Joseph Myers Oct. 28, 2020, 11:25 p.m. UTC | #1
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);				      \
  
Florian Weimer Oct. 29, 2020, 10:02 a.m. UTC | #2
* 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
  
Andreas Schwab Oct. 29, 2020, 10:06 a.m. UTC | #3
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.
  
Joseph Myers Oct. 29, 2020, 3:47 p.m. UTC | #4
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).
  
Joseph Myers Oct. 29, 2020, 3:48 p.m. UTC | #5
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.  */
  
Andreas Schwab Oct. 29, 2020, 4:35 p.m. UTC | #6
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.
  
Joseph Myers Oct. 29, 2020, 5:26 p.m. UTC | #7
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.  */
  
Andreas Schwab Oct. 29, 2020, 6:21 p.m. UTC | #8
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.
  
Joseph Myers Oct. 29, 2020, 7:03 p.m. UTC | #9
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.  */
  
Florian Weimer Oct. 30, 2020, 9:15 p.m. UTC | #10
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
  
Joseph Myers Oct. 30, 2020, 9:42 p.m. UTC | #11
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.
  

Patch

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;
 }