Skip to contentSkip to conversation

add compiler-gcc4.h

PATCH In review Adrian Bunk 5 participants 11 messages Jan 30, 2005 – Feb 6, 2005 Sparse checker

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 add compiler-gcc4.h

With the release of gcc 4.0 being only a few months away and people already tring compiling with it, it's time for adding a compiler-gcc4.h .

This patch contains the following changes:
- compiler-gcc+.h: add the missing noinline and __compiler_offsetof
- compiler-gcc4.h: new file based on the corrected compiler-gcc+.h
- compiler.h: include compiler-gcc4.h for gcc 4
- compiler-gcc3.h: remove __compiler_offsetof (there will never be a gcc 3.5) small indention corrections

I've tested the compilation with both gcc 3.4.4 and a recent gcc 4.0 snapshot from Debian experimental.

---

 include/linux/compiler-gcc+.h |    3 +++
 include/linux/compiler-gcc3.h |   10 ++++------
 include/linux/compiler-gcc4.h |   16 ++++++++++++++++
 include/linux/compiler.h      |    6 ++++--
 4 files changed, 27 insertions(+), 8 deletions(-)
include/linux/compiler.h renamed from include/linux/compiler.h.old +4 -2
@@ -34,8 +34,10 @@
 
 #ifdef __KERNEL__
 
-#if __GNUC__ > 3
-# include <linux/compiler-gcc+.h>	/* catch-all for GCC 4, 5, etc. */
+#if __GNUC__ > 4
+# include <linux/compiler-gcc+.h>	/* catch-all for GCC 5, 6, etc. */
+#elif __GNUC__ == 4
+# include <linux/compiler-gcc4.h>
 #elif __GNUC__ == 3
 # include <linux/compiler-gcc3.h>
 #elif __GNUC__ == 2
include/linux/compiler-gcc+.h renamed from include/linux/compiler-gcc+.h.old +3 -0
@@ -13,4 +13,7 @@
 #define __attribute_used__	__attribute__((__used__))
 #define __attribute_pure__	__attribute__((pure))
 #define __attribute_const__	__attribute__((__const__))
+#define  noinline		__attribute__((noinline))
 #define __must_check 		__attribute__((warn_unused_result))
+#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
+
include/linux/compiler-gcc3.h renamed from include/linux/compiler-gcc3.h.old +4 -6
@@ -10,7 +10,7 @@
 #endif
 
 #if __GNUC_MINOR__ > 0
-# define __deprecated	__attribute__((deprecated))
+# define __deprecated		__attribute__((deprecated))
 #endif
 
 #if __GNUC_MINOR__ >= 3
@@ -23,12 +23,10 @@
 #define __attribute_const__	__attribute__((__const__))
 
 #if __GNUC_MINOR__ >= 1
-#define  noinline __attribute__((noinline))
+#define  noinline		__attribute__((noinline))
 #endif
+
 #if __GNUC_MINOR__ >= 4
-#define __must_check __attribute__((warn_unused_result))
+#define __must_check		__attribute__((warn_unused_result))
 #endif
 
-#if __GNUC_MINOR__ >= 5
-#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
-#endif
include/linux/compiler-gcc4.h new file +16 -0
@@ -0,0 +1,16 @@
+/* Never include this file directly.  Include <linux/compiler.h> instead.  */
+
+/* These definitions are for GCC v4.x.  */
+#include <linux/compiler-gcc.h>
+
+#define inline			inline		__attribute__((always_inline))
+#define __inline__		__inline__	__attribute__((always_inline))
+#define __inline		__inline	__attribute__((always_inline))
+#define __deprecated		__attribute__((deprecated))
+#define __attribute_used__	__attribute__((__used__))
+#define __attribute_pure__	__attribute__((pure))
+#define __attribute_const__	__attribute__((__const__))
+#define  noinline		__attribute__((noinline))
+#define __must_check 		__attribute__((warn_unused_result))
+#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
+
#1 lore raw
Quoted 10 lines · Adrian Bunk

With the release of gcc 4.0 being only a few months away and people already tring compiling with it, it's time for adding a compiler-gcc4.h .

This patch contains the following changes:
- compiler-gcc+.h: add the missing noinline and __compiler_offsetof
- compiler-gcc4.h: new file based on the corrected compiler-gcc+.h
- compiler.h: include compiler-gcc4.h for gcc 4
- compiler-gcc3.h: remove __compiler_offsetof (there will never be a gcc 3.5) small indention corrections

I don't think it makes much sense right now because it's basically identical to compiler-gcc3.h. I would only add it where there is a need for a real difference.

-Andi

#2 lore raw
Quoted 13 lines · Andi Kleen
Quoted 10 lines · Adrian Bunk

With the release of gcc 4.0 being only a few months away and people already tring compiling with it, it's time for adding a compiler-gcc4.h .

This patch contains the following changes:
- compiler-gcc+.h: add the missing noinline and __compiler_offsetof
- compiler-gcc4.h: new file based on the corrected compiler-gcc+.h
- compiler.h: include compiler-gcc4.h for gcc 4
- compiler-gcc3.h: remove __compiler_offsetof (there will never be a gcc 3.5) small indention corrections

Quoted 3 lines

I don't think it makes much sense right now because it's basically identical to compiler-gcc3.h. I would only add it where there is a need for a real difference.

The currently used file for gcc 4 is compiler-gcc+.h, not compiler-gcc3.h .

Quoted 1 line

-Andi

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#3 lore raw
In reply to Andi Kleen
Quoted 21 lines · Andi Kleen
Quoted 11 lines · Adrian Bunk

With the release of gcc 4.0 being only a few months away and people already tring compiling with it, it's time for adding a compiler-gcc4.h .

This patch contains the following changes:
- compiler-gcc+.h: add the missing noinline and __compiler_offsetof
- compiler-gcc4.h: new file based on the corrected compiler-gcc+.h
- compiler.h: include compiler-gcc4.h for gcc 4
- compiler-gcc3.h: remove __compiler_offsetof (there will never be a gcc 3.5) small indention corrections

I don't think it makes much sense right now because it's basically
identical to compiler-gcc3.h. I would only add it where there is a need for a real difference.

(quoted diff) +0 -2
-Andi
-
Quoted 7 lines

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

Hi!
But maybe gcc 4 will get different later, so I think this patch makes sense.

Matthias-Christian Ott

#4 lore raw
Followup to:  <[email protected]>
By author:    Matthias-Christian Ott <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 4 lines

Hi!
But maybe gcc 4 will get different later, so I think this patch makes sense.

No, it doesn't. You fork when you have a reason. Eager forking is *BAD*.

-hpa

#5 lore raw
Quoted 10 lines · H. Peter Anvin
Followup to:  <[email protected]>
By author:    Matthias-Christian Ott <[email protected]>
In newsgroup: linux.dev.kernel
Quoted 4 lines

Hi!
But maybe gcc 4 will get different later, so I think this patch makes sense.

No, it doesn't. You fork when you have a reason. Eager forking is *BAD*.

As I already said in this thread:
The currently used file for gcc 4 is compiler-gcc+.h, not compiler-gcc3.h .

And the current setup is to have one file for every major number of gcc. I have no strong opinion whether this approach or the approach of one file for all gcc versions is better - but with the current approach, everything else than a separate file for gcc 4 wasn't logical.

I can offer the following choices:
- please apply this compiler-gcc4.h patch
- let me send a patch merging all compiler-gcc*.h files into one compiler-gcc.h file
- let me send a patch merging all compiler-gcc*.h files back into compiler.h

Quoted 1 line

-hpa

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#6 lore raw
Quoted 7 lines · Adrian Bunk

As I already said in this thread:
The currently used file for gcc 4 is compiler-gcc+.h, not compiler-gcc3.h .

And the current setup is to have one file for every major number of gcc.
I have no strong opinion whether this approach or the approach of one file for all gcc versions is better - but with the current approach, everything else than a separate file for gcc 4 wasn't logical.

Yes it is. It's perfectly logical: gcc+ contains the "going forward" version, and until it supports some feature that isn't in all versions of gcc4, it's the right thing to do.

Quoted 6 lines

I can offer the following choices:
- please apply this compiler-gcc4.h patch
- let me send a patch merging all compiler-gcc*.h files into one compiler-gcc.h file
- let me send a patch merging all compiler-gcc*.h files back into compiler.h

No. Leave it the way it currently is until there is a *reason* to fork a gcc4 module.

This isn't a cleanup you're proposing, it's a mess-up.

-hpa

#7 lore raw
Quoted 11 lines · H. Peter Anvin
Quoted 9 lines · Adrian Bunk

As I already said in this thread:
The currently used file for gcc 4 is compiler-gcc+.h, not compiler-gcc3.h .

And the current setup is to have one file for every major number of gcc. I have no strong opinion whether this approach or the approach of one file for all gcc versions is better - but with the current approach, everything else than a separate file for gcc 4 wasn't logical.

Quoted 4 lines

Yes it is. It's perfectly logical: gcc+ contains the "going forward" version, and until it supports some feature that isn't in all versions of gcc4, it's the right thing to do.
...

It doesn't seem to be logical for everyone whether compiler-gcc+.h or compiler-gcc3.h is used for gcc 4.0 ...

