From patchwork Wed Oct 28 19:57:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joseph Myers X-Patchwork-Id: 40908 Return-Path: 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 ; 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 X-X-Sender: jsm28@digraph.polyomino.org.uk To: Subject: Disable spurious -Wstringop-overflow for setjmp/longjmp (bug 26647) Message-ID: User-Agent: Alpine 2.22 (DEB 394 2020-01-19) MIME-Version: 1.0 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces@sourceware.org Sender: "Libc-alpha" 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. 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 #include #include +#include #include #include #include @@ -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 #include #include +#include #include #include #include @@ -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 #include #include "pthreadP.h" +#include #include #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; }