tags:

views:

102

answers:

3

Hello,

I'm trying to use llvm-gcc (llvm version 1.7) to compile a driver program (linux/drivers/net/zorro8390.c) in the linux kernel source code (version 2.6.18.8) for research purpose, but I get a lot of errors from the jiffies.h:

bash-3.2$ llvm-gcc -D__GNUCC -E -I../../include zorro8390.c -o test.o
In file included from ../../include/linux/lockdep.h:12,
                 from ../../include/linux/spinlock_types.h:12,
                 from ../../include/linux/spinlock.h:78,
                 from ../../include/linux/module.h:10,
                 from zorro8390.c:22:
../../include/linux/list.h:887:2: warning: #warning "don't include kernel headers in userspace"
In file included from zorro8390.c:30:
../../include/linux/jiffies.h:210:31: error: division by zero in #if
../../include/linux/jiffies.h:210:31: error: division by zero in #if
...(a bunch of same errors)
../../include/linux/jiffies.h:432:28: error: division by zero in #if

I've googled lots of discussions on this error, but lots of them are about building kernel with make command. I still don't know how to fix it when using llvm-gcc directly. Any suggestion on it? Thank you very much for your help!

Daniel

+1  A: 

You're almost certainly getting this error because you haven't defined some of the many things that need to be defined on the command line when compiling Linux kernel source files by hand. This message is also a tip-off:

linux/list.h:887:2: warning: #warning "don't include kernel headers in userspace"

You should do a normal build of the kernel with V=1 on the make command line, log the output to a file, and dig out the line for zorro8390.c -- that will tell you the additional -D switches you need. There may be others necessary as well (-I, -include, etc).

Zack
A: 

Zack: Thank you very much for your fast response! I'll try to do that.

viraptor: Thank you for your help for modifying the output!

Daniel

Daniel
Don't add commentary like this as an answer - SO isn't a bulletin board. Use comments ("add comment" under each question or answer) instead.
caf
A: 

jiffies are the internal clock ticks of the kernel and depend on a define called HZ which iirc is the number of jiffies/second. This would typically be a configuration constant (I remember it once went from 100 to 1024, maybe nowadays it's more). And HZ is typically used in divisions, hence the div/0 errors.

So these are the problems @Zack rightly refers to; you don't have the config defines etc. But you could try and define HZ (or what it's called today) and see if you can make it work.

mvds