Skip to contentSkip to conversation

PROBLEM: please remove reserved word "new" from kernel headers

DISCUSSION Rob Prowel 9 participants 9 messages Jul 6, 2005 – Jul 7, 2005 Kbuild

lore
Share & tools
lore

Rob Prowel

author
#0 lore raw

[1.] One line summary of the problem:

2.4 and 2.6 kernel headers use c++ reserved word "new" as identifier in function prototypes.

[2.] Full description of the problem/report:

When kernel headers are included in compilation of c++ programs the compile fails because some header files use "new" in a way that is illegal for c++. This shows up when compiling mySQL under linux 2.6. It uses $KERNELSOURCE/include/asm-i386/system.h.

[3.] Keywords (i.e., modules, networking, kernel):

new, c++, kernel headers

[4.] Kernel version (from /proc/version):

2.4 and 2.6

While not an error, per se, it is kind of sloppy and it is amazing that it hasn't shown up before now. using the identifier "new" in kernel headers that are visible to applications programs is a bad idea.

Thanks,
Rob Prowel

____________________________________________________
Sell on Yahoo! Auctions – no fees. Bid on great items.
http://auctions.yahoo.com/

#1 lore raw
Quoted 5 lines · Rob Prowel

[1.] One line summary of the problem:

2.4 and 2.6 kernel headers use c++ reserved word "new" as identifier in function prototypes.

This is a FAQ.

1) kernel headers are for kernel use.
2) the kernel is written in C, not C++.
3) if userspace needs those headers, write your own based on the kernel headers.

Do you really think you're the first to notice this since it exists in 2.4 headers?

Good luck,
Jurriaan

#3 lore raw
Quoted 10 lines · Alexey Dobriyan
Quoted 5 lines · Rob Prowel

When kernel headers are included in compilation of c++ programs the compile fails because some header files use "new" in a way that is illegal for c++. This shows up when compiling mySQL under linux 2.6. It uses $KERNELSOURCE/include/asm-i386/system.h.

Please read http://marc.theaimsgroup.com/?t=111637777000001&r=2&w=2
where people discuss this brokeness of MySQL.

Just for kicks, see if this 'fixes' it. Then contact the MySQL people and complain.

usr/src/linux-2.6.12/include/asm-i386/system.h renamed from usr/src/linux-2.6.12/include/asm-i386/system.h.orig +5 -5
@@ -235,7 +235,7 @@
 
 /*
  * Atomic compare and exchange.  Compare OLD with MEM, if identical,
- * store NEW in MEM.  Return the initial value in MEM.  Success is
+ * store New in MEM.  Return the initial value in MEM.  Success is
  * indicated by comparing RETURN with OLD.
  */
 
