Bug 76569 - incompilable with cc -D__KERNEL__ -DMODULE with module.h
incompilable with cc -D__KERNEL__ -DMODULE with module.h
Status: CLOSED NOTABUG
Product: Red Hat Linux
Classification: Retired
Component: glibc-kernheaders (Show other bugs)
7.3
i386 Linux
medium Severity medium
: ---
: ---
Assigned To: Arjan van de Ven
Brian Brock
:
: 76571 (view as bug list)
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2002-10-23 11:26 EDT by Need Real Name
Modified: 2007-04-18 12:47 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2002-10-23 11:26:27 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Need Real Name 2002-10-23 11:26:20 EDT
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)

Description of problem:
When I compile simple module device driver programs in C with cc -D__KERNEL__ -
DMODULE option, the cc always return erras in line 60, 62, and 91 in module.h 
at least, then reject to go on; I tried three simple sample programs from books 
<<Linux Device Driver>>, <<Embedded Linux>>, and <Practical Linux Programming>> 
respectively, I get the same returning messages.

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1.copy one of the following three set of module program and its makefile into 
your i386-PC:
  1.1 from <<Practical Linux Programming>>
    1.1.1 makefile:
INCLUDEDIR = /usr/include
DEBFLAGS = -O2
CFLAGS = -D__KERNEL__ -DMODULE -Wall $(DEBFLAGS)
CFLAGS += -I$(INCLUDEDIR)
OBJS = pport.o
all: $(OBJS)

     1.1.2 pport.c:  
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/fs.h>     /* everything... */

int major = 0;

struct file_operations fops = {
NULL,          /* lseek */
NULL,          /* read */
NULL,          /* write */
NULL,          /* readdir */
NULL,			 /* poll */
NULL,          /* ioctl */
NULL,          /* mmap */
NULL,          /* open */
NULL,			 /* flush */
NULL,          /* release */
NULL,          /* fsync */
NULL,          /* fasync */
NULL,			 /* check_media_change */
NULL, 			 /* revalidate */
NULL,	       /* lock */
};

int init_module(void)
{

   major = register_chrdev(0, "pport", &fops);
   return 0;
}

void cleanup_module(void)
{
   unregister_chrdev(major, "pport");
}

  1.2 from <<Linux Device Drivers>>@2001 website:
       examples:
      faulty.c and Makefile in misc-module folder:
      1.2.1 Makefile:
# Comment/uncomment the following line to enable/disable debugging
#DEBUG = y

# Change it here or specify it on the "make" commandline
INCLUDEDIR = /usr/include

ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DJIT_DEBUG -DJIQ_DEBUG -DALL_DEBUG
else
  DEBFLAGS = -O2
endif

CFLAGS = -D__KERNEL__ -DMODULE -Wall $(DEBFLAGS)


CFLAGS += -I$(INCLUDEDIR)

# first the portable ones, then those that need newer kernel versions
# this way everything compilable is built under 1.2 before getting errors
OBJS = faulty.o sleepy.o silly.o slave.o slaveD.o slaveH.o import.o \
	master.o export.o hello.o \
	jit.o jiq.o 


all: $(OBJS)

clean:
	rm -f *.o *.ver *~ 

# Don't use -Wall here: the cose is silly by design
hello.o: hello.c
	$(CC) -D__KERNEL__ -c $^ -o $@

# set MODVERSIONS if the kernel uses it
VERSUSED = $(shell grep 'define CONFIG_MODVERSIONS' \
                   $(INCLUDEDIR)/linux/autoconf.h | wc -l | sed 's/ //g')
ifeq ($(VERSUSED),1)
  MODVERSIONS = y
endif

# and then use it
ifdef MODVERSIONS
export.o import.o: export.ver
endif

export.ver: export.c
	$(CC) -I$(INCLUDEDIR) -E -D__GENKSYMS__ $^ | genksyms > $@


      1.2.3 faulty.c:
/*
 * faulty.c -- a module which generates an oopswhen read
 *
 * Tested with 1.2 on the x86
 * Tested with 2.0 on the x86, Sparc
 *
 */

#ifndef __KERNEL__
#  define __KERNEL__
#endif
#ifndef MODULE
#  define MODULE
#endif

#define __NO_VERSION__ /* don't define kernel_verion in module.h */
#include <linux/module.h>
#include <linux/version.h>

char kernel_version [] = UTS_RELEASE;

#include <linux/kernel.h> /* printk() */
#include <linux/fs.h>     /* everything... */
#include <linux/types.h>  /* size_t */
#include <asm/segment.h>

#include "sysdep.h" /* count_t for portability 2.0/2.1 */

int faulty_major=0;

char faulty_buf[1024];

read_write_t faulty_read (struct inode *inode, struct file *filp,
                char *buf, count_t count)
{
  printk(KERN_DEBUG "read: inode %p, file %p, buf %p, count %li\n",
         inode, filp, buf, (long)count);
  memcpy_tofs(buf,faulty_buf,count);
  return count;
}
struct pio {int a; char b; long c;};

read_write_t faulty_write (struct inode *inode, struct file *filp,
               const char *buf, count_t count)
{
    /* put_user(0,(struct pio *)buf);*/
    return 0;
}


struct file_operations faulty_fops = {
    NULL,          /* lseek */
    faulty_read,
    faulty_write,
                   /* nothing more, fill with NULLs */
};


int init_module(void)
{
    int result;

    /*
     * Register your major, and accept a dynamic number
     */
    result = register_chrdev(faulty_major, "faulty", &faulty_fops);
    if (result < 0) return result;
    if (faulty_major == 0) faulty_major = result; /* dynamic */

    /* 
     * allocate the devices -- we can't have them static, as the number
     * can be specified at load time
     */
    return 0;
}

void cleanup_module(void)
{
    unregister_chrdev(faulty_major, "faulty");
}



  1.3 from <<Embedded Linux>>@2002 website:
      www.embeddedlinuxinterfacing.com/chapters/7, sample:
      hello_proc_module.c and cc -D__KERNEL__ -DMODULE ...
 
2.run command "make" where the copied programs are
3.You will see returned messages like below in section Actual results:

Actual Results:  stop compiling and return erra message as the attached
s at the end of the bug-report.

Expected Results:  pass through the "make" cc compilation and get pport.o.

Additional info:

Makefiles without option -D__KERNEL__ -DMODULE for a non-module/driver
/kernel C program are ok, now.
Comment 1 Arjan van de Ven 2002-10-23 13:52:50 EDT
INCLUDEDIR = /usr/include
that is wrong
you are trying to compile a kernel modules without using kernel headers but by
using glibc headers!

the kernel headers are in /lib/modules/`uname -r`/build/include
Comment 2 Arjan van de Ven 2002-10-23 13:53:21 EDT
*** Bug 76571 has been marked as a duplicate of this bug. ***
Comment 3 Need Real Name 2002-10-24 10:23:59 EDT
Redhat 7.3 lib for kernel seems not compatible with its 7.0/7.1 version.

What changes has the redhat liunx 7.3 made for the lib from 7.0/7.1?
At the end of this comment attached are copies of new returned message from
your suggested header and lib on my machine, its makefile "makefile1".
 

The author of <<Practical Linux Programming>>, ASHFAQ A. KHAH, told me
that he success testing these programs on Redhat 7.0/7.1 without using
a bugfix patch. His email:akhan@aklinux.com; his email to me:

" The code was tested with Red Hat 7.0 and 7.1.
The user is trying to compile the code for
RedHat Version 7.3. I need to install 7.3 and
test it again. It may take some time.

Sincerely,
Ash "


=============New returned message and makefile1==================
1. makefile1:
#INCLUDEDIR = /usr/include
#INCLUDEDIR = /lib/modules/'uname -r'/include
INCLUDEDIR = /usr/src/linux-2.4.18-3/include
DEBFLAGS = -O2
CFLAGS = -D__KERNEL__ -DMODULE -Wall $(DEBFLAGS)
CFLAGS += -I$(INCLUDEDIR)
OBJS = pport.o
all: $(OBJS)

2. new returned message:
[root@mdoggy refbkplp:363]# make -f makefile1
cc -D__KERNEL__ -DMODULE -Wall -02 -I/usr/src/linux-2.4.18-3/include   -c -o 
pport.o pport.c
cc: unrecognized option `-02'
pport.c:6: `null' undeclared here (not in a function)
pport.c:6: initializer element is not constant
pport.c:6: (near initialization for `fops.owner')
pport.c:7: `null' undeclared here (not in a function)
pport.c:7: initializer element is not constant
pport.c:7: (near initialization for `fops.llseek')
pport.c:8: `null' undeclared here (not in a function)
pport.c:8: initializer element is not constant
pport.c:8: (near initialization for `fops.read')
pport.c:9: `null' undeclared here (not in a function)
pport.c:9: initializer element is not constant
pport.c:9: (near initialization for `fops.write')
pport.c:10: `null' undeclared here (not in a function)
pport.c:10: initializer element is not constant
pport.c:10: (near initialization for `fops.readdir')
pport.c:11: `null' undeclared here (not in a function)
pport.c:11: initializer element is not constant
pport.c:11: (near initialization for `fops.poll')
pport.c:12: `null' undeclared here (not in a function)
pport.c:12: initializer element is not constant
pport.c:12: (near initialization for `fops.ioctl')
pport.c:13: `null' undeclared here (not in a function)
pport.c:13: initializer element is not constant
pport.c:13: (near initialization for `fops.mmap')
pport.c:14: `null' undeclared here (not in a function)
pport.c:14: initializer element is not constant
pport.c:14: (near initialization for `fops.open')
pport.c:15: `null' undeclared here (not in a function)
pport.c:15: initializer element is not constant
pport.c:15: (near initialization for `fops.flush')
pport.c:16: `null' undeclared here (not in a function)
pport.c:16: initializer element is not constant
pport.c:16: (near initialization for `fops.release')
pport.c:17: `null' undeclared here (not in a function)
pport.c:17: initializer element is not constant
pport.c:17: (near initialization for `fops.fsync')
pport.c:18: `null' undeclared here (not in a function)
pport.c:18: initializer element is not constant
pport.c:18: (near initialization for `fops.fasync')
pport.c:19: `null' undeclared here (not in a function)
pport.c:19: initializer element is not constant
pport.c:19: (near initialization for `fops.lock')
pport.c:20: `null' undeclared here (not in a function)
pport.c:20: initializer element is not constant
pport.c:20: (near initialization for `fops.readv')
make: *** [pport.o] Error 1
[root@mdoggy refbkplp:364]# ls
Makefile  makefile2  mkf0  pport.c
[root@mdoggy refbkplp:365]#
Comment 4 Arjan van de Ven 2002-10-24 10:28:38 EDT
#ifndef __KERNEL__
#  define __KERNEL__
#endif
#ifndef MODULE
#  define MODULE
#endif
is bullshit btw and not needed at all

also -O2 is dash oh two (eg the letter O not the number zero)
and null is spelled NULL with capitals

Comment 5 Need Real Name 2002-10-25 19:21:47 EDT
Great! now it's OK! Thank you very much.

Note You need to log in before you can comment on or make changes to this bug.