From: Masahiro Yamada <yamada.masahiro@socionext.com>
To: Linus Torvalds <torvalds@linux-foundation.org>
Cc: Kees Cook <keescook@chromium.org>,
Nick Desaulniers <ndesaulniers@google.com>,
Joe Perches <joe@perches.com>, Jonathan Corbet <corbet@lwn.net>,
Masahiro Yamada <yamada.masahiro@socionext.com>,
Arnd Bergmann <arnd@arndb.de>,
David Woodhouse <dwmw@amazon.co.uk>,
linux-kernel@vger.kernel.org,
Thomas Gleixner <tglx@linutronix.de>,
Will Deacon <will.deacon@arm.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Ingo Molnar <mingo@kernel.org>,
Andrew Morton <akpm@linux-foundation.org>
Subject: [PATCH] compiler-gcc: get back Clang build
Date: Tue, 21 Aug 2018 15:48:08 +0900 [thread overview]
Message-ID: <1534834088-15835-1-git-send-email-yamada.masahiro@socionext.com> (raw)
Commit cafa0010cd51 ("Raise the minimum required gcc version to 4.6")
missed the fact that <linux/compiler-gcc.h> is included by Clang
as well as by GCC.
Clang actually defines __GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__
and it looks like GCC 4.2.1.
$ scripts/gcc-version.sh -p clang
040201
If you try to build the kernel with Clang, you will get the
"Sorry, your compiler is too old - please upgrade it."
followed by a bunch of "unknown attribute" warnings.
Add !defined(__clang__) to the minimum version check.
Also, revive the version test blocks for versions >= 4.2.1
in order to disable features not supported by Clang.
Fixes: cafa0010cd51 ("Raise the minimum required gcc version to 4.6")
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
---
include/linux/compiler-gcc.h | 34 ++++++++++++++++++++++++++++------
1 file changed, 28 insertions(+), 6 deletions(-)
diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc.h
index 250b9b7..8e41fd2 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc.h
@@ -10,7 +10,7 @@
+ __GNUC_MINOR__ * 100 \
+ __GNUC_PATCHLEVEL__)
-#if GCC_VERSION < 40600
+#if !defined(__clang__) && GCC_VERSION < 40600
# error Sorry, your compiler is too old - please upgrade it.
#endif
@@ -163,7 +163,16 @@
#define __used __attribute__((__used__))
#define __compiler_offsetof(a, b) \
__builtin_offsetof(a, b)
+#define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
+/*
+ * GCC version specific checks
+ *
+ * Keep the version checks for 4.2.1 or newer
+ * because Clang defines GCC_VERSION as 40201
+ */
+
+#if GCC_VERSION >= 40300
/* Mark functions as cold. gcc will assume any path leading to a call
* to them will be unlikely. This means a lot of manual unlikely()s
* are unnecessary now for any paths leading to the usual suspects
@@ -182,15 +191,20 @@
#define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
+#ifndef __CHECKER__
+# define __compiletime_warning(message) __attribute__((warning(message)))
+# define __compiletime_error(message) __attribute__((error(message)))
+#endif /* __CHECKER__ */
+#endif /* GCC_VERSION >= 40300 */
+
+#if GCC_VERSION >= 40400
#define __optimize(level) __attribute__((__optimize__(level)))
#define __nostackprotector __optimize("no-stack-protector")
+#endif /* GCC_VERSION >= 40400 */
-#define __compiletime_object_size(obj) __builtin_object_size(obj, 0)
+#if GCC_VERSION >= 40500
#ifndef __CHECKER__
-#define __compiletime_warning(message) __attribute__((warning(message)))
-#define __compiletime_error(message) __attribute__((error(message)))
-
#ifdef LATENT_ENTROPY_PLUGIN
#define __latent_entropy __attribute__((latent_entropy))
#endif
@@ -232,6 +246,9 @@
#define randomized_struct_fields_end } __randomize_layout;
#endif
+#endif /* GCC_VERSION >= 40500 */
+
+#if GCC_VERSION >= 40600
/*
* When used with Link Time Optimization, gcc can optimize away C functions or
* variables which are referenced only from assembly code. __visible tells the
@@ -240,7 +257,7 @@
*/
#define __visible __attribute__((externally_visible))
-/* gcc version specific checks */
+#endif /* GCC_VERSION >= 40600 */
#if GCC_VERSION >= 40900 && !defined(__CHECKER__)
/*
@@ -274,8 +291,10 @@
* folding in __builtin_bswap*() (yet), so don't set these for it.
*/
#if defined(CONFIG_ARCH_USE_BUILTIN_BSWAP) && !defined(__CHECKER__)
+#if GCC_VERSION >= 40400
#define __HAVE_BUILTIN_BSWAP32__
#define __HAVE_BUILTIN_BSWAP64__
+#endif
#if GCC_VERSION >= 40800
#define __HAVE_BUILTIN_BSWAP16__
#endif
@@ -327,9 +346,12 @@
#define __diag_GCC_warn warning
#define __diag_GCC_error error
+/* Compilers before gcc-4.6 do not understand "#pragma GCC diagnostic push" */
+#if GCC_VERSION >= 40600
#define __diag_str1(s) #s
#define __diag_str(s) __diag_str1(s)
#define __diag(s) _Pragma(__diag_str(GCC diagnostic s))
+#endif
#if GCC_VERSION >= 80000
#define __diag_GCC_8(s) __diag(s)
--
2.7.4
next reply other threads:[~2018-08-21 6:49 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-21 6:48 Masahiro Yamada [this message]
2018-08-21 8:09 ` [PATCH] compiler-gcc: get back Clang build Nick Desaulniers
2018-08-21 10:39 ` Joe Perches
2018-08-21 16:35 ` Nick Desaulniers
2018-08-21 17:13 ` Masahiro Yamada
2018-08-21 17:20 ` Joe Perches
2018-08-21 12:38 ` Dominique Martinet
2018-08-21 16:32 ` Nick Desaulniers
2018-08-21 16:45 ` Joe Perches
2018-08-21 17:00 ` Nick Desaulniers
2018-08-22 4:16 ` Dominique Martinet
2018-08-22 4:22 ` Joe Perches
2018-08-22 4:32 ` Dominique Martinet
2018-08-22 18:31 ` Nick Desaulniers
2018-08-22 19:01 ` Nick Desaulniers
2018-08-22 20:50 ` Joe Perches
2018-08-22 23:05 ` Nick Desaulniers
2018-08-22 23:32 ` Joe Perches
2018-08-22 23:57 ` Dominique Martinet
2018-08-21 16:33 ` Joe Perches
2018-08-21 16:57 ` Nick Desaulniers
2018-08-21 17:22 ` Joe Perches
2018-08-21 17:07 ` Masahiro Yamada
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1534834088-15835-1-git-send-email-yamada.masahiro@socionext.com \
--to=yamada.masahiro@socionext.com \
--cc=akpm@linux-foundation.org \
--cc=arnd@arndb.de \
--cc=corbet@lwn.net \
--cc=dwmw@amazon.co.uk \
--cc=geert@linux-m68k.org \
--cc=joe@perches.com \
--cc=keescook@chromium.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=ndesaulniers@google.com \
--cc=tglx@linutronix.de \
--cc=torvalds@linux-foundation.org \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).