Skip to contentSkip to conversation

non-static init in a basic kernel module

DISCUSSION Warren Turkal 3 participants 3 messages Jun 9, 2014 – Jun 16, 2014

lore
Share & tools
lore
#0 lore raw

Hey,

I was writing a basic hello world module. I am using Ubuntu, so I installed linux-headers package that corresponded to my kernel. It's strange because all of the examples that I saw (including from modules in the kernel itself) show things like the following for the init function:

static int netcat_init(void)

{
     ...
     return 0;
}

module_init(netcat_init);

However, I was not able to get it to work with "static". My hello_world_init function looks like the following:

int __init hello_world_init(void)

{
     ...
     return 0;
}

module_init(hello_world_init);

The command that is used to make the kernel module is the one suggested in Documentation/kbuild/modules.txt. It looks like this:
make -C /lib/modules/uname -r/build M=$PWD

Does anyone know why the "static" version would not work?

Thanks,
wt

#1 lore raw
Quoted 24 lines · Warren Turkal

Hey,

I was writing a basic hello world module. I am using Ubuntu, so I installed linux-headers package that corresponded to my kernel. It's strange because all of the examples that I saw (including from modules in the kernel itself) show things like the following for the init function:

static int netcat_init(void)

{
     ...
     return 0;
}

module_init(netcat_init);

However, I was not able to get it to work with "static". My hello_world_init function looks like the following:

int __init hello_world_init(void)

{
     ...
     return 0;
}
Quoted 7 lines

module_init(hello_world_init);

The command that is used to make the kernel module is the one suggested in Documentation/kbuild/modules.txt. It looks like this:
make -C /lib/modules/uname -r/build M=$PWD

Does anyone know why the "static" version would not work?

What exactly were the errors you got?

#2 lore raw
In reply to Warren Turkal

Hi,

To prevent namespace pollution static is being used but this problem is nothing to do with static and you should share Error Logs to know exact problem also pointed by Greg.

Regards
Sanjeev Sharma

Quoted 39 lines · Warren Turkal

Hey,

I was writing a basic hello world module. I am using Ubuntu, so I installed linux-headers package that corresponded to my kernel. It's strange because all of the examples that I saw (including from modules in the kernel itself) show things like the following for the init function:

static int netcat_init(void)

{
     ...
     return 0;
}

module_init(netcat_init);

However, I was not able to get it to work with "static". My hello_world_init function looks like the following:

int __init hello_world_init(void)

{
     ...
     return 0;
}

module_init(hello_world_init);

The command that is used to make the kernel module is the one suggested in Documentation/kbuild/modules.txt. It looks like this:
make -C /lib/modules/uname -r/build M=$PWD

Does anyone know why the "static" version would not work?

Thanks,
wt

_______________________________________________
Kernelnewbies mailing list
Kernelnewbies at kernelnewbies.org
http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies