Commit c99f5cea authored by Rusty Russell's avatar Rusty Russell Committed by James Bottomley

[PATCH] module names fix

By Kai Germaschewski:

 "Well, I have another solution, which doesn't need additional Makefile
  magic or anything.

  I just put the module name into each .o file where <linux/module.h> is
  included. Putting it into the section .gnu.linkonce.modname has the effect
  that even for multi-part modules, we only end up with one copy of the
  name.

  Caveat: I'm using the preprocessor macro KBUILD_MODNAME to know what to
  put into .gnu.linkonce.modname. The following used to happen:

  (drivers/isdn/eicon/Makefile)

  divas-objs := common.o Divas_mod.o ...
  eicon-objs := common.o eicon_mod.o ...

  Divas_mod.o is compiled with -DKBUILD_MODNAME=divas
  eicon_mod.o is compiled with -DKBUILD_MODNAME=eicon
  common.o is compiled with -DKBUILD_MODNAME=divas_eicon

  So in the case above, both divas.o and eicon.o would end up with
  a .gnu.linkonce.modname section containing "divas_eicon"

  My fix to this is to not define KBUILD_MODNAME when compiling an object
  whilch will be linked into more than one module - so common.o gets no
  .gnu.linkonce.modname section at all. Works fine here.

  Now, doing this I remove one of the reasons why we would need modules
  linked as '.ko' ;), but it seems much cleaner than generating a temporary
  file, using objcopy etc."
