Skip to contentSkip to conversation

any value to numerous checks of "#ifdef __GNUC__"?

DISCUSSION Robert P. J. Day 3 participants 6 messages Apr 4, 2008 – Apr 5, 2008 Kernel janitors

lore
Share & tools
lore
#0 lore raw

there are numerous header files that contain a check of the form

    #ifdef __GNUC__

but <linux/compiler.h> already insists on a GNU C-flavoured compiler:

#if __GNUC__ >= 4

# include <linux/compiler-gcc4.h>
#elif __GNUC__ = 3 && __GNUC_MINOR__ >= 2
# include <linux/compiler-gcc3.h>
#else
# error Sorry, your compiler is too old/not recognized.
#endif

so is there any point in keeping all those checks around? is it
even remotely feasible that the kernel might someday support a non-GNU C compiler, given the numerous gcc extensions that are used?

rday
--

====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
====================================

#1 lore raw
Quoted 14 lines · Robert P. J. Day

there are numerous header files that contain a check of the form

    #ifdef __GNUC__

but <linux/compiler.h> already insists on a GNU C-flavoured compiler:

#if __GNUC__ >= 4

# include <linux/compiler-gcc4.h>
#elif __GNUC__ = 3 && __GNUC_MINOR__ >= 2
# include <linux/compiler-gcc3.h>
#else
# error Sorry, your compiler is too old/not recognized.
#endif
Quoted 7 lines

so is there any point in keeping all those checks around? is it
even remotely feasible that the kernel might someday support a non-GNU C compiler, given the numerous gcc extensions that are used?

rday
--

hi,
so far i know the intel compiler can compile a linux kernel.
ntl. this is most likely crap since the compiler is checked much more early. (or at least should).
I only reason i can think of is that this module is used in other places outside the linux kernle tree.

re,
wh

#2 lore raw
In reply to Robert P. J. Day
Quoted 19 lines · walter harms
Quoted 18 lines · Robert P. J. Day

there are numerous header files that contain a check of the form

    #ifdef __GNUC__

but <linux/compiler.h> already insists on a GNU C-flavoured compiler:

#if __GNUC__ >= 4

# include <linux/compiler-gcc4.h>
#elif __GNUC__ = 3 && __GNUC_MINOR__ >= 2
# include <linux/compiler-gcc3.h>
#else
# error Sorry, your compiler is too old/not recognized.
#endif

so is there any point in keeping all those checks around? is it
even remotely feasible that the kernel might someday support a non-GNU C compiler, given the numerous gcc extensions that are used?

Quoted 6 lines
Quoted 3 lines

rday
--

hi,
so far i know the intel compiler can compile a linux kernel.

i know, but even the intel compiler identifies itself as GNU-compatible by defining __GNUC__.

Quoted 2 lines

ntl. this is most likely crap since the compiler is checked much more early. (or at least should).

it is, as i point out above: linux/compiler.h.

Quoted 2 lines

I only reason i can think of is that this module is used in other places outside the linux kernle tree.

perhaps, but unlikely, given the amount of checking that's being done all over the place:

$ grep -r "#if.*__GNUC__" *

and, philosophically speaking, it's not clear that source in the kernel tree is responsible for being compatible for being used in environments *outside* of the tree.

i'm going to go with the position that it's crap and submit a few patches to start ripping it out.

rday
--

====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
====================================

#3 lore raw
In reply to Robert P. J. Day
Quoted 3 lines · walter harms

hi, so far i know the intel compiler can compile a linux kernel. ntl. this is most likely crap since the compiler is checked much more early. (or at least should).

actually, those checks could be reasonable for content exported to userspace, but if it's not exported, i don't see any value to those tests.

rday
--

====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
====================================

#4 lore raw
In reply to Robert P. J. Day
Quoted 3 lines · Robert P. J. Day

is it
even remotely feasible that the kernel might someday support a non-GNU C compiler, given the numerous gcc extensions that are used?

I think people are working on getting tinycc to compile an un-modified kernel, and I think LLVM is close-ish, also some BSD guys are working on PCC so it might be able to compile the kernel in the (distant?)future.

It concerns me a little that GCC is the only OSS compiler that can compile the kernel.

Darren J.

#5 lore raw
In reply to Robert P. J. Day
Quoted 6 lines · Darren Jenkins
Quoted 3 lines · Robert P. J. Day

is it even remotely feasible that the kernel might someday support a non-GNU C compiler, given the numerous gcc extensions that are used?

Quoted 7 lines

I think people are working on getting tinycc to compile an un-modified kernel, and I think LLVM is close-ish, also some BSD guys are working on PCC so it might be able to compile the kernel in the (distant?)future.

It concerns me a little that GCC is the only OSS compiler that can compile the kernel.

well, as i mentioned earlier, the intel compiler is also officially approved, but it defines __GNUC__ so it masquerades as gcc, anyway.

and, as a followup to my original question, once i looked closer, it does look like most of that "#ifdef __GNUC__" checking does get exported to userspace, quite possibly for exactly the reason darren mentions -- to support *userspace* non-gcc compilation. i'm sure there are *some* superfluous in-kernel __GNUC__ tests, but probably nowhere near as many as i first suspected.

rday
--

====================================
Robert P. J. Day
Linux Consulting, Training and Annoying Kernel Pedantry:
Have classroom, will lecture.

http://crashcourse.ca Waterloo, Ontario, CANADA
====================================