Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp136896imj; Fri, 8 Feb 2019 16:42:08 -0800 (PST) X-Google-Smtp-Source: AHgI3IbvNd3SrDWivxoI9hqQmtmekiWl3hvwiu5JoNr5DSNu/FGfHV2xPFZJYUzA1HNwgFY5UfK2 X-Received: by 2002:a62:931a:: with SMTP id b26mr26045988pfe.65.1549672928712; Fri, 08 Feb 2019 16:42:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549672928; cv=none; d=google.com; s=arc-20160816; b=Uwiw7cOYxgIGWigxMz85T5Z6faD0ZrCy4rxXl1PxqheTpnPNlTsZ9BIiFsPW7UM1KB tk3ciUTqnETvjWYnlgrgbrHdNcDtJeHCHfYm4yL84WGWJ/vcwdPy00c/WbPIE+LPgJ5g ShLUr4xujx78h6MrPqa0I0eVz+orhSmxVuXKJ8ezJH/aweZ+GSuA8fWIoFZhLoq7skN8 08GGXhy4gjfSn1ilcLOYOVUN6LrjUSw3bG0o7ZjPgbef/GHY2XPTYRElPjioS5YWp/Ea 6AHjaQqd2WQLHchtl4gfCucGfu2uBJ11x1tR1ukxScZlawM9V9Wg/ij8y8wEqdOtVw7e TTiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=6xWTl4mp4zbl4vVPfLCeQM8pvz2X7ElhN61xgasB7Lw=; b=PSA7obIKz82Y9AG92f1ErbXzt7DP8bH1sNSBKJrP3ilAaR5gSkblniW9qvgwl6eCKX 6Ug3NLRshjITYZ0KrYPGvqfUhpq3nSDbnLymWwVIxZGl+V80lgk5+xDXiLm+fPK9HhPZ H/c1oq8oEmibKsLH6HctDhfNyYgu1Pk52wF8y+JWj1FmOHaCYT2LPQz3q69ViAC2OLSC tXmHSOXDuQ6+Cf2lG1lGvo2c3VMsVHW+GSoT4jjfsV/Vm5ewkPVGbnY+5YKlkQasAnTs /QKfoAslS6AL1xMiH+4q5C/Rjfyxkwhq0pvuTbvpYguvoHN2w0YunISQB6+sAt1XCAhw qTSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=RqGTxI6P; 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 a18si3425586pgw.530.2019.02.08.16.41.53; Fri, 08 Feb 2019 16:42:08 -0800 (PST) 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=RqGTxI6P; 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 S1727081AbfBIAle (ORCPT + 99 others); Fri, 8 Feb 2019 19:41:34 -0500 Received: from mail-pl1-f194.google.com ([209.85.214.194]:37377 "EHLO mail-pl1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726565AbfBIAle (ORCPT ); Fri, 8 Feb 2019 19:41:34 -0500 Received: by mail-pl1-f194.google.com with SMTP id b5so2475814plr.4 for ; Fri, 08 Feb 2019 16:41:34 -0800 (PST) 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:content-transfer-encoding; bh=6xWTl4mp4zbl4vVPfLCeQM8pvz2X7ElhN61xgasB7Lw=; b=RqGTxI6PMWQJJsNIKsWpniiTI4aLk2ERHjlUWLweE+vd3du/k6Rzz/9UZCG9ijGe6T qdhcJj4Vo6YIWy6zPHE9ooYPiA2AEw0E94/BMxSLHD6XkTom8mgutems8aR+iSocCXPh 3KW5/SOT7T6zxWtdecilUZevW0JsBcy2PrC/pN4b7qN6LllIGX8+qmDHIaXDx7EBLwKN q5R8T3ZTCvXrDLXotuzH4f/n17fs9OyTN8lrMAKs+jq6tuEKhys2/X+W+UjB4NIeHETV YVDN5T61NYFX9nHEZu3H9kndo0YTeD2cXFVtcKdVudVx4veA6jB8RibzLCcX3/dBlV8c aGzA== 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:content-transfer-encoding; bh=6xWTl4mp4zbl4vVPfLCeQM8pvz2X7ElhN61xgasB7Lw=; b=tfH+L2wdZD672WEB5tcLlpFIItXL2YRIxDzt7gsu/4ljOCeV4Djvu2klL+guUOmFE5 h7v1WNbl4DrzS9vCqDxJUJyQ+1ckClD39mb0jWy2lyhT0IKscKAoTkdV4zhYms++kHc0 LU8gzZgv0HIdnO2ia4IyTUrbaAOd4/0EBfNmWW6c7w1EV05Wy/cPD0603r2w3foscuQ7 JrsDqysMTQFXtMOc7VwU9MyWkp0Ob6S44UDRZJ4XEQdxEqvc/eJwAU0ErC2k3UsOl3wZ xjtfe1kAYmpbks4MCZLT59A5ql97iSd1Igay2AHo7hcAcUrdj+nRO87NR62K/RDPWfqo d1Xw== X-Gm-Message-State: AHQUAuaQ3nVai5FDrVppbVCVZNsSsfUHqkX7RuKhDo0636mGDMP6xu8p dfzmpG4bvDl8gLJaSnS0mwlrUkxOfKXuas+juQZKkg== X-Received: by 2002:a17:902:4464:: with SMTP id k91mr26032490pld.13.1549672893345; Fri, 08 Feb 2019 16:41:33 -0800 (PST) MIME-Version: 1.0 References: <20190209000840.11018-1-miguel.ojeda.sandonis@gmail.com> <20190209000840.11018-3-miguel.ojeda.sandonis@gmail.com> In-Reply-To: <20190209000840.11018-3-miguel.ojeda.sandonis@gmail.com> From: Nick Desaulniers Date: Fri, 8 Feb 2019 16:41:44 -0800 Message-ID: Subject: Re: [PATCH 2/3] Compiler Attributes: add support for __copy (gcc >= 9) To: Miguel Ojeda Cc: LKML , Martin Sebor , Arnd Bergmann , Laura Abbott , Luc Van Oostenryck , Andrey Konovalov , Kees Cook , Sean Christopherson Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 8, 2019 at 4:09 PM Miguel Ojeda wrote: > > From the GCC manual: > > copy > copy(function) > > The copy attribute applies the set of attributes with which function > has been declared to the declaration of the function to which > the attribute is applied. The attribute is designed for libraries > that define aliases or function resolvers that are expected > to specify the same set of attributes as their targets. The copy > attribute can be used with functions, variables, or types. However, > the kind of symbol to which the attribute is applied (either > function or variable) must match the kind of symbol to which > the argument refers. The copy attribute copies only syntactic and > semantic attributes but not attributes that affect a symbol=E2=80=99s > linkage or visibility such as alias, visibility, or weak. > The deprecated attribute is also not copied. > > https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html > > The upcoming GCC 9 release extends the -Wmissing-attributes warnings > (enabled by -Wall) to C and aliases: it warns when particular function > attributes are missing in the aliases but not in their target, e.g.: > > void __cold f(void) {} > void __alias("f") g(void); > > diagnoses: > > warning: 'g' specifies less restrictive attribute than > its target 'f': 'cold' [-Wmissing-attributes] > > Using __copy(f) we can copy the __cold attribute from f to g: > > void __cold f(void) {} > void __copy(f) __alias("f") g(void); > > This attribute is most useful to deal with situations where an alias > is declared but we don't know the exact attributes the target has. > > For instance, in the kernel, the widely used module_init/exit macros > define the init/cleanup_module aliases, but those cannot be marked > always as __init/__exit since they some modules do not have their > functions marked as such. Drop "they" from this sentence if there's a respin, otherwise looks helpful= . Reviewed-by: Nick Desaulniers > > Suggested-by: Martin Sebor > 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 19f32b0c29af..6b318efd8a74 100644 > --- a/include/linux/compiler_attributes.h > +++ b/include/linux/compiler_attributes.h > @@ -34,6 +34,7 @@ > #ifndef __has_attribute > # define __has_attribute(x) __GCC4_has_attribute_##x > # define __GCC4_has_attribute___assume_aligned__ (__GNUC_MINOR__ >= =3D 9) > +# define __GCC4_has_attribute___copy__ 0 > # define __GCC4_has_attribute___designated_init__ 0 > # define __GCC4_has_attribute___externally_visible__ 1 > # define __GCC4_has_attribute___noclone__ 1 > @@ -100,6 +101,19 @@ > */ > #define __attribute_const__ __attribute__((__const__)) > > +/* > + * Optional: only supported since gcc >=3D 9 > + * Optional: not supported by clang > + * Optional: not supported by icc > + * > + * gcc: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.= html#index-copy-function-attribute > + */ > +#if __has_attribute(__copy__) > +# define __copy(symbol) __attribute__((__copy__(symbol))= ) > +#else > +# define __copy(symbol) > +#endif > + > /* > * Don't. Just don't. See commit 771c035372a0 ("deprecate the '__depreca= ted' > * attribute warnings entirely and for good") for more information. > -- > 2.17.1 > --=20 Thanks, ~Nick Desaulniers