Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp288955imm; Sat, 1 Sep 2018 02:58:12 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZqDA2NR9xH3RH+drEn7vPWzkyCIF6dYA2oeUTpJCc4RPhJx7rcCmG8kvH45DD6j68L6KC+ X-Received: by 2002:a63:225f:: with SMTP id t31-v6mr17946031pgm.275.1535795892717; Sat, 01 Sep 2018 02:58:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535795892; cv=none; d=google.com; s=arc-20160816; b=K7XNbsv9/xCijJkJ5gad2+ZYUQiACrmPmvwmPGhmxp4VBl7KNYZ7FedGG/VSis6zuZ F1fI7kOKgfgnfBSdkl/5HQIBgxMlCkoCBLLmmdURCxK02FX59Tr0kl3PvxPF8t+bNsVj yUxHvDVHPQjJG3w6h5PBNfPm+ClQQVNCV+3Nswmlu0zlnpa042vv6aQ54MzAyojrC2Zm ldNzsFPxb5mzjR0Fhd9LNa+Fp3+/LrcMFhybG/0zUEAlhErNBvqoIMM0ajKfbJNpNBgn LatOTcjS//BXZ7rLjL6sJ/YfGGMckaUcpPW+uBY8dScJO2ahPh7FiWvnuk97WiHTXS3m uOeQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=y68SOC07le/SZ4yltDqOkzxDrSzriWveq7jDunIYiys=; b=QrJ0vvfyAw2/tqw9kt/NQQUOaDwaGBA2+49oYw5tHpV5Ls8W7F6Vm5b1CGaPJoIxz1 YiHMALGUCxXWeH1AK3vLGCWsikQiJY00mMXyh9o0Dw/lJeh6+9lFtVqFiTf6hkvk3dlg Ap+a76YItbcyCqZaLxgaOkeJ6AfZxzpp6PTOJbda358Cm8pfAhKPivZoFIRRRVaqRkLr bw87o8RJTj6QOUIeAono92SWnqb2By96Ckbuz23/PUbRbnqWh5niKQwYhSwcIhCoP6Bf 6XWzAhUz+FrQLHRt44RzxtLgZzalHA2mbdsr4FIw20ahQBOCwvCSlZOL2qZxL9PVSC0K O/cQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=eCMTjM6Z; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 44-v6si12422108plc.409.2018.09.01.02.57.57; Sat, 01 Sep 2018 02:58:12 -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=@gmail.com header.s=20161025 header.b=eCMTjM6Z; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727442AbeIAOIM (ORCPT + 99 others); Sat, 1 Sep 2018 10:08:12 -0400 Received: from mail-wr1-f68.google.com ([209.85.221.68]:42543 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725973AbeIAOIL (ORCPT ); Sat, 1 Sep 2018 10:08:11 -0400 Received: by mail-wr1-f68.google.com with SMTP id v17-v6so13310191wrr.9 for ; Sat, 01 Sep 2018 02:56:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=y68SOC07le/SZ4yltDqOkzxDrSzriWveq7jDunIYiys=; b=eCMTjM6Zq3r+jZYgemwXGMaZD+P2vWI+f/SqcABfCB6tv03gTTqXrhIVVheYFVFpyV ucMsjRSgG8KBjUhC8wYNnKOQz9houd0CqpfHIxMLwOwoYFl3l3P77XFf96M+RI4eixr2 un+jtrqhnTySzLBEUE7P92aCefBToCeCC16gVJnhCs1uO1ivgX7VUFWDkx8j71kJLU4F Qp63F8o0amwd3d3r9WVXyneS4na1j3bTd1JsXvI9sTv+eNFJ4ZtO+NMF1FgkS3rFMg0X xu8ZwJqvr3L7MJnUr8fUMjomoDO5lQRFc1i1PDtm23K/Dpw5ZXt1wafnKhqs7Bm9bdFd JYbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=y68SOC07le/SZ4yltDqOkzxDrSzriWveq7jDunIYiys=; b=dE27RtIicl9oHHeM1FE2IMJ5/r7yEUQKI0mKzyuYigMLATB2PO/SbR+YXXh/DYSa2z ysYlG1dzEjVeX52/P2x5GkPVEnEbNGdknAESdLrV8yvD4ETtwJB2aoDk9OLU8nIWAL7T rrlUV+2YcbVjnKe9NYAcCseMhFAjaILMFsRbIunzHs4L5TFor8Jd0iVUkgjL3tbXbmtH WIaP94bnv8M76jbFmWXn+def6Zfd5y3pmQrJciZ1Uz/fIb9oLCJKiOMjUqAXgOZXhnbE x3m9e8Xg3NHDu8NAYYUVHW87Km/XuLleNyfUixBVdDgXRCKVs6jIzr/1RiMtHxVTYozH yRYg== X-Gm-Message-State: APzg51DAU/T+d4g6WpH3z9vvnUjUqpNVXgzB1yHY2csm5DdDR6HNduAO gjasDrYjSZLBA5dW29HfpWA= X-Received: by 2002:adf:9c12:: with SMTP id f18-v6mr14058664wrc.93.1535795802392; Sat, 01 Sep 2018 02:56:42 -0700 (PDT) Received: from ltop.local ([2a02:a03f:4006:df00:8852:4a4c:95e8:7a2]) by smtp.gmail.com with ESMTPSA id w18-v6sm24683751wrc.38.2018.09.01.02.56.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 01 Sep 2018 02:56:41 -0700 (PDT) Date: Sat, 1 Sep 2018 11:56:40 +0200 From: Luc Van Oostenryck To: Miguel Ojeda Cc: Linus Torvalds , linux-kernel@vger.kernel.org, Eli Friedman , Christopher Li , Kees Cook , Ingo Molnar , Geert Uytterhoeven , Arnd Bergmann , Greg Kroah-Hartman , Masahiro Yamada , Joe Perches , Dominique Martinet , Nick Desaulniers Subject: Re: [PATCH 7/7] Compiler Attributes: use feature checks instead of version checks Message-ID: <20180901095639.ms6kkzywazkvs376@ltop.local> References: <20180831170514.24665-1-miguel.ojeda.sandonis@gmail.com> <20180831170514.24665-7-miguel.ojeda.sandonis@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180831170514.24665-7-miguel.ojeda.sandonis@gmail.com> User-Agent: NeoMutt/20180622 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Aug 31, 2018 at 07:05:14PM +0200, Miguel Ojeda wrote: > Instead of using version checks per-compiler to define (or not) > each attribute, use __has_attribute to test for them, following > the cleanup started with commit 815f0ddb346c > ("include/linux/compiler*.h: make compiler-*.h mutually exclusive"). > > All the attributes that are fairly common/standard (i.e. those that > do not require extra logic to define them) have been moved > to a new file include/linux/compiler_attributes.h. > > In an effort to make the file as regular as possible, comments > stating the purpose of attributes have been removed. Instead, > links to the compiler docs have been added (i.e. to gcc and, > if available, to clang as well). In addition, they have been sorted. > > Finally, if an attribute is optional (i.e. if it is guarded > by __has_attribute), the reason has been stated for future reference. > > diff --git a/include/linux/compiler_attributes.h b/include/linux/compiler_attributes.h > new file mode 100644 > index 000000000000..a9dfafc8fd19 > --- /dev/null > +++ b/include/linux/compiler_attributes.h > @@ -0,0 +1,226 @@ > +#ifndef __LINUX_COMPILER_ATTRIBUTES_H > +#define __LINUX_COMPILER_ATTRIBUTES_H > + > +/* > + * This file is meant to be sorted (by actual attribute name, > + * not by #define identifier). > + * > + * Do not add here attributes which depend on others or require extra logic. > + * > + * If an attribute is optional, state the reason in the comment. > + */ > + > +/* > + * To check for optional attributes, we use __has_attribute, which is supported > + * on gcc >= 5, clang >= 2.9 and icc >= 17. In the meantime, to support > + * 4.6 <= gcc < 5, we implement __has_attribute by hand. > + */ > +#ifndef __has_attribute > +#define __has_attribute(x) __GCC4_has_attribute_##x > +#define __GCC4_has_attribute_externally_visible 1 > +#define __GCC4_has_attribute_noclone 1 > +#define __GCC4_has_attribute_optimize 1 > +#if __GNUC_MINOR__ >= 8 > +#define __GCC4_has_attribute_no_sanitize_address 1 > +#endif > +#if __GNUC_MINOR__ >= 9 > +#define __GCC4_has_attribute_assume_aligned 1 > +#endif > +#endif For sparse (which doesn't support __has_attribute() yet and defines __GNUC_MINOR__ depending on the compiler used to build it) it won't be totally correct since the concerned attributes here will be incorrectly considered as not supported. But, since these attributes have no semantic effects for sparse, it won't matter. So, for sparse: Reviewed-by: Luc Van Oostenryck -- Luc