public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] warning: `__attribute_used__' redefined
@ 2004-02-10  6:39 Jeff Chua
  2004-02-10  6:53 ` Andrew Morton
  0 siblings, 1 reply; 10+ messages in thread
From: Jeff Chua @ 2004-02-10  6:39 UTC (permalink / raw)
  To: Linus Torvalds, Andrew Morton; +Cc: Linux Kernel



Linus, Andrew,

Here's a small fix for linux 2.6.3-rc2 to get rid of the annoying warnings
while non-kernel programs ...

/usr/include/linux/compiler-gcc2.h:15: warning: `__attribute_used__' redefined
/usr/include/sys/cdefs.h:170: warning: this is the location of the previous definition


Thanks,
Jeff


--- linux-2.6.2/include/linux/compiler-gcc2.h	Wed Feb  4 11:45:02 2004
+++ linux-2.6.3-rc2/include/linux/compiler-gcc2.h	Tue Feb 10 14:30:04 2004
@@ -12,6 +12,10 @@
 # define __builtin_expect(x, expected_value) (x)
 #endif

+#ifdef __attribute_used__
+#undef __attribute_used__
+#endif
+
 #define __attribute_used__	__attribute__((__unused__))

 /*

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] warning: `__attribute_used__' redefined
  2004-02-10  6:39 [PATCH] warning: `__attribute_used__' redefined Jeff Chua
@ 2004-02-10  6:53 ` Andrew Morton
  2004-02-10 13:59   ` Jeff Chua
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2004-02-10  6:53 UTC (permalink / raw)
  To: Jeff Chua; +Cc: torvalds, linux-kernel

Jeff Chua <jeffchua@silk.corp.fedex.com> wrote:
>
> Here's a small fix for linux 2.6.3-rc2 to get rid of the annoying warnings
>  while non-kernel programs ...
> 
>  /usr/include/linux/compiler-gcc2.h:15: warning: `__attribute_used__' redefined
>  /usr/include/sys/cdefs.h:170: warning: this is the location of the previous definition

It is more likely that we need to extend the __KERNEL__ coverage somewhere.

Can you please do a `gcc -H' of that application and show us the inclusion
route by which it is hitting compiler.h?


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] warning: `__attribute_used__' redefined
  2004-02-10  6:53 ` Andrew Morton
@ 2004-02-10 13:59   ` Jeff Chua
  2004-02-10 16:25     ` Andrew Morton
  0 siblings, 1 reply; 10+ messages in thread
From: Jeff Chua @ 2004-02-10 13:59 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Chua, torvalds, Linux Kernel

On Mon, 9 Feb 2004, Andrew Morton wrote:

> It is more likely that we need to extend the __KERNEL__ coverage somewhere.
>
> Can you please do a `gcc -H' of that application and show us the inclusion
> route by which it is hitting compiler.h?

Andrew,

Here's the sample "sig.c". Just compile with "cc sig.c"



#include <signal.h>	/* signal */
#include <stdio.h>	/* printf */

void action(int signum);

int main(int argc, char *argv[])
{
	int i;
	for(i = 1; i < 31; i++) {
		if(i == 9 || i == 19)
			continue;

		signal(i, action);
	}
}

void action(int signum)
{
	printf("%d\n", signum);
}




Here's output of "gcc -H sig.c" gcc 2.95.3  glibc 2.2.5  linux 2.6.3-rc2


/usr/include/signal.h
 /usr/include/features.h
  /usr/include/sys/cdefs.h
  /usr/include/gnu/stubs.h
 /usr/include/bits/sigset.h
 /usr/include/bits/types.h
  /usr/lib/gcc-lib/i586-pc-linux-gnu/2.95.3/include/stddef.h
  /usr/include/bits/pthreadtypes.h
   /usr/include/bits/sched.h
 /usr/include/bits/signum.h
 /usr/include/time.h
 /usr/include/bits/siginfo.h
  /usr/include/bits/wordsize.h
 /usr/include/bits/sigaction.h
 /usr/include/bits/sigcontext.h
  /usr/include/asm/sigcontext.h
   /usr/include/linux/compiler.h
    /usr/include/linux/compiler-gcc2.h
     /usr/include/linux/compiler-gcc.h
In file included from /usr/include/linux/compiler.h:18,
                 from /usr/include/asm/sigcontext.h:4,
                 from /usr/include/bits/sigcontext.h:28,
                 from /usr/include/signal.h:307,
                 from sig.c:1:
/usr/include/linux/compiler-gcc2.h:21: warning: `__attribute_used__' redefined
/usr/include/sys/cdefs.h:170: warning: this is the location of the previous definition
 /usr/include/bits/sigstack.h
 /usr/include/bits/sigthread.h
/usr/include/stdio.h
 /usr/lib/gcc-lib/i586-pc-linux-gnu/2.95.3/include/stddef.h
 /usr/include/libio.h
  /usr/include/_G_config.h
   /usr/lib/gcc-lib/i586-pc-linux-gnu/2.95.3/include/stddef.h
   /usr/include/wchar.h
    /usr/lib/gcc-lib/i586-pc-linux-gnu/2.95.3/include/stddef.h
    /usr/include/bits/wchar.h
   /usr/include/gconv.h
    /usr/include/wchar.h
     /usr/lib/gcc-lib/i586-pc-linux-gnu/2.95.3/include/stddef.h
    /usr/lib/gcc-lib/i586-pc-linux-gnu/2.95.3/include/stddef.h
  /usr/lib/gcc-lib/i586-pc-linux-gnu/2.95.3/include/stdarg.h
 /usr/include/bits/stdio_lim.h


Thanks,
Jeff



^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] warning: `__attribute_used__' redefined
  2004-02-10 13:59   ` Jeff Chua
@ 2004-02-10 16:25     ` Andrew Morton
  2004-02-10 16:31       ` Linus Torvalds
  0 siblings, 1 reply; 10+ messages in thread
From: Andrew Morton @ 2004-02-10 16:25 UTC (permalink / raw)
  To: Jeff Chua; +Cc: jeffchua, torvalds, linux-kernel

Jeff Chua <jchua@fedex.com> wrote:
>
> ...
> Here's output of "gcc -H sig.c" gcc 2.95.3  glibc 2.2.5  linux 2.6.3-rc2
> 
> 
> /usr/include/signal.h
>  /usr/include/features.h
>   /usr/include/sys/cdefs.h
>   /usr/include/gnu/stubs.h
>  /usr/include/bits/sigset.h
>  /usr/include/bits/types.h
>   /usr/lib/gcc-lib/i586-pc-linux-gnu/2.95.3/include/stddef.h
>   /usr/include/bits/pthreadtypes.h
>    /usr/include/bits/sched.h
>  /usr/include/bits/signum.h
>  /usr/include/time.h
>  /usr/include/bits/siginfo.h
>   /usr/include/bits/wordsize.h
>  /usr/include/bits/sigaction.h
>  /usr/include/bits/sigcontext.h
>   /usr/include/asm/sigcontext.h
>    /usr/include/linux/compiler.h
>     /usr/include/linux/compiler-gcc2.h
>      /usr/include/linux/compiler-gcc.h
> In file included from /usr/include/linux/compiler.h:18,
>                  from /usr/include/asm/sigcontext.h:4,
>                  from /usr/include/bits/sigcontext.h:28,
>                  from /usr/include/signal.h:307,
>                  from sig.c:1:
> /usr/include/linux/compiler-gcc2.h:21: warning: `__attribute_used__' redefined

ah, thanks.

Like this?

--- 25/include/asm-i386/sigcontext.h~sigcontext-include-fix	2004-02-10 08:23:47.000000000 -0800
+++ 25-akpm/include/asm-i386/sigcontext.h	2004-02-10 08:24:18.000000000 -0800
@@ -1,7 +1,9 @@
 #ifndef _ASMi386_SIGCONTEXT_H
 #define _ASMi386_SIGCONTEXT_H
 
+#ifdef __KERNEL__
 #include <linux/compiler.h>
+#endif
 
 /*
  * As documented in the iBCS2 standard..

_


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] warning: `__attribute_used__' redefined
  2004-02-10 16:25     ` Andrew Morton
@ 2004-02-10 16:31       ` Linus Torvalds
  2004-02-10 17:10         ` Daniel Jacobowitz
                           ` (2 more replies)
  0 siblings, 3 replies; 10+ messages in thread
From: Linus Torvalds @ 2004-02-10 16:31 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Jeff Chua, jeffchua, linux-kernel



On Tue, 10 Feb 2004, Andrew Morton wrote:
> 
> ah, thanks.
> 
> Like this?

That will just break. The reason for the "compiler.h" include is the 
"__user" part of fpstate, so now you'll get a parse error later if 
non-kernel code includes this.

So the rule should still be: don't include kernel headers from user 
programs. But if it's needed for some reason, that #ifdef needs to be 
somewhere else (inside "compiler.h" or something).

		Linus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] warning: `__attribute_used__' redefined
  2004-02-10 16:31       ` Linus Torvalds
@ 2004-02-10 17:10         ` Daniel Jacobowitz
  2004-02-10 17:18           ` Linus Torvalds
  2004-02-10 17:28           ` Valdis.Kletnieks
  2004-02-10 17:37         ` Andrew Morton
  2004-02-11 13:07         ` Jeff Chua
  2 siblings, 2 replies; 10+ messages in thread
From: Daniel Jacobowitz @ 2004-02-10 17:10 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Andrew Morton, Jeff Chua, jeffchua, linux-kernel

On Tue, Feb 10, 2004 at 08:31:24AM -0800, Linus Torvalds wrote:
> 
> 
> On Tue, 10 Feb 2004, Andrew Morton wrote:
> > 
> > ah, thanks.
> > 
> > Like this?
> 
> That will just break. The reason for the "compiler.h" include is the 
> "__user" part of fpstate, so now you'll get a parse error later if 
> non-kernel code includes this.
> 
> So the rule should still be: don't include kernel headers from user 
> programs. But if it's needed for some reason, that #ifdef needs to be 
> somewhere else (inside "compiler.h" or something).

This is what Debian has been using.  I believe the other folks with a
glibc-kernel-headers package based on 2.6 do something similar.  I
don't know how you'll feel about adding this sort of crap to the
kernel, though.  Someone else needs to find time to start linuxabi
moving again...

--- include/linux/compiler.h	2003-10-15 11:13:09.000000000 -0400
+++ include/linux/compiler.h.t	2003-11-01 18:04:19.000000000 -0500
@@ -9,6 +9,15 @@
 # define __kernel
 #endif
 
+#if !defined(__KERNEL__)
+/* Debian: Most of these are inappropriate for userspace.  */
+/* We don't define likely, unlikely, or barrier; they're namespace-intrusive
+   and should not be needed outside of __KERNEL__.  For __attribute_pure__
+   and __attribute_used__ we use glibc's definitions.  */
+# include <sys/cdefs.h>
+# define __deprecated
+#else
+
 #if __GNUC__ > 3
 # include <linux/compiler-gcc+.h>	/* catch-all for GCC 4, 5, etc. */
 #elif __GNUC__ == 3
@@ -86,4 +95,6 @@
     (typeof(ptr)) (__ptr + (off)); })
 #endif
 
+#endif /* __KERNEL__ */
+
 #endif /* __LINUX_COMPILER_H */

-- 
Daniel Jacobowitz
MontaVista Software                         Debian GNU/Linux Developer

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] warning: `__attribute_used__' redefined
  2004-02-10 17:10         ` Daniel Jacobowitz
@ 2004-02-10 17:18           ` Linus Torvalds
  2004-02-10 17:28           ` Valdis.Kletnieks
  1 sibling, 0 replies; 10+ messages in thread
From: Linus Torvalds @ 2004-02-10 17:18 UTC (permalink / raw)
  To: Daniel Jacobowitz; +Cc: Andrew Morton, Jeff Chua, jeffchua, linux-kernel



On Tue, 10 Feb 2004, Daniel Jacobowitz wrote:
> 
> This is what Debian has been using.  I believe the other folks with a
> glibc-kernel-headers package based on 2.6 do something similar.  I
> don't know how you'll feel about adding this sort of crap to the
> kernel, though.  Someone else needs to find time to start linuxabi
> moving again...

I don't mind adding a few __KERNEL__ checks, but no I don't want code like 
this:

> +#if !defined(__KERNEL__)
> +/* Debian: Most of these are inappropriate for userspace.  */
> +/* We don't define likely, unlikely, or barrier; they're namespace-intrusive
> +   and should not be needed outside of __KERNEL__.  For __attribute_pure__
> +   and __attribute_used__ we use glibc's definitions.  */
> +# include <sys/cdefs.h>
> +# define __deprecated
> +#else

that is completely glibc-dependent and has no meaning in a kernel header 
file.

In general, anything that uses most of the kernel special magic defines
(__deprecated, __inline__, etc) probably should be inside #ifdef
__KERNEL__ anyway, so the kernel <linux/compiler.h> file should not need 
to define them. 

There are a few cases that look special, just because they touch data
structures that are actually visible to user space. That would be things
like "__packed__" and "__user" etc, which are used to tell something about 
the data structure.

So right now I just added a "#ifdef __KERNEL__" around the special parts, 
and did _not_ do the part about. We can add a few more #ifdef's around 
something else that breaks, but in general I feel that this is up to 
whoever merges the headers into user space.

		Linus

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] warning: `__attribute_used__' redefined
  2004-02-10 17:10         ` Daniel Jacobowitz
  2004-02-10 17:18           ` Linus Torvalds
@ 2004-02-10 17:28           ` Valdis.Kletnieks
  1 sibling, 0 replies; 10+ messages in thread