parent 1504317a
...@@ -125,14 +125,6 @@ extern struct kernel_param __setup_start, __setup_end; ...@@ -125,14 +125,6 @@ extern struct kernel_param __setup_start, __setup_end;
*/ */
#define module_exit(x) __exitcall(x); #define module_exit(x) __exitcall(x);
/**
* no_module_init - code needs no initialization.
*
* The equivalent of declaring an empty init function which returns 0.
* Every module must have exactly one module_init() or no_module_init
* invocation. */
#define no_module_init
#else /* MODULE */ #else /* MODULE */
/* Don't use these in modules, but some people do... */ /* Don't use these in modules, but some people do... */
...@@ -144,11 +136,6 @@ extern struct kernel_param __setup_start, __setup_end; ...@@ -144,11 +136,6 @@ extern struct kernel_param __setup_start, __setup_end;
#define device_initcall(fn) module_init(fn) #define device_initcall(fn) module_init(fn)
#define late_initcall(fn) module_init(fn) #define late_initcall(fn) module_init(fn)
/* Each module knows its own name. */
#define __DEFINE_MODULE_NAME \
char __module_name[] __attribute__((section(".modulename"))) = \
__stringify(KBUILD_MODNAME)
/* These macros create a dummy inline: gcc 2.9x does not count alias /* These macros create a dummy inline: gcc 2.9x does not count alias
as usage, hence the `unused function' warning when __init functions as usage, hence the `unused function' warning when __init functions
are declared static. We use the dummy __*_module_inline functions are declared static. We use the dummy __*_module_inline functions
...@@ -157,13 +144,10 @@ extern struct kernel_param __setup_start, __setup_end; ...@@ -157,13 +144,10 @@ extern struct kernel_param __setup_start, __setup_end;
/* Each module must use one module_init(), or one no_module_init */ /* Each module must use one module_init(), or one no_module_init */
#define module_init(initfn) \ #define module_init(initfn) \
__DEFINE_MODULE_NAME; \
static inline initcall_t __inittest(void) \ static inline initcall_t __inittest(void) \
{ return initfn; } \ { return initfn; } \
int __initfn(void) __attribute__((alias(#initfn))); int __initfn(void) __attribute__((alias(#initfn)));
#define no_module_init __DEFINE_MODULE_NAME
/* This is only required if you want to be unloadable. */ /* This is only required if you want to be unloadable. */
#define module_exit(exitfn) \ #define module_exit(exitfn) \
static inline exitcall_t __exittest(void) \ static inline exitcall_t __exittest(void) \
......
...@@ -46,6 +46,11 @@ struct kernel_symbol ...@@ -46,6 +46,11 @@ struct kernel_symbol
#ifdef MODULE #ifdef MODULE
#ifdef KBUILD_MODNAME
static const char __module_name[MODULE_NAME_LEN] __attribute__((section(".gnu.linkonce.modname"))) = \
__stringify(KBUILD_MODNAME);
#endif
/* For replacement modutils, use an alias not a pointer. */ /* For replacement modutils, use an alias not a pointer. */
#define MODULE_GENERIC_TABLE(gtype,name) \ #define MODULE_GENERIC_TABLE(gtype,name) \
static const unsigned long __module_##gtype##_size \ static const unsigned long __module_##gtype##_size \
...@@ -315,12 +320,7 @@ extern int module_dummy_usage; ...@@ -315,12 +320,7 @@ extern int module_dummy_usage;
/* Old-style "I'll just call it init_module and it'll be run at /* Old-style "I'll just call it init_module and it'll be run at
insert". Use module_init(myroutine) instead. */ insert". Use module_init(myroutine) instead. */
#ifdef MODULE #ifdef MODULE
/* Used as "int init_module(void) { ... }". Get funky to insert modname. */ #define init_module(voidarg) __initfn(void)
#define init_module(voidarg) \
__initfn(void); \
char __module_name[] __attribute__((section(".modulename"))) = \
__stringify(KBUILD_MODNAME); \
int __initfn(void)
#define cleanup_module(voidarg) __exitfn(void) #define cleanup_module(voidarg) __exitfn(void)
#endif #endif
......
...@@ -867,8 +867,8 @@ static struct module *load_module(void *umod, ...@@ -867,8 +867,8 @@ static struct module *load_module(void *umod,
/* Internal symbols */ /* Internal symbols */
DEBUGP("Symbol table in section %u\n", i); DEBUGP("Symbol table in section %u\n", i);
symindex = i; symindex = i;
} else if (strcmp(secstrings+sechdrs[i].sh_name, ".modulename") } else if (strcmp(secstrings+sechdrs[i].sh_name,
== 0) { ".gnu.linkonce.modname") == 0) {
/* This module's name */ /* This module's name */
DEBUGP("Module name in section %u\n", i); DEBUGP("Module name in section %u\n", i);
modnameindex = i; modnameindex = i;
......
...@@ -19,5 +19,3 @@ EXPORT_SYMBOL(zlib_deflateReset); ...@@ -19,5 +19,3 @@ EXPORT_SYMBOL(zlib_deflateReset);
EXPORT_SYMBOL(zlib_deflateCopy); EXPORT_SYMBOL(zlib_deflateCopy);
EXPORT_SYMBOL(zlib_deflateParams); EXPORT_SYMBOL(zlib_deflateParams);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
no_module_init;
...@@ -20,5 +20,3 @@ EXPORT_SYMBOL(zlib_inflateReset); ...@@ -20,5 +20,3 @@ EXPORT_SYMBOL(zlib_inflateReset);
EXPORT_SYMBOL(zlib_inflateSyncPoint); EXPORT_SYMBOL(zlib_inflateSyncPoint);
EXPORT_SYMBOL(zlib_inflateIncomp); EXPORT_SYMBOL(zlib_inflateIncomp);
MODULE_LICENSE("GPL"); MODULE_LICENSE("GPL");
no_module_init;
...@@ -124,14 +124,14 @@ depfile = $(subst $(comma),_,$(@D)/.$(@F).d) ...@@ -124,14 +124,14 @@ depfile = $(subst $(comma),_,$(@D)/.$(@F).d)
# than one module. In that case KBUILD_MODNAME will be set to foo_bar, # than one module. In that case KBUILD_MODNAME will be set to foo_bar,
# where foo and bar are the name of the modules. # where foo and bar are the name of the modules.
basename_flags = -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F))) basename_flags = -DKBUILD_BASENAME=$(subst $(comma),_,$(subst -,_,$(*F)))
modname_flags = -DKBUILD_MODNAME=$(subst $(comma),_,$(subst -,_,$(modname))) modname_flags = $(if $(filter 1,$(words $(modname))),-DKBUILD_MODNAME=$(subst $(comma),_,$(subst -,_,$(modname))))
c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \ c_flags = -Wp,-MD,$(depfile) $(CFLAGS) $(NOSTDINC_FLAGS) \
$(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \ $(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \
$(basename_flags) $(modname_flags) $(export_flags) $(basename_flags) $(modname_flags) $(export_flags)
# Finds the multi-part object the current object will be linked into # Finds the multi-part object the current object will be linked into
modname-multi = $(subst $(space),_,$(sort $(foreach m,$(multi-used),\ modname-multi = $(sort $(foreach m,$(multi-used),\
$(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))) $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))
# Shipped files # Shipped files
# =========================================================================== # ===========================================================================
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment