From 35bc6f3f8db6a6412fcb6fb9a251a1083094ca47 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 29 Dec 2002 01:47:53 -0800 Subject: [PATCH] Embed __this_module in module itself. Rather than have the module loader the module structure and resolve the symbols __this_module to it, make __this_module a real structure inside the module, using the linkonce trick we used for module names. This saves us an allocation (saving a page per module on archs which need the module structure close by), and means we don't have to fill in a few module fields. --- include/linux/init.h | 5 ++--- include/linux/module.h | 34 ++++++++++++++++++---------------- 2 files changed, 20 insertions(+), 19 deletions(-) (limited to 'include') diff --git a/include/linux/init.h b/include/linux/init.h index 46b1ef190c52..b7c6363478aa 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -147,14 +147,13 @@ struct obs_kernel_param { #define module_init(initfn) \ static inline initcall_t __inittest(void) \ { return initfn; } \ - int __initfn(void) __attribute__((alias(#initfn))); + int init_module(void) __attribute__((alias(#initfn))); /* This is only required if you want to be unloadable. */ #define module_exit(exitfn) \ static inline exitcall_t __exittest(void) \ { return exitfn; } \ - void __exitfn(void) __attribute__((alias(#exitfn))); - + void cleanup_module(void) __attribute__((alias(#exitfn))); #define __setup(str,func) /* nothing */ #endif diff --git a/include/linux/module.h b/include/linux/module.h index c033488d6eeb..3a411c8c6575 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -40,12 +40,11 @@ struct kernel_symbol char name[MODULE_NAME_LEN]; }; -#ifdef MODULE +/* These are either module local, or the kernel's dummy ones. */ +extern int init_module(void); +extern void cleanup_module(void); -#ifdef KBUILD_MODNAME -static const char __module_name[MODULE_NAME_LEN] __attribute__((section(".gnu.linkonce.modname"))) = \ - __stringify(KBUILD_MODNAME); -#endif +#ifdef MODULE /* For replacement modutils, use an alias not a pointer. */ #define MODULE_GENERIC_TABLE(gtype,name) \ @@ -56,9 +55,6 @@ static const struct gtype##_id * __module_##gtype##_table \ extern const struct gtype##_id __mod_##gtype##_table \ __attribute__ ((unused, alias(__stringify(name)))) -/* This is magically filled in by the linker, but THIS_MODULE must be - a constant so it works in initializers. */ -extern struct module __this_module; #define THIS_MODULE (&__this_module) #else /* !MODULE */ @@ -176,7 +172,7 @@ struct module /* The command line arguments (may be mangled). People like keeping pointers to this stuff */ - char args[0]; + char *args; }; /* FIXME: It'd be nice to isolate modules during init, too, so they @@ -289,6 +285,19 @@ static inline const char *module_address_lookup(unsigned long addr, } #endif /* CONFIG_MODULES */ +#if defined(MODULE) && defined(KBUILD_MODNAME) +/* We make the linker do some of the work. */ +struct module __this_module +__attribute__((section(".gnu.linkonce.this_module"))) = { + .name = __stringify(KBUILD_MODNAME), + .symbols = { .owner = &__this_module }, + .init = init_module, +#ifdef CONFIG_MODULE_UNLOAD + .exit = cleanup_module, +#endif +}; +#endif /* MODULE && KBUILD_MODNAME */ + /* For archs to search exception tables */ extern struct list_head extables; extern spinlock_t modlist_lock; @@ -360,13 +369,6 @@ extern int module_dummy_usage; && __mod_between((p),(n),(m)->module_init,(m)->init_size)) \ || __mod_between((p),(n),(m)->module_core,(m)->core_size)) -/* Old-style "I'll just call it init_module and it'll be run at - insert". Use module_init(myroutine) instead. */ -#ifdef MODULE -#define init_module(voidarg) __initfn(void) -#define cleanup_module(voidarg) __exitfn(void) -#endif - /* * The exception and symbol tables, and the lock * to protect them. -- cgit v1.2.3