Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp2321216imm; Thu, 20 Sep 2018 11:09:59 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZBVsVF13TCjv1U0MigSq1tLIggZiqfnhaYcbNmESbKOxD+V8UcS1xubzOGt81/Ug7QnUD/ X-Received: by 2002:a63:9712:: with SMTP id n18-v6mr37773399pge.69.1537466999270; Thu, 20 Sep 2018 11:09:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537466999; cv=none; d=google.com; s=arc-20160816; b=0xYwcKIsoXsaNSv3w/fuNswKobr2vG1RnVNQMO9t2iL404idle3L2qtlbbJCvJd1Cz f9y0v6yzKtlPiWSI3w/6jWk56XuUUlGFTumEbxcs7xo15FQvKaABH5IqYGYDxRMqOPqd KG0yn5RJQ9LFPE21GI8vX5tu0o6cW+C62R+iMGJpRGFejnm0diD2ENHF4C1ZLIpBJf9i 6v5tE4msJdmxDhDGXjmiT2Vpb9u0DdZkHNbI2QUgN9DOPayBTFSzwBb+JxtwguyMOHK5 M/kqgCEdSP9e+Esxzu/kBfsdG5btNAO4kCKziwj58JyLzUDN9tO3JzAfrMsE6Gd4tx+G kWbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=hhBbcYIjWMAfcE0bX5sqVlG5FUKTWnKEZWytPAJUITw=; b=BwINkKrSD+zlTvX3v6i+oGk4UaH6CECHOx3Hb/DdKwtZSoW47GuAcuNbMJgAtZp3Eg bMqYH+lZ2I154athO4vNHmw8fHYm3d6vFQnrUdCzc2y692FkzA0DRahCAWkmJ1iqje3C oiJOKxzcfjhosID52cOgFe444Gb0P1bPJHCFYZ04liQ54yz8NUfnWbJOaO6tpa8Bq00g NxlLIr+oYXOFYze+pGLPhxVDPUgkHToZXaKNFqA1BTUmXs3N1acwvQ7osrBRdQsQgKfU g5ecoYD2eCn59X4J5sv1a5nS1FYNVeVY4fCxfIW81yz+Z0YVvPzJHEgnqnA1Y9XCRutN lwtA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=A06jq5rA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e1-v6si23041790pgo.325.2018.09.20.11.09.41; Thu, 20 Sep 2018 11:09:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=A06jq5rA; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387762AbeITXws (ORCPT + 99 others); Thu, 20 Sep 2018 19:52:48 -0400 Received: from mail-pl1-f194.google.com ([209.85.214.194]:43376 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727232AbeITXwr (ORCPT ); Thu, 20 Sep 2018 19:52:47 -0400 Received: by mail-pl1-f194.google.com with SMTP id 38-v6so4715796plc.10 for ; Thu, 20 Sep 2018 11:08:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=hhBbcYIjWMAfcE0bX5sqVlG5FUKTWnKEZWytPAJUITw=; b=A06jq5rAZLo59KK26eml9lAgrX1M/6L9+SFxKcecxH+0xsqikiEzHPDfedA4XjXKYn 4Cjo6W7pfCeEoZT5iTLaqzH2ZFC3X/RCJ6fT+oy9DLMugWJXOjbknG7YsHUe1pSlKkLO OJZjJ3a4RGJ6hCJfQnmnk8wCeAXxCO0Q6mrxrTvUS7uaNkATCkRRkLuJo0rU4B5kMdtt spQV/177YWr9vjSV3T1CGbh969r0hjUhPoXPlPDkY+x2NX6eA1aQ/ARR1eg1EonE/tXt WbNaEBz1GKtBJ/UVM8sJPmCW8nieuXT5iSoNzq/DrYHs+3M0KeuRbfkDMVhVFfVHr7if YTRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=hhBbcYIjWMAfcE0bX5sqVlG5FUKTWnKEZWytPAJUITw=; b=tuYgUhF3jWFpEdWOI57/jtQ/yTEgBnjeg2JXxKrTmUAO6Wgvp42MLigiz+A6dlS3Rd Gj3oHXfB73iahQ12+LWqBRbZn+l2bMntaGK+5mxNQDP0n94UsZPYUnrXbQEE36tlAWlK zCB22ifog3wsrUoCTyErwdroGlOdnVIlZBXxQC2zd9MXyX36opWlP7ApovKLNkqwylBD NxNBty10JgOlJeQYyX5ysYCBLPV15E1YbG/obRCCOD2Eponfxr2D5KCag74lam3/FXRj N35lta7VDz9VAnLS+R0HyABQpIbPlVG31YsKmCXG3uXJD1JxlkDRtXEbzp01YA+dfzjs B5xA== X-Gm-Message-State: APzg51AWgxuaNcp8Jpcxh4b8kgXDQbFMj8B09SA1yRMeNNE1aAKnZZKc mFn2/Cn+aVZ81BCDsYP00csX6JA+1gZMBNkrOqPtnw== X-Received: by 2002:a17:902:708a:: with SMTP id z10-v6mr41107122plk.229.1537466884304; Thu, 20 Sep 2018 11:08:04 -0700 (PDT) MIME-Version: 1.0 References: <20180920172301.21868-1-miguel.ojeda.sandonis@gmail.com> <20180920172301.21868-13-miguel.ojeda.sandonis@gmail.com> In-Reply-To: <20180920172301.21868-13-miguel.ojeda.sandonis@gmail.com> From: Nick Desaulniers Date: Thu, 20 Sep 2018 11:07:53 -0700 Message-ID: Subject: Re: [PATCH v5 12/15] Compiler Attributes: add support for __nonstring (gcc >= 8) To: Miguel Ojeda Cc: Greg KH , LKML , adilger.kernel@dilger.ca, Masahiro Yamada , Michal Marek , rostedt@goodmis.org, mchehab+samsung@kernel.org, olof@lxom.net, konstantin@linuxfoundation.org, "David S. Miller" , Andrey Ryabinin , Kees Cook , Thomas Gleixner , Ingo Molnar , Paul Lawrence , sandipan@linux.vnet.ibm.com, Andrey Konovalov , David Woodhouse , Will Deacon , Philippe Ombredanne , paul.burton@mips.com, David Rientjes , w@1wt.eu, msebor@gmail.com, sparse@chrisli.org, Jonathan Corbet , tytso@mit.edu, Geert Uytterhoeven , Rasmus Villemoes , joe@perches.com, Arnd Bergmann , asmadeus@codewreck.org, Stefan Agner , Luc Van Oostenryck , Andrew Morton , Linus Torvalds , linux-doc@vger.kernel.org, linux-ext4@vger.kernel.org, linux-sparse@vger.kernel.org, Linux Kbuild mailing list Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Sep 20, 2018 at 10:23 AM Miguel Ojeda wrote: > > From the GCC manual: > > nonstring > > The nonstring variable attribute specifies that an object or member > declaration with type array of char, signed char, or unsigned char, > or pointer to such a type is intended to store character arrays that > do not necessarily contain a terminating NUL. This is useful in detecting > uses of such arrays or pointers with functions that expect NUL-terminated > strings, and to avoid warnings when such an array or pointer is used as > an argument to a bounded string manipulation function such as strncpy. > > https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html > > This attribute can be used for documentation purposes (i.e. replacing > comments), but it is most helpful when the following warnings are enabled: > > -Wstringop-overflow > > Warn for calls to string manipulation functions such as memcpy and > strcpy that are determined to overflow the destination buffer. > > [...] > > -Wstringop-truncation > > Warn for calls to bounded string manipulation functions such as > strncat, strncpy, and stpncpy that may either truncate the copied > string or leave the destination unchanged. > > [...] > > In situations where a character array is intended to store a sequence > of bytes with no terminating NUL such an array may be annotated with > attribute nonstring to avoid this warning. Such arrays, however, > are not suitable arguments to functions that expect NUL-terminated > strings. To help detect accidental misuses of such arrays GCC issues > warnings unless it can prove that the use is safe. > > https://gcc.gnu.org/onlinedocs/gcc/Warning-Options.html > > Signed-off-by: Miguel Ojeda > --- > include/linux/compiler_attributes.h | 14 ++++++++++++++ > 1 file changed, 14 insertions(+) > > diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h > index f0f9fc398440..6b28c1b7310c 100644 > --- a/include/linux/compiler_attributes.h > +++ b/include/linux/compiler_attributes.h > @@ -34,6 +34,7 @@ > # define __GCC4_has_attribute___externally_visible__ 1 > # define __GCC4_has_attribute___noclone__ 1 > # define __GCC4_has_attribute___optimize__ 1 > +# define __GCC4_has_attribute___nonstring__ 0 > # define __GCC4_has_attribute___no_sanitize_address__ (__GNUC_MINOR__ >= 8) > #endif > > @@ -181,6 +182,19 @@ > */ > #define noinline __attribute__((__noinline__)) > > +/* > + * Optional: only supported since gcc >= 8 > + * Optional: not supported by clang > + * Optional: not supported by icc > + * > + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html#index-nonstring-variable-attribute > + */ > +#if __has_attribute(__nonstring__) > +# define __nonstring __attribute__((__nonstring__)) > +#else > +# define __nonstring > +#endif > + > /* > * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-noreturn-function-attribute > * clang: https://clang.llvm.org/docs/AttributeReference.html#noreturn > -- > 2.17.1 > Reviewed-by: Nick Desaulniers -- Thanks, ~Nick Desaulniers