Perhaps compiler-gcc+.h (which wasn't always updated when compiler-gcc3.h was updated) should be removed?

Quoted 1 line

-hpa

cu
Adrian

Signature · 4 lines
       "Is there not promise of rain?" Ling Tan asked suddenly out
        of the darkness. There had been need of rain for many days.
       "Only a promise," Lao Er said.
                                       Pearl S. Buck - Dragon Seed
#8 lore raw
Quoted 5 lines · Adrian Bunk

It doesn't seem to be logical for everyone whether compiler-gcc+.h or compiler-gcc3.h is used for gcc 4.0 ...

Perhaps compiler-gcc+.h (which wasn't always updated when compiler-gcc3.h was updated) should be removed?

That would make more sense. After all, gcc5+ can use the gcc4 file until a gcc5 file proper is created.

-hpa

#9 lore raw

RFC 1/1 Clean up and merge compiler-*.h

I set up a sample patch to clean up and merge the compiler.h files, on the basis that it's generally easier to manage all implementations of a single compiler feature in the same file right next to each other, instead of spread across 3 files. This also cleans it up and puts the __KERNEL__ stuff in a single small section at the bottom, so as not to pollute the user-space namespace. This is also a precursor to several other patches I'm working on to clean up and split out user-space available ABI from the kernel headers in include/linux to include/linux-abi.

A sample new GCC feature test:
/*
* __attribute__((__someattr__)) [GCC 3.3 or later]

 *   This will force the specified function to be inlined, or throw an
 *   error if inlining is impossible.  This is designed to be used
 *   where inlining is critical.  In the kernel, we want basically
 *   everything marked "inline" to be forced to inline, because 

otherwise
* the code is just plain wrong.
*/
#if (__GNUC__ > 3) || (__GNUC__ == 3 && __GNUC_MINOR__ >= 3)

# define __attribute_someattr__ __attribute__((__someattr__))
#else
# define __attribute_someattr__ /* unimplemented */
#endif

Index: linux-2.5/include/linux/compiler-gcc+.h

include/linux/compiler-gcc+.h renamed from include/linux/compiler-gcc+.h:1.5 +0 -16
diff -u linux-2.5/include/linux/compiler-gcc+.h:1.5 linux-2.5/include/linux/compiler-gcc+.h:removed
@@ -1,16 +0,0 @@
-/* Never include this file directly.  Include <linux/compiler.h> instead.  */
-
-/*
- * These definitions are for Ueber-GCC: always newer than the latest
- * version and hence sporting everything plus a kitchen-sink.
- */
-#include <linux/compiler-gcc.h>
-
-#define inline			inline		__attribute__((always_inline))
-#define __inline__		__inline__	__attribute__((always_inline))
-#define __inline		__inline	__attribute__((always_inline))
-#define __deprecated		__attribute__((deprecated))
-#define __attribute_used__	__attribute__((__used__))
-#define __attribute_pure__	__attribute__((pure))
-#define __attribute_const__	__attribute__((__const__))
-#define __must_check 		__attribute__((warn_unused_result))

Index: linux-2.5/include/linux/compiler-gcc.h

include/linux/compiler-gcc.h renamed from include/linux/compiler-gcc.h:1.2 +0 -17
diff -u linux-2.5/include/linux/compiler-gcc.h:1.2 linux-2.5/include/linux/compiler-gcc.h:removed
@@ -1,17 +0,0 @@
-/* Never include this file directly.  Include <linux/compiler.h> instead.  */
-
-/*
- * Common definitions for all gcc versions go here.
- */
-
-
-/* Optimization barrier */
-/* The "volatile" is due to gcc bugs */
-#define barrier() __asm__ __volatile__("": : :"memory")
-
-/* This macro obfuscates arithmetic on a variable address so that gcc
-   shouldn't recognize the original var, and make assumptions about it */
-#define RELOC_HIDE(ptr, off)					\
-  ({ unsigned long __ptr;					\
-    __asm__ ("" : "=g"(__ptr) : "0"(ptr));		\
-    (typeof(ptr)) (__ptr + (off)); })

Index: linux-2.5/include/linux/compiler-gcc2.h

include/linux/compiler-gcc2.h renamed from include/linux/compiler-gcc2.h:1.3 +0 -24
diff -u linux-2.5/include/linux/compiler-gcc2.h:1.3 linux-2.5/include/linux/compiler-gcc2.h:removed
@@ -1,24 +0,0 @@
-/* Never include this file directly.  Include <linux/compiler.h> instead.  */
-
-/* These definitions are for GCC v2.x.  */
-
-/* Somewhere in the middle of the GCC 2.96 development cycle, we implemented
-   a mechanism by which the user can annotate likely branch directions and
-   expect the blocks to be reordered appropriately.  Define __builtin_expect
-   to nothing for earlier compilers.  */
-#include <linux/compiler-gcc.h>
-
-#if __GNUC_MINOR__ < 96
-# define __builtin_expect(x, expected_value) (x)
-#endif
-
-#define __attribute_used__	__attribute__((__unused__))
-
-/*
- * The attribute `pure' is not implemented in GCC versions earlier
- * than 2.96.
- */
-#if __GNUC_MINOR__ >= 96
-# define __attribute_pure__	__attribute__((pure))
-# define __attribute_const__	__attribute__((__const__))
-#endif

Index: linux-2.5/include/linux/compiler-gcc3.h

include/linux/compiler-gcc3.h renamed from include/linux/compiler-gcc3.h:1.10 +0 -34
diff -u linux-2.5/include/linux/compiler-gcc3.h:1.10 linux-2.5/include/linux/compiler-gcc3.h:removed
@@ -1,34 +0,0 @@
-/* Never include this file directly.  Include <linux/compiler.h> instead.  */
-
-/* These definitions are for GCC v3.x.  */
-#include <linux/compiler-gcc.h>
-
-#if __GNUC_MINOR__ >= 1
-# define inline		inline		__attribute__((always_inline))
-# define __inline__	__inline__	__attribute__((always_inline))
-# define __inline	__inline	__attribute__((always_inline))
-#endif
-
-#if __GNUC_MINOR__ > 0
-# define __deprecated	__attribute__((deprecated))
-#endif
-
-#if __GNUC_MINOR__ >= 3
-# define __attribute_used__	__attribute__((__used__))
-#else
-# define __attribute_used__	__attribute__((__unused__))
-#endif
-
-#define __attribute_pure__	__attribute__((pure))
-#define __attribute_const__	__attribute__((__const__))
-
-#if __GNUC_MINOR__ >= 1
-#define  noinline __attribute__((noinline))
-#endif
-#if __GNUC_MINOR__ >= 4
-#define __must_check __attribute__((warn_unused_result))
-#endif
-
-#if __GNUC_MINOR__ >= 5
-#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
-#endif

Index: linux-2.5/include/linux/compiler-intel.h

include/linux/compiler-intel.h renamed from include/linux/compiler-intel.h:1.2 +0 -24
diff -u linux-2.5/include/linux/compiler-intel.h:1.2 linux-2.5/include/linux/compiler-intel.h:removed
@@ -1,24 +0,0 @@
-/* Never include this file directly.  Include <linux/compiler.h> instead.  */
-
-#ifdef __ECC
-
-/* Some compiler specific definitions are overwritten here
- * for Intel ECC compiler
- */
-
-#include <asm/intrinsics.h>
-
-/* Intel ECC compiler doesn't support gcc specific asm stmts.
- * It uses intrinsics to do the equivalent things.
- */
-#undef barrier
-#undef RELOC_HIDE
-
-#define barrier() __memory_barrier()
-
-#define RELOC_HIDE(ptr, off)					\
-  ({ unsigned long __ptr;					\
-     __ptr = (unsigned long) (ptr);				\
-    (typeof(ptr)) (__ptr + (off)); })
-
-#endif

Index: linux-2.5/include/linux/compiler.h

include/linux/compiler.h renamed from include/linux/compiler.h:1.38 +192 -94

340 lines not on this page · raw message

Index: linux-2.5/include/linux/stddef.h

include/linux/stddef.h renamed from include/linux/stddef.h:1.3 +0 -7
diff -u linux-2.5/include/linux/stddef.h:1.3 linux-2.5/include/linux/stddef.h:1.4
@@ -10,11 +10,4 @@
 #define NULL ((void *)0)
 #endif
 
-#undef offsetof
-#ifdef __compiler_offsetof
-#define offsetof(TYPE,MEMBER) __compiler_offsetof(TYPE,MEMBER)
-#else
-#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
-#endif
-
 #endif

Cheers,
Kyle Moffett

-----BEGIN GEEK CODE BLOCK-----
Version: 3.12
GCM/CS/IT/U d- s++: a18 C++++>$ UB/L/X/*++++(+)>$ P+++(++++)>$ L++++(+++) E W++(+) N+++(++) o? K? w--- O? M++ V? PS+() PE+(-) Y+ PGP+++ t+(+++) 5 X R? tv-(--) b++++(++) DI+ D+ G e->++++$ h!*()>++$ r !y?(-) ------END GEEK CODE BLOCK------

#10 lore raw

PATCH 1/1 add compiler-gcc4.h

In reply to H. Peter Anvin
Quoted 11 lines · H. Peter Anvin
Quoted 7 lines · Adrian Bunk

It doesn't seem to be logical for everyone whether compiler-gcc+.h or compiler-gcc3.h is used for gcc 4.0 ...

Perhaps compiler-gcc+.h (which wasn't always updated when compiler-gcc3.h was updated) should be removed?

That would make more sense. After all, gcc5+ can use the gcc4 file until a gcc5 file proper is created.

The compiler-gcc*.h files check only for __GNUC_MINOR__ but not for __GNUC__ .

Is the patch below OK?

Quoted 1 line

-hpa

cu
Adrian

<-- snip -->

With the release of gcc 4.0 being only a few months away and people already tring compiling with it, it's time for adding a compiler-gcc4.h .

This patch contains the following changes:
- remove compiler-gcc+.h
- compiler-gcc4.h: new file based on a corrected compiler-gcc+.h
- compiler.h: include compiler-gcc4.h for gcc 4
- compiler.h: #error for gcc > 4
- compiler-gcc3.h: remove __compiler_offsetof (there will never be a gcc 3.5) small indention corrections

I've tested the compilation with both gcc 3.4.4 and a recent gcc 4.0 snapshot from Debian experimental.

---

 include/linux/compiler-gcc+.h |    3 +++
 include/linux/compiler-gcc3.h |   10 ++++------
 include/linux/compiler-gcc4.h |   16 ++++++++++++++++
 include/linux/compiler.h      |    6 ++++--
 4 files changed, 27 insertions(+), 8 deletions(-)
include/linux/compiler.h renamed from include/linux/compiler.h.old +4 -2
@@ -34,8 +34,10 @@
 
 #ifdef __KERNEL__
 
-#if __GNUC__ > 3
-# include <linux/compiler-gcc+.h>	/* catch-all for GCC 4, 5, etc. */
+#if __GNUC__ > 4
+#error no compiler-gcc.h file for this gcc version
+#elif __GNUC__ == 4
+# include <linux/compiler-gcc4.h>
 #elif __GNUC__ == 3
 # include <linux/compiler-gcc3.h>
 #elif __GNUC__ == 2
include/linux/compiler-gcc3.h renamed from include/linux/compiler-gcc3.h.old +4 -6
@@ -10,7 +10,7 @@
 #endif
 
 #if __GNUC_MINOR__ > 0
-# define __deprecated	__attribute__((deprecated))
+# define __deprecated		__attribute__((deprecated))
 #endif
 
 #if __GNUC_MINOR__ >= 3
@@ -23,12 +23,10 @@
 #define __attribute_const__	__attribute__((__const__))
 
 #if __GNUC_MINOR__ >= 1
-#define  noinline __attribute__((noinline))
+#define  noinline		__attribute__((noinline))
 #endif
+
 #if __GNUC_MINOR__ >= 4
-#define __must_check __attribute__((warn_unused_result))
+#define __must_check		__attribute__((warn_unused_result))
 #endif
 
-#if __GNUC_MINOR__ >= 5
-#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
-#endif
include/linux/compiler-gcc4.h new file +16 -0
@@ -0,0 +1,16 @@
+/* Never include this file directly.  Include <linux/compiler.h> instead.  */
+
+/* These definitions are for GCC v4.x.  */
+#include <linux/compiler-gcc.h>
+
+#define inline			inline		__attribute__((always_inline))
+#define __inline__		__inline__	__attribute__((always_inline))
+#define __inline		__inline	__attribute__((always_inline))
+#define __deprecated		__attribute__((deprecated))
+#define __attribute_used__	__attribute__((__used__))
+#define __attribute_pure__	__attribute__((pure))
+#define __attribute_const__	__attribute__((__const__))
+#define  noinline		__attribute__((noinline))
+#define __must_check 		__attribute__((warn_unused_result))
+#define __compiler_offsetof(a,b) __builtin_offsetof(a,b)
+
include/linux/compiler-gcc+.h deleted +0 -16
@@ -1,16 +0,0 @@
-/* Never include this file directly.  Include <linux/compiler.h> instead.  */
-
-/*
- * These definitions are for Ueber-GCC: always newer than the latest
- * version and hence sporting everything plus a kitchen-sink.
- */
-#include <linux/compiler-gcc.h>
-
-#define inline			inline		__attribute__((always_inline))
-#define __inline__		__inline__	__attribute__((always_inline))
-#define __inline		__inline	__attribute__((always_inline))
-#define __deprecated		__attribute__((deprecated))
-#define __attribute_used__	__attribute__((__used__))
-#define __attribute_pure__	__attribute__((pure))
-#define __attribute_const__	__attribute__((__const__))
-#define __must_check 		__attribute__((warn_unused_result))