Я набрал следующий код:
#include <linux/init.h>
#include <linux/module.h>
#include <linux/kernel.h>
MODULE_LICENSE("GPL");
static int test_init(void) {
printk(KERN_ALERT"Hello!\n");
return 0;
}
static void test_exit(void) {
printk(KERN_ALERT"End!\n");
}
module_init(test_init);
module_init(test_exit);
obj-m += hello.o
make -C /usr/src/linux-headers-`uname -r` SUBDIRS=$PWD modules
make: Entering directory '/usr/src/linux-headers-4.10.0-28-generic'
CC [M] /home/vasya/gcc/kernel/hello.o
In file included from /home/vasya/gcc/kernel/hello.c:2:0:
./include/linux/module.h:130:27: error: redefinition of ‘__inittest’
static inline initcall_t __inittest(void) \
^
/home/vasya/gcc/kernel/hello.c:13:1: note: in expansion of macro ‘module_init’
module_init(test_exit);
^
./include/linux/module.h:130:27: note: previous definition of ‘__inittest’ was here
static inline initcall_t __inittest(void) \
^
/home/vasya/gcc/kernel/hello.c:12:1: note: in expansion of macro ‘module_init’
module_init(test_init);
^
/home/vasya/gcc/kernel/hello.c: In function ‘__inittest’:
/home/vasya/gcc/kernel/hello.c:13:13: error: return from incompatible pointer type [-Werror=incompatible-pointer-types]
module_init(test_exit);
^
./include/linux/module.h:131:11: note: in definition of macro ‘module_init’
{ return initfn; } \
^
/home/vasya/gcc/kernel/hello.c: At top level:
./include/linux/module.h:132:6: error: redefinition of ‘init_module’
int init_module(void) __attribute__((alias(#initfn)));
^
/home/vasya/gcc/kernel/hello.c:13:1: note: in expansion of macro ‘module_init’
module_init(test_exit);
^
./include/linux/module.h:132:6: note: previous definition of ‘init_module’ was here
int init_module(void) __attribute__((alias(#initfn)));
^
/home/vasya/gcc/kernel/hello.c:12:1: note: in expansion of macro ‘module_init’
module_init(test_init);
^
cc1: some warnings being treated as errors
scripts/Makefile.build:301: recipe for target '/home/vasya/gcc/kernel/hello.o' failed
make[1]: *** [/home/vasya/gcc/kernel/hello.o] Error 1
Makefile:1524: recipe for target '_module_/home/vasya/gcc/kernel' failed
make: *** [_module_/home/vasya/gcc/kernel] Error 2
make: Leaving directory '/usr/src/linux-headers-4.10.0-28-generic'