Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp298274imm; Sat, 1 Sep 2018 03:17:11 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaWBF2ovHIs0+2aAmJEMCfv/SEFg8yoRWMy5En/V27yaYgWL5Xbena7j9HsR81mEBe0/8qS X-Received: by 2002:a17:902:c7:: with SMTP id a65-v6mr6206210pla.264.1535797031241; Sat, 01 Sep 2018 03:17:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535797031; cv=none; d=google.com; s=arc-20160816; b=eLQBxPi3pMcWCy96gaBc+lFI6C5By+mZTzhAYc0hhnHhMKZItSM+k/3ET1GmcDdF6r enEKn6zbZJ1zIOFNYGUVt+3QJkU6ZEStpPHnb5q9BHCSlxckam9bIirL+7tGrUh/bEsW CwW9ASYWsrHyQWCLcK4Vw4NvrbabdsBf7nuKcqM8CCzapGcJzx5F0qEAR86DlY4AF/ll z47AGLyO6P1OfDF4NSkfPBGZ/b5aHeL/99e/LduYlLHoEFFLYgmASUAN4grRA4YOs/tw 9rPpRBeBztquIK80GcRIWTZj0oQF0vnrjnrv346cCEFHejCArM5c2tbapPWS8AcWQM/0 Nqog== 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:arc-authentication-results; bh=3urH8g43qSZ52IdD8RHU3TafFI/wiS/5BjpB3qIFOzk=; b=z1v4Qj/EU82Kk+E0QYbE1JwsJ0PsfQjhoCEMjzCjv8Usht+al9c/x3terhFBCM7ETJ IDsv7tS1vAR8Of+jWovmOa6F+3aDY+wQr0T+QoUv9m3lVOnmjGOOKn91tgFuZOuoqHj4 r99TBYKDSgi2BBgwhqzK/lh2HADLJl2CcHfYdAOzc/VHf1QJFmfL4c9+TCsG6aC5bw+i WACQdbm8o58ueFrRXBycupBgBpYaAhALVpAYokLk9tmMImi1L1MLChvc3ivTBsgWYkXT PLQBreA2kiRSK+2BAdaIVdXbrPDDWqJULWfweLagXpFSCaeFRKBJ7Hw2iBXGs+lCCKmQ oIgA== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a1-v6si12188816pga.475.2018.09.01.03.16.42; Sat, 01 Sep 2018 03:17:11 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727234AbeIAO0T (ORCPT + 99 others); Sat, 1 Sep 2018 10:26:19 -0400 Received: from nautica.notk.org ([91.121.71.147]:53657 "EHLO nautica.notk.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726430AbeIAO0T (ORCPT ); Sat, 1 Sep 2018 10:26:19 -0400 Received: by nautica.notk.org (Postfix, from userid 1001) id 1640AC009; Sat, 1 Sep 2018 12:14:45 +0200 (CEST) Date: Sat, 1 Sep 2018 12:14:30 +0200 From: Dominique Martinet 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 , Nick Desaulniers Subject: Re: [PATCH 7/7] Compiler Attributes: use feature checks instead of version checks Message-ID: <20180901101430.GA21877@nautica> 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=utf-8 Content-Disposition: inline In-Reply-To: <20180831170514.24665-7-miguel.ojeda.sandonis@gmail.com> User-Agent: Mutt/1.5.21 (2010-09-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Miguel Ojeda wrote on Fri, Aug 31, 2018: > 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. > > Cc: Eli Friedman > Cc: Christopher Li > Cc: Kees Cook > Cc: Ingo Molnar > Cc: Geert Uytterhoeven > Cc: Arnd Bergmann > Cc: Greg Kroah-Hartman > Cc: Masahiro Yamada > Cc: Joe Perches > Cc: Dominique Martinet > Cc: Nick Desaulniers > Cc: Linus Torvalds > Signed-off-by: Miguel Ojeda Nice work! Since I'm being Cc'd I took the time to test this as well, and have no problem with libbcc-building-with-clang (or native x86 gcc build) Nick already made many comments so I only have one more. > [...] > 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 > [...] > +/* > + * 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 Hmm, if this is in this file and not compiler-gcc, I am not sure about using GNUC_MINOR without checking the major -- I have no idea what kind of versions e.g. icc will use (or what attributes ancients version of clang or old icc support, actually) It's a bit of research work but I think it'd be cleaner to define similar macros for all three compilers, if we care about the old versions... Or actually.. For clang you've implicitely required clang >= 3.0 in patch 3 of this serie, so presumabely it wouldn't need this compat macro at all. For icc I think icc 17 is still fairly recent... But I just abused work to test and linux fails to compile with icc 15/17/18 for other reasons (unrelated to this patch), so unless anyone helps with this I'm tempted to suggest leaving it at it, and whoever that is will probably have a better idea of how far back they want to make icc work / what attributes are defined there. It's a bit of a shame there's no linux-compilers list to reach out to :) (this would need to move the include of this file after the compiler-specific headers, but from what I can see there is no problem with that) -- Dominique