2006-11-19 12:00:38

by Olaf Hering

[permalink] [raw]
Subject: uml fails to compile due to missing offsetof


I fail to see how arch/um/sys-i386/user-offsets.c can compile since
offsetof() was declared __KERNEL__ only in include/linux/stddef.h.
Does it work for anyone else? If so, is linux/stddef.h or
/usr/include/linux/stddef.h used during compilation?
The x86_64 variant looks weird as well, linux/stddef.h is appearently
included via some other headers.


2006-11-19 14:28:31

by Jeff Dike

[permalink] [raw]
Subject: Re: uml fails to compile due to missing offsetof

On Sun, Nov 19, 2006 at 01:00:01PM +0100, Olaf Hering wrote:
>
> I fail to see how arch/um/sys-i386/user-offsets.c can compile since
> offsetof() was declared __KERNEL__ only in include/linux/stddef.h.
> Does it work for anyone else?

It obviously works for me. offsetof is very standard C. I'd venture
to say that a system which can't find it has a broken gcc installation.

> If so, is linux/stddef.h or /usr/include/linux/stddef.h used during
> compilation?

/usr/include/linux/stddef.h (but see below) - this is a userspace
file, so it builds against libc headers.

> The x86_64 variant looks weird as well, linux/stddef.h is appearently
> included via some other headers.

Well, /usr/include/linux/stddef.h on my x86_64 box has no offsetof,
despite being FC5 just like my i386 laptop. Yay for consistency.

However, there is a /usr/lib/gcc/x86_64-redhat-linux/4.1.1/include/stddef.h
which defines offsetof (and there's a corresponding file on my
laptop), so I bet that's the true source of offsetof.

Jeff
--
Work email - jdike at linux dot intel dot com

2006-11-19 15:59:39

by Olaf Hering

[permalink] [raw]
Subject: Re: uml fails to compile due to missing offsetof

On Sun, Nov 19, Jeff Dike wrote:

> On Sun, Nov 19, 2006 at 01:00:01PM +0100, Olaf Hering wrote:
> >
> > I fail to see how arch/um/sys-i386/user-offsets.c can compile since
> > offsetof() was declared __KERNEL__ only in include/linux/stddef.h.
> > Does it work for anyone else?
>
> It obviously works for me. offsetof is very standard C. I'd venture
> to say that a system which can't find it has a broken gcc installation.

How do you get _STDDEF_H defined in
/usr/lib/gcc/<target>/<vers>/include/stddef.h ?
For me _STDDEF_H remains undefined, and /usr/include/linux/stddef.h has
offsetof inside __KERNEL__.

2006-11-19 17:08:50

by Roland Dreier

[permalink] [raw]
Subject: Re: uml fails to compile due to missing offsetof

> I fail to see how arch/um/sys-i386/user-offsets.c can compile since
> offsetof() was declared __KERNEL__ only in include/linux/stddef.h.
> Does it work for anyone else? If so, is linux/stddef.h or
> /usr/include/linux/stddef.h used during compilation?
> The x86_64 variant looks weird as well, linux/stddef.h is appearently
> included via some other headers.

Yes, the

#include <linux/stddef.h>

looks weird to me. AFAIK the C standard says that offsetof() comes
from plain old <stddef.h>. Does the (untested) patch below fix the
build for you?

diff --git a/arch/um/sys-i386/user-offsets.c b/arch/um/sys-i386/user-offsets.c
index 6f4ef2b..447306b 100644
--- a/arch/um/sys-i386/user-offsets.c
+++ b/arch/um/sys-i386/user-offsets.c
@@ -2,7 +2,7 @@ #include <stdio.h>
#include <signal.h>
#include <asm/ptrace.h>
#include <asm/user.h>
-#include <linux/stddef.h>
+#include <stddef.h>
#include <sys/poll.h>

#define DEFINE(sym, val) \

2006-11-19 17:21:04

by Olaf Hering

[permalink] [raw]
Subject: Re: uml fails to compile due to missing offsetof

On Sun, Nov 19, Roland Dreier wrote:

> looks weird to me. AFAIK the C standard says that offsetof() comes
> from plain old <stddef.h>. Does the (untested) patch below fix the
> build for you?

Yes, it does.

2006-11-19 19:38:50

by Jeff Dike

[permalink] [raw]
Subject: Re: uml fails to compile due to missing offsetof

On Sun, Nov 19, 2006 at 04:58:47PM +0100, Olaf Hering wrote:
> How do you get _STDDEF_H defined in
> /usr/lib/gcc/<target>/<vers>/include/stddef.h ?
> For me _STDDEF_H remains undefined, and /usr/include/linux/stddef.h has
> offsetof inside __KERNEL__.

I guess that the __KERNEL__ is your problem. I don't see that
anything like that has any business being in the libc headers. In the
other case of this that I looked at, the stuff in /usr/include/linux/
had been replaced by (or /usr/include/linux symlinked to) a kernel
include/linux.

Jeff
--
Work email - jdike at linux dot intel dot com

2006-11-19 19:42:00

by Jeff Dike

[permalink] [raw]
Subject: Re: uml fails to compile due to missing offsetof

On Sun, Nov 19, 2006 at 09:08:47AM -0800, Roland Dreier wrote:
> looks weird to me. AFAIK the C standard says that offsetof() comes
> from plain old <stddef.h>.

Yes, sorry.

Fixed in my tree, will be send to mainline shortly.

Jeff
--
Work email - jdike at linux dot intel dot com