[PATCH] gcc: clamp gcc version to most highest specific header version available

From: Hannes Frederic Sowa
Date: Fri Sep 05 2014 - 16:40:14 EST


As announced in [1] gcc will increase its major number yearly but we don't
need to include gcc version specific quirks for every version normally.

This patch allows to compile every kernel with all new versions of gcc
without adding a specific compiler-gccX.h header. We do so by clamping
the __GNUC__ version to the most specific version dependent header file.

If someone adds a new gccX.h file __GCC_CLAMP_VERSION_HEADER also needs
to be modified.

The decision if chained including of header files (e.g. gcc5.h includes
gcc4.h) is necessary or should be avoided can be postponed until more
experience in using the official gcc release is gained.

Tested with gcc4 and gcc5.

[1] https://gcc.gnu.org/develop.html#num_scheme

Cc: Aaro Koskinen <aaro.koskinen@xxxxxx>
Cc: Sasha Levin <sasha.levin@xxxxxxxxxx>
Cc: akpm@xxxxxxxxxxxxxxxxxxx
Cc: mingo@xxxxxxxxxx
Cc: H. Peter Anvin <hpa@xxxxxxxxx>
Cc: Joe Perches <joe@xxxxxxxxxxx>
Cc: Richard Weinberger <richard.weinberger@xxxxxxxxx>
Signed-off-by: Hannes Frederic Sowa <hannes@xxxxxxxxxxxxxxxxxxx>
---
include/linux/{compiler-gcc.h => compiler-gcc/gcc.h} | 12 ++++++++++--
include/linux/{compiler-gcc3.h => compiler-gcc/gcc3.h} | 0
include/linux/{compiler-gcc4.h => compiler-gcc/gcc4.h} | 0
include/linux/compiler.h | 2 +-
4 files changed, 11 insertions(+), 3 deletions(-)
rename include/linux/{compiler-gcc.h => compiler-gcc/gcc.h} (91%)
rename include/linux/{compiler-gcc3.h => compiler-gcc/gcc3.h} (100%)
rename include/linux/{compiler-gcc4.h => compiler-gcc/gcc4.h} (100%)

diff --git a/include/linux/compiler-gcc.h b/include/linux/compiler-gcc/gcc.h
similarity index 91%
rename from include/linux/compiler-gcc.h
rename to include/linux/compiler-gcc/gcc.h
index 02ae99e..0681fa3 100644
--- a/include/linux/compiler-gcc.h
+++ b/include/linux/compiler-gcc/gcc.h
@@ -1,5 +1,5 @@
#ifndef __LINUX_COMPILER_H
-#error "Please don't include <linux/compiler-gcc.h> directly, include <linux/compiler.h> instead."
+#error "Please don't include <linux/compiler-gcc/gcc.h> directly, include <linux/compiler.h> instead."
#endif

/*
@@ -101,9 +101,17 @@
#define __always_unused __attribute__((unused))

#define __gcc_header(x) #x
-#define _gcc_header(x) __gcc_header(linux/compiler-gcc##x.h)
+#define _gcc_header(x) __gcc_header(linux/compiler-gcc/gcc##x.h)
#define gcc_header(x) _gcc_header(x)
+
+/* increase this if you add a new compiler-gcc/gccX.h header file */
+#define __GCC_CLAMP_VERSION_HEADER 4
+
+#if __GNUC__ > __GCC_CLAMP_VERSION_HEADER
+#include gcc_header(__GCC_CLAMP_VERSION_HEADER)
+#else
#include gcc_header(__GNUC__)
+#endif

#if !defined(__noclone)
#define __noclone /* not needed */
diff --git a/include/linux/compiler-gcc3.h b/include/linux/compiler-gcc/gcc3.h
similarity index 100%
rename from include/linux/compiler-gcc3.h
rename to include/linux/compiler-gcc/gcc3.h
diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc/gcc4.h
similarity index 100%
rename from include/linux/compiler-gcc4.h
rename to include/linux/compiler-gcc/gcc4.h
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index d5ad7b1..06be28b 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -51,7 +51,7 @@ extern void __chk_io_ptr(const volatile void __iomem *);
#ifdef __KERNEL__

#ifdef __GNUC__
-#include <linux/compiler-gcc.h>
+#include <linux/compiler-gcc/gcc.h>
#endif

#define notrace __attribute__((no_instrument_function))
--
1.9.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/