1*4882a593SmuzhiyunFrom 12cd30dbe088f20a2953985ca1612cb6a539700d Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Joseph Myers <joseph@codesourcery.com> 3*4882a593SmuzhiyunDate: Fri, 30 Oct 2020 21:38:31 +0000 4*4882a593SmuzhiyunSubject: [PATCH 05/20] Disable spurious -Wstringop-overflow for setjmp/longjmp 5*4882a593Smuzhiyun (bug 26647) 6*4882a593Smuzhiyun 7*4882a593SmuzhiyunBuilding glibc with GCC 11 fails with (among other warnings) spurious 8*4882a593Smuzhiyun-Wstringop-overflow warnings from calls to setjmp and longjmp with a 9*4882a593Smuzhiyunpointer to a pthread_unwind_buf that is smaller than jmp_buf. As 10*4882a593Smuzhiyundiscussed in bug 26647, the warning in libc-start.c is a false 11*4882a593Smuzhiyunpositive, because setjmp and longjmp do not access anything (the 12*4882a593Smuzhiyunsignal mask) beyond the common prefix of the two structures, so this 13*4882a593Smuzhiyunpatch disables the warning for that call to setjmp, as well as for two 14*4882a593Smuzhiyuncalls in NPTL code that produce the same warning and look like false 15*4882a593Smuzhiyunpositives for the same reason. 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunTested with build-many-glibcs.py for arm-linux-gnueabi, where this 18*4882a593Smuzhiyunallows the build to get further. 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunReviewed-by: DJ Delorie <dj@redhat.com> 21*4882a593Smuzhiyun(cherry picked from commit 2098d4034d398cbde6ccd4a2aaac52c518374698) 22*4882a593SmuzhiyunSigned-off-by: Jeffy Chen <jeffy.chen@rock-chips.com> 23*4882a593Smuzhiyun--- 24*4882a593Smuzhiyun csu/libc-start.c | 10 ++++++++++ 25*4882a593Smuzhiyun nptl/pthread_create.c | 10 ++++++++++ 26*4882a593Smuzhiyun nptl/unwind.c | 10 ++++++++++ 27*4882a593Smuzhiyun 3 files changed, 30 insertions(+) 28*4882a593Smuzhiyun 29*4882a593Smuzhiyundiff --git a/csu/libc-start.c b/csu/libc-start.c 30*4882a593Smuzhiyunindex 49413236..dd572d53 100644 31*4882a593Smuzhiyun--- a/csu/libc-start.c 32*4882a593Smuzhiyun+++ b/csu/libc-start.c 33*4882a593Smuzhiyun@@ -21,6 +21,7 @@ 34*4882a593Smuzhiyun #include <unistd.h> 35*4882a593Smuzhiyun #include <ldsodefs.h> 36*4882a593Smuzhiyun #include <exit-thread.h> 37*4882a593Smuzhiyun+#include <libc-diag.h> 38*4882a593Smuzhiyun #include <libc-internal.h> 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun #include <elf/dl-tunables.h> 41*4882a593Smuzhiyun@@ -292,7 +293,16 @@ LIBC_START_MAIN (int (*main) (int, char **, char ** MAIN_AUXVEC_DECL), 42*4882a593Smuzhiyun struct pthread_unwind_buf unwind_buf; 43*4882a593Smuzhiyun 44*4882a593Smuzhiyun int not_first_call; 45*4882a593Smuzhiyun+ DIAG_PUSH_NEEDS_COMMENT; 46*4882a593Smuzhiyun+#if __GNUC_PREREQ (7, 0) 47*4882a593Smuzhiyun+ /* This call results in a -Wstringop-overflow warning because struct 48*4882a593Smuzhiyun+ pthread_unwind_buf is smaller than jmp_buf. setjmp and longjmp 49*4882a593Smuzhiyun+ do not use anything beyond the common prefix (they never access 50*4882a593Smuzhiyun+ the saved signal mask), so that is a false positive. */ 51*4882a593Smuzhiyun+ DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow="); 52*4882a593Smuzhiyun+#endif 53*4882a593Smuzhiyun not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf); 54*4882a593Smuzhiyun+ DIAG_POP_NEEDS_COMMENT; 55*4882a593Smuzhiyun if (__glibc_likely (! not_first_call)) 56*4882a593Smuzhiyun { 57*4882a593Smuzhiyun struct pthread *self = THREAD_SELF; 58*4882a593Smuzhiyundiff --git a/nptl/pthread_create.c b/nptl/pthread_create.c 59*4882a593Smuzhiyunindex fe75d041..05bbbd88 100644 60*4882a593Smuzhiyun--- a/nptl/pthread_create.c 61*4882a593Smuzhiyun+++ b/nptl/pthread_create.c 62*4882a593Smuzhiyun@@ -26,6 +26,7 @@ 63*4882a593Smuzhiyun #include <hp-timing.h> 64*4882a593Smuzhiyun #include <ldsodefs.h> 65*4882a593Smuzhiyun #include <atomic.h> 66*4882a593Smuzhiyun+#include <libc-diag.h> 67*4882a593Smuzhiyun #include <libc-internal.h> 68*4882a593Smuzhiyun #include <resolv.h> 69*4882a593Smuzhiyun #include <kernel-features.h> 70*4882a593Smuzhiyun@@ -429,7 +430,16 @@ START_THREAD_DEFN 71*4882a593Smuzhiyun struct pthread_unwind_buf unwind_buf; 72*4882a593Smuzhiyun 73*4882a593Smuzhiyun int not_first_call; 74*4882a593Smuzhiyun+ DIAG_PUSH_NEEDS_COMMENT; 75*4882a593Smuzhiyun+#if __GNUC_PREREQ (7, 0) 76*4882a593Smuzhiyun+ /* This call results in a -Wstringop-overflow warning because struct 77*4882a593Smuzhiyun+ pthread_unwind_buf is smaller than jmp_buf. setjmp and longjmp 78*4882a593Smuzhiyun+ do not use anything beyond the common prefix (they never access 79*4882a593Smuzhiyun+ the saved signal mask), so that is a false positive. */ 80*4882a593Smuzhiyun+ DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow="); 81*4882a593Smuzhiyun+#endif 82*4882a593Smuzhiyun not_first_call = setjmp ((struct __jmp_buf_tag *) unwind_buf.cancel_jmp_buf); 83*4882a593Smuzhiyun+ DIAG_POP_NEEDS_COMMENT; 84*4882a593Smuzhiyun 85*4882a593Smuzhiyun /* No previous handlers. NB: This must be done after setjmp since the 86*4882a593Smuzhiyun private space in the unwind jump buffer may overlap space used by 87*4882a593Smuzhiyundiff --git a/nptl/unwind.c b/nptl/unwind.c 88*4882a593Smuzhiyunindex b37a063c..3cf0779d 100644 89*4882a593Smuzhiyun--- a/nptl/unwind.c 90*4882a593Smuzhiyun+++ b/nptl/unwind.c 91*4882a593Smuzhiyun@@ -23,6 +23,7 @@ 92*4882a593Smuzhiyun #include <string.h> 93*4882a593Smuzhiyun #include <unistd.h> 94*4882a593Smuzhiyun #include "pthreadP.h" 95*4882a593Smuzhiyun+#include <libc-diag.h> 96*4882a593Smuzhiyun #include <jmpbuf-unwind.h> 97*4882a593Smuzhiyun 98*4882a593Smuzhiyun #ifdef _STACK_GROWS_DOWN 99*4882a593Smuzhiyun@@ -90,8 +91,17 @@ unwind_stop (int version, _Unwind_Action actions, 100*4882a593Smuzhiyun } 101*4882a593Smuzhiyun } 102*4882a593Smuzhiyun 103*4882a593Smuzhiyun+ DIAG_PUSH_NEEDS_COMMENT; 104*4882a593Smuzhiyun+#if __GNUC_PREREQ (7, 0) 105*4882a593Smuzhiyun+ /* This call results in a -Wstringop-overflow warning because struct 106*4882a593Smuzhiyun+ pthread_unwind_buf is smaller than jmp_buf. setjmp and longjmp 107*4882a593Smuzhiyun+ do not use anything beyond the common prefix (they never access 108*4882a593Smuzhiyun+ the saved signal mask), so that is a false positive. */ 109*4882a593Smuzhiyun+ DIAG_IGNORE_NEEDS_COMMENT (11, "-Wstringop-overflow="); 110*4882a593Smuzhiyun+#endif 111*4882a593Smuzhiyun if (do_longjump) 112*4882a593Smuzhiyun __libc_unwind_longjmp ((struct __jmp_buf_tag *) buf->cancel_jmp_buf, 1); 113*4882a593Smuzhiyun+ DIAG_POP_NEEDS_COMMENT; 114*4882a593Smuzhiyun 115*4882a593Smuzhiyun return _URC_NO_REASON; 116*4882a593Smuzhiyun } 117*4882a593Smuzhiyun-- 118*4882a593Smuzhiyun2.20.1 119*4882a593Smuzhiyun 120