@@ -244,26 +244,26 @@
 #endif
 
 static inline unsigned long __cmpxchg(volatile void *ptr, unsigned long old,
-				      unsigned long new, int size)
+				      unsigned long New, int size)
 {
 	unsigned long prev;
 	switch (size) {
 	case 1:
 		__asm__ __volatile__(LOCK_PREFIX "cmpxchgb %b1,%2"
 				     : "=a"(prev)
-				     : "q"(new), "m"(*__xg(ptr)), "0"(old)
+				     : "q"(New), "m"(*__xg(ptr)), "0"(old)
 				     : "memory");
 		return prev;
 	case 2:
 		__asm__ __volatile__(LOCK_PREFIX "cmpxchgw %w1,%2"
 				     : "=a"(prev)
-				     : "q"(new), "m"(*__xg(ptr)), "0"(old)
+				     : "q"(New), "m"(*__xg(ptr)), "0"(old)
 				     : "memory");
 		return prev;
 	case 4:
 		__asm__ __volatile__(LOCK_PREFIX "cmpxchgl %1,%2"
 				     : "=a"(prev)
-				     : "q"(new), "m"(*__xg(ptr)), "0"(old)
+				     : "q"(New), "m"(*__xg(ptr)), "0"(old)
 				     : "memory");
 		return prev;
 	}

Cheers,
Dick Johnson
Penguin : Linux version 2.6.12 on an i686 machine (5537.79 BogoMips).
Notice : All mail here is now cached for review by Dictator Bush.
98.36% of all statistics are fiction.

#4 lore raw
In reply to Rob Prowel
Quoted 5 lines · Rob Prowel

[1.] One line summary of the problem:

2.4 and 2.6 kernel headers use c++ reserved word "new" as identifier in function prototypes.

"new" is not a reserved word in C. the kernel is written in C.

Quoted 5 lines

[2.] Full description of the problem/report:

When kernel headers are included in compilation of c++ programs the compile fails because some header files use "new" in a way that is illegal for c++.

Userspace programs should not include kernel headers directly.

But, if you really want it changed I suggest you create a patch and submit that for review/inclusion and see what feedback you get.

Signature · 3 lines
Jesper Juhl <[email protected]>
Don't top-post  http://www.catb.org/~esr/jargon/html/T/top-post.html
Plain text mails only, please      http://www.expita.com/nomime.html
#5 lore raw
In reply to Rob Prowel
Quoted 4 lines · Rob Prowel

While not an error, per se, it is kind of sloppy and it is amazing that it hasn't shown up before now. using the identifier "new" in kernel headers that are visible to applications programs is a bad idea.

It _is_ an error, on mysql's part. The kernel headers are _not_ intended to be visible to applications, in the general case. Why is mysql including this header?

Signature · 1 line
dwmw2
#6 lore raw
In reply to Rob Prowel
Quoted 4 lines · Rob Prowel

[1.] One line summary of the problem:

2.4 and 2.6 kernel headers use c++ reserved word "new" as identifier in function prototypes.

Correction:

[1.] One line summary of problem:

Userspace application is making use of private kernel headers.

Quoted 8 lines

[2.] Full description of the problem/report:

When kernel headers are included in compilation of c++ programs the compile fails because some header files use "new" in a way that is illegal for c++. This shows up when compiling mySQL under linux 2.6. It uses $KERNELSOURCE/include/asm-i386/system.h.

Corrected:

[2.] Full description of the problem/report:

When userspace applications include headers they shouldn't, all kinds of problems can appear. One example of this shows up when compiling mySQL under linux 2.6. It uses $KERNELSOURCE/include/asm-i386/system.h.

...

Quoted 2 lines

While not an error, per se, it is kind of sloppy and it is amazing that it hasn't shown up before now.

It has shown up, and it has been discussed. Search the archives. I'm pretty sure the exact problem you're reporting was discussed here a few months back.

Quoted 2 lines

using the identifier "new" in kernel headers that are visible to applications programs is a bad idea.

Noone's doing that. Because the headers aren't meant to be visible.

This is not a C vs. C++ problem and it has nothing to do with 'sloppiness'. Something much subtler could have happened had it been C application code which would have parsed cleanly but just broken in strange ways (due to assumptions in kernel header code which just happen to not be met in the userspace code). Actually, you should be greatful someone used 'new' - at least now the error is caught at compile time ;)

It should be simple to fix MySQL to keep it's dirty little fingers off of the kernel's private parts..

Really, that is the solution.

Take a look at *what* MySQL is doing with the header. If it is the same problem (I have not double checked, but I guess chances are good) as was reported earlier, it's really just a small braindamage in MySQL which is easily fixed (thus removing the need for inclusion of the header in question).

Signature · 1 line
 / jakob
#7 lore raw
In reply to Rob Prowel
Quoted 4 lines · Rob Prowel

[1.] One line summary of the problem:

2.4 and 2.6 kernel headers use c++ reserved word "new" as identifier in function prototypes.

Yes, the kernel is written in C, not C++.

Quoted 2 lines

using the identifier "new" in kernel headers that are visible to applications programs is a bad idea.

Programs are not supposed to include kernel headers. This is a FAQ, see the archives.

Michal

#8 lore raw
In reply to Rob Prowel
Quoted 7 lines · Rob Prowel

2.4 and 2.6 kernel headers use c++ reserved word "new" as identifier in function prototypes.
[...]
While not an error, per se, it is kind of sloppy and it is amazing that it hasn't shown up before now. using the identifier "new" in kernel headers that are visible to applications programs is a bad idea.

This has been discussed before: see
http://marc.theaimsgroup.com/?l=linux-kernel&m=111637766131104&w=2 and the ensuing thread.

Signature · 1 line
schnee