Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp378378imm; Sat, 1 Sep 2018 05:57:39 -0700 (PDT) X-Google-Smtp-Source: ANB0Vda66EC1DknKEu2Dh+Zsq/69Xz314XYYN8CTmuH56/WuYu4+jdBtgEG0zSEdfWntn/vcPD7+ X-Received: by 2002:a63:6b03:: with SMTP id g3-v6mr16462417pgc.57.1535806659812; Sat, 01 Sep 2018 05:57:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535806659; cv=none; d=google.com; s=arc-20160816; b=JVyh9Kpgb1hy8hRi5+WATpGsJcl1GshY9+U0QSHsm/KPOIwzCCgQeJE0c6/W4XD9bX 00AsMAIg66bfBzs2Qs+Qphg+pprr//1IqNKTCyTPxB74SaqUDbzoRwno3hRR7KQh4n2M y0AKv6R352Hn+HURU8pNgz3+2uuKHrXHtvQ0OoDodG2YgzOLShKNgN45LZgdIhPMmXEn R+Nvpf6nqZ7MZi6YGlttkYdW94siBsqzb/eBFOhQ/vHDnRKp90Dt6BSGt8k3H40kIB9m o9Ze9FE3NndGU5OyFEkqbtJoeru9oVqSV48W0idiVPgKpwKt0Pxy/jVfVCOLajT803pJ DKkw== 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 :references:in-reply-to:mime-version:dkim-signature :arc-authentication-results; bh=S0FTQX6kRiRrZHrH4HqQkEvbgBClX1Md+QOaVczeHPk=; b=Tc5fanB+kop/Lr44tz7xBM4Ji3DvqNUULETMegFoxv7NPG/co7iDMJx3PK1+IvsKPB oUGU1yXo8AaaOONG+5YBmZQ3QqTfq1J9m7R9f763A7UnOw1U9N77HNyYf/ejTUwzhDdz fleQZ6aoHxaDICwqMF9jpgb8dXBRDVnr4WVMYcPrxG6JamlMbHw3BF4N92Rs3A4iRYr8 BpZq3cHAl3rdnYdOgc14k9dBBxwbDSMtE4s0NDo/VV3sYwrA1MnZ2IQLIRviwA6EdFHt 4iQGIwfxyqjkoWdhtgF4bUioC//pEenR5VNlXBA9dewdnuRhH0XPvprJA09tUmZYxv+C oJwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=TJw0yAL8; 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 u8-v6si11069238plz.481.2018.09.01.05.57.24; Sat, 01 Sep 2018 05:57:39 -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=TJw0yAL8; 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 S1727416AbeIARIS (ORCPT + 99 others); Sat, 1 Sep 2018 13:08:18 -0400 Received: from mail-qt0-f193.google.com ([209.85.216.193]:37261 "EHLO mail-qt0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726430AbeIARIS (ORCPT ); Sat, 1 Sep 2018 13:08:18 -0400 Received: by mail-qt0-f193.google.com with SMTP id n6-v6so17479717qtl.4 for ; Sat, 01 Sep 2018 05:56:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=S0FTQX6kRiRrZHrH4HqQkEvbgBClX1Md+QOaVczeHPk=; b=TJw0yAL8AyLbXMXA1SdPypW1olHc35uvmv9fW8Uh89a4+qDCQsQCkNHMdX3C+I9XFD eH7x7dNzHZIpYyMVOMfysENYNotfi9x+F7fC/nhDpSDQUQvcUGbrTxl8YfJpipXC/7MO fyZX0BKUDz0Xnm7oPE0CUA59PLf//OK4iXvuN7gsWKb4gRKZMomHLK4CpSo3641E1hLy 8GaSB/0r7gHlqUJkOU/OF92ktgJbpdKr/AWAfZBFSahXV7gEl9hY34j/cRqNsALbRHGN xcBtQgN7ALT/e6TShT18ZdaWyFnd3DhSJJP7mClSt40TV/AZGtQsVEf8abDUx8ud5kIO T4fQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=S0FTQX6kRiRrZHrH4HqQkEvbgBClX1Md+QOaVczeHPk=; b=ucU6i0xM6FyIpndPJj+nd1aBGt8MbdxcBcGT6CiBWmfgiC2rRy1LPDXS5EVFoXYLcR yWH5kRSOJt7OnRu/2EG6XVGTEXXLR/RspN1vB8sO3UMOCML3XUZhtgHAxr5FY6cBIvh2 aUom9vk/g0Ubh884uAF3sGNuOmwD46wTqC3D4aq3oG9Ey1n3n+Ozh6n9k+zc09yVpxjQ Nm2nqL+W+AzBj861Ch1SpnOoOVF6BGjvnxKG3olJZR6XuRgSn6k9UdzKd8gO48QStzcQ U/uZd8LzIwMhx/E9qXXyQPoFoPOReMMIr1UhlGqmn2ATCmPQ1D97+4Fckic6BSYlG7gz oj5Q== X-Gm-Message-State: APzg51DCdbvUWIw9SZNTkWS0vclAVYC6eQmHnIDj64H1gBcY7okTiv9M 2vyw9r7aaLMLUBiiO13+JZiTG7xeV/tE3uEX09c= X-Received: by 2002:a0c:aac9:: with SMTP id g9-v6mr19565913qvb.78.1535806578971; Sat, 01 Sep 2018 05:56:18 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:aed:2291:0:0:0:0:0 with HTTP; Sat, 1 Sep 2018 05:55:58 -0700 (PDT) In-Reply-To: <20180901101430.GA21877@nautica> References: <20180831170514.24665-1-miguel.ojeda.sandonis@gmail.com> <20180831170514.24665-7-miguel.ojeda.sandonis@gmail.com> <20180901101430.GA21877@nautica> From: Miguel Ojeda Date: Sat, 1 Sep 2018 14:55:58 +0200 Message-ID: Subject: Re: [PATCH 7/7] Compiler Attributes: use feature checks instead of version checks To: Dominique Martinet Cc: Linus Torvalds , linux-kernel , Eli Friedman , Christopher Li , Kees Cook , Ingo Molnar , Geert Uytterhoeven , Arnd Bergmann , Greg Kroah-Hartman , Masahiro Yamada , Joe Perches , Nick Desaulniers 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 Hi Dominique, On Sat, Sep 1, 2018 at 12:14 PM, Dominique Martinet wrote: > 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) Thanks a lot for testing! :-) > > 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) The idea here is that all non-gcc recent compilers that we may care about support __has_attribute,so if we are inside the #ifndef, we *have* to be gcc < 5 (see https://godbolt.org/z/NQFdsK). > > > 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 Thanks a lot for testing it! I agree that icc 17 is fairly recent, but is there anybody using it on a regular basis to compile the kernel -- I guess your tests confirm that there isn't, but you never know... :-) As for clang < 2.9, I doubt anybody is using it for anything meaningful. Also, we should note that this is about compiling the latest greatest kernel release, which someone with older compilers is less likely to be doing with clang and icc than gcc, I guess. As for the failures: indeed, if anyone is actually doing it, they probably need to apply quite some third-party patches anyway, so they can also patch this file as well. Otherwise, they can always speak up and ask for support. If nobody says anything though, then we have proof nobody cares about it... > 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) I included it as soon as possible so that other code (e.g. the compiler-specific headers) can depend on the common attributes for anything they need (in this way, the compiler_attributes.h can be considered like it defines some extensions to the C language that we allow all code in the kernel to use -- as if it was not there to begin with). By the way, do you know if there are some public docs on the attributes supported by icc that we can link to? I couldn't find anything in a quick search, both in google and in the icc's "Compatibility" pages... Cheers, Miguel