From 1929e8b2a804ea760ef1dba27f26d62d6236dd65 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 1 Dec 2002 02:12:36 -0800 Subject: [PATCH] kallsyms in modules fix Two fixes. Firstly, set ALLOC on the right section so we actually keep the symbol names and don't deref a freed section, and secondly get the symbol size (more) correct. --- kernel/module.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'kernel/module.c') diff --git a/kernel/module.c b/kernel/module.c index f9ee37c95dbe..9ee9bf6411ad 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -892,7 +892,7 @@ static struct module *load_module(void *umod, } #ifdef CONFIG_KALLSYMS /* symbol and string tables for decoding later. */ - if (sechdrs[i].sh_type == SHT_SYMTAB || i == hdr->e_shstrndx) + if (sechdrs[i].sh_type == SHT_SYMTAB || i == strindex) sechdrs[i].sh_flags |= SHF_ALLOC; #endif #ifndef CONFIG_MODULE_UNLOAD @@ -1165,7 +1165,14 @@ static const char *get_ksymbol(struct module *mod, unsigned long *size, unsigned long *offset) { - unsigned int i, next = 0, best = 0; + unsigned int i, best = 0; + unsigned long nextval; + + /* At worse, next value is at end of module */ + if (inside_core(mod, addr)) + nextval = (unsigned long)mod->module_core+mod->core_size; + else + nextval = (unsigned long)mod->module_init+mod->init_size; /* Scan for closest preceeding symbol, and next symbol. (ELF starts real symbols at 1). */ @@ -1177,22 +1184,14 @@ static const char *get_ksymbol(struct module *mod, && mod->symtab[i].st_value > mod->symtab[best].st_value) best = i; if (mod->symtab[i].st_value > addr - && mod->symtab[i].st_value < mod->symtab[next].st_value) - next = i; + && mod->symtab[i].st_value < nextval) + nextval = mod->symtab[i].st_value; } if (!best) return NULL; - if (!next) { - /* Last symbol? It ends at the end of the module then. */ - if (inside_core(mod, addr)) - *size = mod->module_core+mod->core_size - (void*)addr; - else - *size = mod->module_init+mod->init_size - (void*)addr; - } else - *size = mod->symtab[next].st_value - addr; - + *size = nextval - mod->symtab[best].st_value; *offset = addr - mod->symtab[best].st_value; return mod->strtab + mod->symtab[best].st_name; } -- cgit v1.2.3 From 1504317a0d85ff9cbf729d9d4ff3886aacc7a695 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 1 Dec 2002 02:12:47 -0800 Subject: [PATCH] v850 support On the v850, the elf toolchain uses a `_' prefix for all user symbols (I'm not sure why, since most toolchains seem to have dropped this sort of thing). The attached patch adds the ability to deal with this, if the macro MODULE_SYMBOL_PREFIX is defined by . This only affects places where symbol names come from the user, e.g., EXPORT_SYMBOL, or the explicit symbol-names used in kernel/module.c itself. [Tweaked a little by Rusty, original by Miles Bader] --- include/linux/module.h | 11 ++++++++--- kernel/module.c | 9 ++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) (limited to 'kernel/module.c') diff --git a/include/linux/module.h b/include/linux/module.h index 24389ac2db19..7729a4e10fb9 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -32,6 +32,11 @@ #define MODULE_PARM_DESC(var,desc) #define print_modules() +/* v850 toolchain uses a `_' prefix for all user symbols */ +#ifndef MODULE_SYMBOL_PREFIX +#define MODULE_SYMBOL_PREFIX "" +#endif + #define MODULE_NAME_LEN (64 - sizeof(unsigned long)) struct kernel_symbol { @@ -90,13 +95,13 @@ struct exception_table /* Get/put a kernel symbol (calls must be symmetric) */ void *__symbol_get(const char *symbol); void *__symbol_get_gpl(const char *symbol); -#define symbol_get(x) ((typeof(&x))(__symbol_get(#x))) +#define symbol_get(x) ((typeof(&x))(__symbol_get(MODULE_SYMBOL_PREFIX #x))) /* For every exported symbol, place a struct in the __ksymtab section */ #define EXPORT_SYMBOL(sym) \ const struct kernel_symbol __ksymtab_##sym \ __attribute__((section("__ksymtab"))) \ - = { (unsigned long)&sym, #sym } + = { (unsigned long)&sym, MODULE_SYMBOL_PREFIX #sym } #define EXPORT_SYMBOL_NOVERS(sym) EXPORT_SYMBOL(sym) #define EXPORT_SYMBOL_GPL(sym) EXPORT_SYMBOL(sym) @@ -170,7 +175,7 @@ struct module #ifdef CONFIG_MODULE_UNLOAD void __symbol_put(const char *symbol); -#define symbol_put(x) __symbol_put(#x) +#define symbol_put(x) __symbol_put(MODULE_SYMBOL_PREFIX #x) void symbol_put_addr(void *addr); /* We only need protection against local interrupts. */ diff --git a/kernel/module.c b/kernel/module.c index 9ee9bf6411ad..712f780d6be1 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -37,6 +37,9 @@ #define DEBUGP(fmt , a...) #endif +#define symbol_is(literal, string) \ + (strcmp(MODULE_SYMBOL_PREFIX literal, (string)) == 0) + /* List of modules, protected by module_mutex */ static DECLARE_MUTEX(module_mutex); LIST_HEAD(modules); /* FIXME: Accessed w/o lock on oops by some archs */ @@ -630,10 +633,10 @@ static int grab_private_symbols(Elf_Shdr *sechdrs, unsigned int i; for (i = 1; i < sechdrs[symbolsec].sh_size/sizeof(*sym); i++) { - if (strcmp("__initfn", strtab + sym[i].st_name) == 0) + if (symbol_is("__initfn", strtab + sym[i].st_name)) mod->init = (void *)sym[i].st_value; #ifdef CONFIG_MODULE_UNLOAD - if (strcmp("__exitfn", strtab + sym[i].st_name) == 0) + if (symbol_is("__exitfn", strtab + sym[i].st_name)) mod->exit = (void *)sym[i].st_value; #endif } @@ -770,7 +773,7 @@ static void simplify_symbols(Elf_Shdr *sechdrs, mod, &ksg); /* We fake up "__this_module" */ - if (strcmp(strtab+sym[i].st_name, "__this_module")==0) + if (symbol_is("__this_module", strtab+sym[i].st_name)) sym[i].st_value = (unsigned long)mod; } } -- cgit v1.2.3 From c99f5cea7036f066e9cdefade80a85f0c4f13d93 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Sun, 1 Dec 2002 02:15:26 -0800 Subject: [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 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." --- include/linux/init.h | 16 ---------------- include/linux/module.h | 12 ++++++------ kernel/module.c | 4 ++-- lib/zlib_deflate/deflate_syms.c | 2 -- lib/zlib_inflate/inflate_syms.c | 2 -- scripts/Makefile.lib | 6 +++--- 6 files changed, 11 insertions(+), 31 deletions(-) (limited to 'kernel/module.c') diff --git a/include/linux/init.h b/include/linux/init.h index 52db706d0ed0..e2bf29a635bf 100644 --- a/include/linux/init.h +++ b/include/linux/init.h @@ -125,14 +125,6 @@ extern struct kernel_param __setup_start, __setup_end; */ #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 */ /* Don't use these in modules, but some people do... */ @@ -144,11 +136,6 @@ extern struct kernel_param __setup_start, __setup_end; #define device_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 as usage, hence the `unused function' warning when __init functions are declared static. We use the dummy __*_module_inline functions @@ -157,13 +144,10 @@ extern struct kernel_param __setup_start, __setup_end; /* Each module must use one module_init(), or one no_module_init */ #define module_init(initfn) \ - __DEFINE_MODULE_NAME; \ static inline initcall_t __inittest(void) \ { return initfn; } \ int __initfn(void) __attribute__((alias(#initfn))); -#define no_module_init __DEFINE_MODULE_NAME - /* This is only required if you want to be unloadable. */ #define module_exit(exitfn) \ static inline exitcall_t __exittest(void) \ diff --git a/include/linux/module.h b/include/linux/module.h index 7729a4e10fb9..0362a206ccd9 100644 --- a/include/linux/module.h +++ b/include/linux/module.h @@ -46,6 +46,11 @@ struct kernel_symbol #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. */ #define MODULE_GENERIC_TABLE(gtype,name) \ static const unsigned long __module_##gtype##_size \ @@ -315,12 +320,7 @@ extern int module_dummy_usage; /* Old-style "I'll just call it init_module and it'll be run at insert". Use module_init(myroutine) instead. */ #ifdef MODULE -/* Used as "int init_module(void) { ... }". Get funky to insert modname. */ -#define init_module(voidarg) \ - __initfn(void); \ - char __module_name[] __attribute__((section(".modulename"))) = \ - __stringify(KBUILD_MODNAME); \ - int __initfn(void) +#define init_module(voidarg) __initfn(void) #define cleanup_module(voidarg) __exitfn(void) #endif diff --git a/kernel/module.c b/kernel/module.c index 712f780d6be1..a30c32e38e23 100644 --- a/kernel/module.c +++ b/kernel/module.c @@ -867,8 +867,8 @@ static struct module *load_module(void *umod, /* Internal symbols */ DEBUGP("Symbol table in section %u\n", i); symindex = i; - } else if (strcmp(secstrings+sechdrs[i].sh_name, ".modulename") - == 0) { + } else if (strcmp(secstrings+sechdrs[i].sh_name, + ".gnu.linkonce.modname") == 0) { /* This module's name */ DEBUGP("Module name in section %u\n", i); modnameindex = i; diff --git a/lib/zlib_deflate/deflate_syms.c b/lib/zlib_deflate/deflate_syms.c index 080fa4166f28..5985b28c8e30 100644 --- a/lib/zlib_deflate/deflate_syms.c +++ b/lib/zlib_deflate/deflate_syms.c @@ -19,5 +19,3 @@ EXPORT_SYMBOL(zlib_deflateReset); EXPORT_SYMBOL(zlib_deflateCopy); EXPORT_SYMBOL(zlib_deflateParams); MODULE_LICENSE("GPL"); - -no_module_init; diff --git a/lib/zlib_inflate/inflate_syms.c b/lib/zlib_inflate/inflate_syms.c index 7b8f309350a2..aa1b08189121 100644 --- a/lib/zlib_inflate/inflate_syms.c +++ b/lib/zlib_inflate/inflate_syms.c @@ -20,5 +20,3 @@ EXPORT_SYMBOL(zlib_inflateReset); EXPORT_SYMBOL(zlib_inflateSyncPoint); EXPORT_SYMBOL(zlib_inflateIncomp); MODULE_LICENSE("GPL"); - -no_module_init; diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index 95026d841a1c..c8e1528aae55 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -124,14 +124,14 @@ depfile = $(subst $(comma),_,$(@D)/.$(@F).d) # than one module. In that case KBUILD_MODNAME will be set to foo_bar, # where foo and bar are the name of the modules. 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) \ $(modkern_cflags) $(EXTRA_CFLAGS) $(CFLAGS_$(*F).o) \ $(basename_flags) $(modname_flags) $(export_flags) # Finds the multi-part object the current object will be linked into -modname-multi = $(subst $(space),_,$(sort $(foreach m,$(multi-used),\ - $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=))))) +modname-multi = $(sort $(foreach m,$(multi-used),\ + $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) # Shipped files # =========================================================================== -- cgit v1.2.3