Skip to contentSkip to conversation

basic module bug

DISCUSSION Bob McElrath 2 participants 6 messages Aug 25, 2001

lore
Share & tools
lore
#0 lore raw

What's wrong with this minimal module?

    /* test module */
    #ifndef __KERNEL__
    #define __KERNEL__
    #ifndef MODULE
    #define MODULE
    #endif
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <linux/malloc.h>
    #ifdef MODULE
    int init_module(void)
    #else
    int test_init(void)
    #endif
    {
            return 0;
    }
    #ifdef MODULE
    void cleanup_module(void)
    {
    }
    #endif
    #endif

both egcs 2.91.66 and redhat's gcc 2.96-85 barf on it:

In file included from /usr/src/linux/include/asm/semaphore.h:11,

                 from /usr/src/linux/include/linux/fs.h:198,
                 from /usr/src/linux/include/linux/capability.h:17,
                 from /usr/src/linux/include/linux/binfmts.h:5,
                 from /usr/src/linux/include/linux/sched.h:9,
                 from /usr/src/linux/include/linux/mm.h:4,
                 from /usr/src/linux/include/linux/slab.h:14,
                 from /usr/src/linux/include/linux/malloc.h:4,
                 from test.c:11:

/usr/src/linux/include/asm/current.h:4: global register variable follows a function definition /usr/src/linux/include/asm/current.h:4: warning: call-clobbered register used for global register variable

What have I done wrong?

Thanks,
-- Bob

Bob McElrath ([email protected]) Univ. of Wisconsin at Madison, Department of Physics

#1 lore raw

Hello.

On Sat, 25 Aug 2001 00:59:57 -0500
Bob McElrath <[email protected]> wrote:

BM> both egcs 2.91.66 and redhat's gcc 2.96-85 barf on it:

BM> In file included from /usr/src/linux/include/asm/semaphore.h:11, BM> from /usr/src/linux/include/linux/fs.h:198,
<...>
BM> used for global register variable

BM> What have I done wrong?

How do you compile this module?
I've just trying to do this with the following command and all is OK:
gcc ./test.c -c -o ./test.o -D__KERNEL__ -DMODULE.

BM> Thanks,
BM> -- Bob

---
WBR. //s0mbre

#2 lore raw
In reply to Bob McElrath
Quoted 12 lines · Evgeny Polyakov [[email protected]] wrote:

Hello.

On Sat, 25 Aug 2001 00:59:57 -0500
Bob McElrath <[email protected]> wrote:

BM> both egcs 2.91.66 and redhat's gcc 2.96-85 barf on it:

BM> In file included from /usr/src/linux/include/asm/semaphore.h:11, BM> from /usr/src/linux/include/linux/fs.h:198,
<...>
BM> used for global register variable

Quoted 5 lines

BM> What have I done wrong?

How do you compile this module?
I've just trying to do this with the following command and all is OK:
gcc ./test.c -c -o ./test.o -D__KERNEL__ -DMODULE.

That's because if you -D__KERNEL__ the whole file is ifdef'ed out. ;)

Remove the #ifdef __KERNEL__ stuff if you want to compile it that way.

Quoted 5 lines

BM> Thanks,
BM> -- Bob

---
WBR. //s0mbre

-- Bob

Bob McElrath ([email protected]) Univ. of Wisconsin at Madison, Department of Physics

#3 lore raw
In reply to Bob McElrath

Also I don't know if I mentioned this is on the alpha architecture. I've tried egcs 2.91.66, gcc-2.96-85 (redhat), binutils-2.10.91.0.2-3. All kernel versions I've tried (2.4.4, 2.4.5, 2.4.7, 2.4.9, 2.2.19) generate the same message. What am I doing wrong?

Where can I find a "skeleton" kernel module for comparison?

Quoted 8 lines · Bob McElrath [[email protected]] wrote:
Quoted 3 lines · Evgeny Polyakov [[email protected]] wrote:

How do you compile this module?
I've just trying to do this with the following command and all is OK:
gcc ./test.c -c -o ./test.o -D__KERNEL__ -DMODULE.

That's because if you -D__KERNEL__ the whole file is ifdef'ed out. ;)

Remove the #ifdef __KERNEL__ stuff if you want to compile it that way.

Here's a simpler case more compatible with the options passed to gcc when the kernel is compiled:

    /* test module.  Compile with: gcc -c -I/usr/src/linux/include
     * -D__KERNEL__ -DMODULE test.c  */
    #include <linux/module.h>
    #include <linux/kernel.h>
    #include <asm/current.h>
    #ifdef MODULE
     int init_module(void)
    #else
     int test_init(void)
    #endif
     {
             return 0;
     }
    #ifdef MODULE
     void cleanup_module(void)
     {
     }
    #endif

(0)<mcelrath@draal:/home/mcelrath> gcc -c -I/usr/src/linux/include -D__KERNEL__ -DMODULE test.c In file included from test.c:5:
/usr/src/linux/include/asm/current.h:4: warning: call-clobbered register used for global register variable

Yet a simpler case:

    #include <asm/current.h>
    int main() {}

Generates the same warning message. Why does this message not occur when compiling the kernel?

Cheers,
-- Bob

Bob McElrath ([email protected]) Univ. of Wisconsin at Madison, Department of Physics

#4 lore raw

Hello.

On Sat, 25 Aug 2001 10:56:45 -0500
Bob McElrath <[email protected]> wrote:

BM> Where can I find a "skeleton" kernel module for comparison?

You wrote it some strins below.

BM> Here's a simpler case more compatible with the options passed to gcc BM> when the kernel is compiled:

BM> /* test module. Compile with: gcc -c -I/usr/src/linux/include BM> * -D__KERNEL__ -DMODULE test.c */
BM> #include <linux/module.h>
BM> #include <linux/kernel.h>
BM> #include <asm/current.h>
BM> #ifdef MODULE
BM> int init_module(void)
BM> #else
BM> int test_init(void)
BM> #endif
BM> {
BM> return 0;
BM> }
BM> #ifdef MODULE
BM> void cleanup_module(void)
BM> {
BM> }
BM> #endif

BM> (0)<mcelrath@draal:/home/mcelrath> gcc -c -I/usr/src/linux/include -D__KERNEL__
BM> -DMODULE test.c
BM> In file included from test.c:5:
BM> /usr/src/linux/include/asm/current.h:4: warning: call-clobbered register
BM> used for global register variable

[s0mbre@Sombre /tmp]$ gcc ./test.c -c -o ./test.o -D__KERNEL__ -DMODULE -I/usr/src/linux/include
[s0mbre@Sombre /tmp]$

All is OK.

BM> Yet a simpler case:

BM> #include <asm/current.h>
BM> int main() {}

[s0mbre@Sombre /tmp]$ gcc ./test1.c -o ./test1
[s0mbre@Sombre /tmp]$ cat ./test1.c
#include <asm/current.h>
int main()

        {}

[s0mbre@Sombre /tmp]$

BM> Generates the same warning message. Why does this message not occur BM> when compiling the kernel?

I have no problem.
But if i would have this problem, i
a) rewrite include dir and check symlink
b) reinstall system :)

BM> Cheers,
BM> -- Bob

---
WBR. //s0mbre

#5 lore raw
In reply to Bob McElrath
Quoted 8 lines · Evgeny Polyakov [[email protected]] wrote:

Hello.

On Sat, 25 Aug 2001 10:56:45 -0500
Bob McElrath <[email protected]> wrote:

BM> Where can I find a "skeleton" kernel module for comparison?

You wrote it some strins below.

Aha! It was caused by not passing the right compiler options. There are some compiler options (CFLAGS) in arch/{arch}/Makefile that should be included for modules, and some in the top level Makefile.

Cheers,
-- Bob

Bob McElrath ([email protected]) Univ. of Wisconsin at Madison, Department of Physics