From: Valdis.Kletnieks @ 2004-02-10 17:28 UTC (permalink / raw)
  To: Daniel Jacobowitz
  Cc: Linus Torvalds, Andrew Morton, Jeff Chua, jeffchua, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 805 bytes --]

On Tue, 10 Feb 2004 12:10:55 EST, Daniel Jacobowitz said:

> This is what Debian has been using.  I believe the other folks with a
> glibc-kernel-headers package based on 2.6 do something similar.  I
> don't know how you'll feel about adding this sort of crap to the

I found this in the Fedora linux-2.6.0-compile.patch included in their
kernel-2.6.1-1.65.src.rpm.  A bit more hard-line. :)

Anybody want to push it for the Linus or -mm trees? ;)

--- linux-2.6.0-test11/include/linux/config.h~  2003-12-11 09:29:14.090625985 +0100
+++ linux-2.6.0-test11/include/linux/config.h   2003-12-11 09:29:14.090625985 +0100
@@ -2,5 +2,7 @@
 #define _LINUX_CONFIG_H
 
 #include <linux/autoconf.h>
-
+#ifndef __KERNEL__
+#error including kernel header in userspace; use the glibc headers instead!
+#endif
 #endif


[-- Attachment #2: Type: application/pgp-signature, Size: 226 bytes --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] warning: `__attribute_used__' redefined
  2004-02-10 16:31       ` Linus Torvalds
  2004-02-10 17:10         ` Daniel Jacobowitz
@ 2004-02-10 17:37         ` Andrew Morton
  2004-02-11 13:07         ` Jeff Chua
  2 siblings, 0 replies; 10+ messages in thread
From: Andrew Morton @ 2004-02-10 17:37 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: jeffchua, linux-kernel

Linus Torvalds <torvalds@osdl.org> wrote:
>
> So the rule should still be: don't include kernel headers from user 
>  programs. 

Yup.  I generally take the position that we should fix up things which used
to work, but which 2.6 broke.  Usually that is the only thing which people
care about anyway...


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH] warning: `__attribute_used__' redefined
  2004-02-10 16:31       ` Linus Torvalds
  2004-02-10 17:10         ` Daniel Jacobowitz
  2004-02-10 17:37         ` Andrew Morton
@ 2004-02-11 13:07         ` Jeff Chua
  2 siblings, 0 replies; 10+ messages in thread
From: Jeff Chua @ 2004-02-11 13:07 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: Andrew Morton, Jeff Chua, Jeff Chua, Linux Kernel

On Tue, 10 Feb 2004, Linus Torvalds wrote:

> On Tue, 10 Feb 2004, Andrew Morton wrote:
> > ah, thanks.
> > Like this?
> That will just break. The reason for the "compiler.h" include is the
> "__user" part of fpstate, so now you'll get a parse error later if
> non-kernel code includes this.
>
> So the rule should still be: don't include kernel headers from user
> programs. But if it's needed for some reason, that #ifdef needs to be
> somewhere else (inside "compiler.h" or something).

So, what's wrong with the patch I posted earlier. I've verified that it
works with just one place to patch, and that makes all warnings went away.

Patch attached here again.

Thanks,
Jeff

--- linux-2.6.2/include/linux/compiler-gcc2.h	Wed Feb  4 11:45:02 2004
+++ linux-2.6.3-rc2/include/linux/compiler-gcc2.h	Tue Feb 10 14:30:04 2004
@@ -12,6 +12,10 @@
 # define __builtin_expect(x, expected_value) (x)
 #endif

+#ifdef __attribute_used__
+#undef __attribute_used__
+#endif
+
 #define __attribute_used__	__attribute__((__unused__))

 /*

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2004-02-11 13:07 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-02-10  6:39 [PATCH] warning: `__attribute_used__' redefined Jeff Chua
2004-02-10  6:53 ` Andrew Morton
2004-02-10 13:59   ` Jeff Chua
2004-02-10 16:25     ` Andrew Morton
2004-02-10 16:31       ` Linus Torvalds
2004-02-10 17:10         ` Daniel Jacobowitz
2004-02-10 17:18           ` Linus Torvalds
2004-02-10 17:28           ` Valdis.Kletnieks
2004-02-10 17:37         ` Andrew Morton
2004-02-11 13:07         ` Jeff Chua

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox