Shrink struct module: CONFIG_UNUSED_SYMBOLS ifdefs

module.c and module.h conatains code for finding
exported symbols which are declared with EXPORT_UNUSED_SYMBOL,
and this code is compiled in even if CONFIG_UNUSED_SYMBOLS is not set
and thus there can be no EXPORT_UNUSED_SYMBOLs in modules anyway
(because EXPORT_UNUSED_SYMBOL(x) are compiled out to nothing then).

This patch adds required #ifdefs.

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Denys Vlasenko 2008-07-22 19:24:26 -05:00 committed by Rusty Russell
parent af5406895a
commit f7f5b67557
3 changed files with 38 additions and 17 deletions

View file

@ -257,6 +257,7 @@ struct module
const struct kernel_symbol *gpl_syms; const struct kernel_symbol *gpl_syms;
const unsigned long *gpl_crcs; const unsigned long *gpl_crcs;
#ifdef CONFIG_UNUSED_SYMBOLS
/* unused exported symbols. */ /* unused exported symbols. */
const struct kernel_symbol *unused_syms; const struct kernel_symbol *unused_syms;
const unsigned long *unused_crcs; const unsigned long *unused_crcs;
@ -266,6 +267,7 @@ struct module
unsigned int num_unused_gpl_syms; unsigned int num_unused_gpl_syms;
const struct kernel_symbol *unused_gpl_syms; const struct kernel_symbol *unused_gpl_syms;
const unsigned long *unused_gpl_crcs; const unsigned long *unused_gpl_crcs;
#endif
/* symbols that will be GPL-only in the near future. */ /* symbols that will be GPL-only in the near future. */
const struct kernel_symbol *gpl_future_syms; const struct kernel_symbol *gpl_future_syms;

View file

@ -856,8 +856,8 @@ config MODULE_UNLOAD
help help
Without this option you will not be able to unload any Without this option you will not be able to unload any
modules (note that some modules may not be unloadable modules (note that some modules may not be unloadable
anyway), which makes your kernel slightly smaller and anyway), which makes your kernel smaller, faster
simpler. If unsure, say Y. and simpler. If unsure, say Y.
config MODULE_FORCE_UNLOAD config MODULE_FORCE_UNLOAD
bool "Forced module unloading" bool "Forced module unloading"

View file

@ -134,17 +134,19 @@ extern const struct kernel_symbol __start___ksymtab_gpl[];
extern const struct kernel_symbol __stop___ksymtab_gpl[]; extern const struct kernel_symbol __stop___ksymtab_gpl[];
extern const struct kernel_symbol __start___ksymtab_gpl_future[]; extern const struct kernel_symbol __start___ksymtab_gpl_future[];
extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
extern const struct kernel_symbol __start___ksymtab_unused[];
extern const struct kernel_symbol __stop___ksymtab_unused[];
extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
extern const struct kernel_symbol __start___ksymtab_gpl_future[]; extern const struct kernel_symbol __start___ksymtab_gpl_future[];
extern const struct kernel_symbol __stop___ksymtab_gpl_future[]; extern const struct kernel_symbol __stop___ksymtab_gpl_future[];
extern const unsigned long __start___kcrctab[]; extern const unsigned long __start___kcrctab[];
extern const unsigned long __start___kcrctab_gpl[]; extern const unsigned long __start___kcrctab_gpl[];
extern const unsigned long __start___kcrctab_gpl_future[]; extern const unsigned long __start___kcrctab_gpl_future[];
#ifdef CONFIG_UNUSED_SYMBOLS
extern const struct kernel_symbol __start___ksymtab_unused[];
extern const struct kernel_symbol __stop___ksymtab_unused[];
extern const struct kernel_symbol __start___ksymtab_unused_gpl[];
extern const struct kernel_symbol __stop___ksymtab_unused_gpl[];
extern const unsigned long __start___kcrctab_unused[]; extern const unsigned long __start___kcrctab_unused[];
extern const unsigned long __start___kcrctab_unused_gpl[]; extern const unsigned long __start___kcrctab_unused_gpl[];
#endif
#ifndef CONFIG_MODVERSIONS #ifndef CONFIG_MODVERSIONS
#define symversion(base, idx) NULL #define symversion(base, idx) NULL
@ -198,12 +200,14 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr,
{ __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future, { __start___ksymtab_gpl_future, __stop___ksymtab_gpl_future,
__start___kcrctab_gpl_future, __start___kcrctab_gpl_future,
WILL_BE_GPL_ONLY, false }, WILL_BE_GPL_ONLY, false },
#ifdef CONFIG_UNUSED_SYMBOLS
{ __start___ksymtab_unused, __stop___ksymtab_unused, { __start___ksymtab_unused, __stop___ksymtab_unused,
__start___kcrctab_unused, __start___kcrctab_unused,
NOT_GPL_ONLY, true }, NOT_GPL_ONLY, true },
{ __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl, { __start___ksymtab_unused_gpl, __stop___ksymtab_unused_gpl,
__start___kcrctab_unused_gpl, __start___kcrctab_unused_gpl,
GPL_ONLY, true }, GPL_ONLY, true },
#endif
}; };
if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data)) if (each_symbol_in_section(arr, ARRAY_SIZE(arr), NULL, fn, data))
@ -220,6 +224,7 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr,
mod->gpl_future_syms + mod->num_gpl_future_syms, mod->gpl_future_syms + mod->num_gpl_future_syms,
mod->gpl_future_crcs, mod->gpl_future_crcs,
WILL_BE_GPL_ONLY, false }, WILL_BE_GPL_ONLY, false },
#ifdef CONFIG_UNUSED_SYMBOLS
{ mod->unused_syms, { mod->unused_syms,
mod->unused_syms + mod->num_unused_syms, mod->unused_syms + mod->num_unused_syms,
mod->unused_crcs, mod->unused_crcs,
@ -228,6 +233,7 @@ static bool each_symbol(bool (*fn)(const struct symsearch *arr,
mod->unused_gpl_syms + mod->num_unused_gpl_syms, mod->unused_gpl_syms + mod->num_unused_gpl_syms,
mod->unused_gpl_crcs, mod->unused_gpl_crcs,
GPL_ONLY, true }, GPL_ONLY, true },
#endif
}; };
if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data)) if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
@ -270,6 +276,7 @@ static bool find_symbol_in_section(const struct symsearch *syms,
} }
} }
#ifdef CONFIG_UNUSED_SYMBOLS
if (syms->unused && fsa->warn) { if (syms->unused && fsa->warn) {
printk(KERN_WARNING "Symbol %s is marked as UNUSED, " printk(KERN_WARNING "Symbol %s is marked as UNUSED, "
"however this module is using it.\n", fsa->name); "however this module is using it.\n", fsa->name);
@ -281,6 +288,7 @@ static bool find_symbol_in_section(const struct symsearch *syms,
"mailinglist together with submitting your code for " "mailinglist together with submitting your code for "
"inclusion.\n"); "inclusion.\n");
} }
#endif
fsa->owner = owner; fsa->owner = owner;
fsa->crc = symversion(syms->crcs, symnum); fsa->crc = symversion(syms->crcs, symnum);
@ -1476,8 +1484,10 @@ static int verify_export_symbols(struct module *mod)
{ mod->syms, mod->num_syms }, { mod->syms, mod->num_syms },
{ mod->gpl_syms, mod->num_gpl_syms }, { mod->gpl_syms, mod->num_gpl_syms },
{ mod->gpl_future_syms, mod->num_gpl_future_syms }, { mod->gpl_future_syms, mod->num_gpl_future_syms },
#ifdef CONFIG_UNUSED_SYMBOLS
{ mod->unused_syms, mod->num_unused_syms }, { mod->unused_syms, mod->num_unused_syms },
{ mod->unused_gpl_syms, mod->num_unused_gpl_syms }, { mod->unused_gpl_syms, mod->num_unused_gpl_syms },
#endif
}; };
for (i = 0; i < ARRAY_SIZE(arr); i++) { for (i = 0; i < ARRAY_SIZE(arr); i++) {
@ -1795,10 +1805,12 @@ static struct module *load_module(void __user *umod,
unsigned int gplfutureindex; unsigned int gplfutureindex;
unsigned int gplfuturecrcindex; unsigned int gplfuturecrcindex;
unsigned int unwindex = 0; unsigned int unwindex = 0;
#ifdef CONFIG_UNUSED_SYMBOLS
unsigned int unusedindex; unsigned int unusedindex;
unsigned int unusedcrcindex; unsigned int unusedcrcindex;
unsigned int unusedgplindex; unsigned int unusedgplindex;
unsigned int unusedgplcrcindex; unsigned int unusedgplcrcindex;
#endif
unsigned int markersindex; unsigned int markersindex;
unsigned int markersstringsindex; unsigned int markersstringsindex;
struct module *mod; struct module *mod;
@ -1881,13 +1893,15 @@ static struct module *load_module(void __user *umod,
exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab"); exportindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab");
gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl"); gplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl");
gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future"); gplfutureindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_gpl_future");
unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused");
unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl");
crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab"); crcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab");
gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl"); gplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl");
gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future"); gplfuturecrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_gpl_future");
#ifdef CONFIG_UNUSED_SYMBOLS
unusedindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused");
unusedgplindex = find_sec(hdr, sechdrs, secstrings, "__ksymtab_unused_gpl");
unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused"); unusedcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused");
unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl"); unusedgplcrcindex = find_sec(hdr, sechdrs, secstrings, "__kcrctab_unused_gpl");
#endif
setupindex = find_sec(hdr, sechdrs, secstrings, "__param"); setupindex = find_sec(hdr, sechdrs, secstrings, "__param");
exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table"); exindex = find_sec(hdr, sechdrs, secstrings, "__ex_table");
obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm"); obsparmindex = find_sec(hdr, sechdrs, secstrings, "__obsparm");
@ -2049,14 +2063,15 @@ static struct module *load_module(void __user *umod,
mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr; mod->gpl_crcs = (void *)sechdrs[gplcrcindex].sh_addr;
mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size / mod->num_gpl_future_syms = sechdrs[gplfutureindex].sh_size /
sizeof(*mod->gpl_future_syms); sizeof(*mod->gpl_future_syms);
mod->num_unused_syms = sechdrs[unusedindex].sh_size /
sizeof(*mod->unused_syms);
mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size /
sizeof(*mod->unused_gpl_syms);
mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr; mod->gpl_future_syms = (void *)sechdrs[gplfutureindex].sh_addr;
if (gplfuturecrcindex) if (gplfuturecrcindex)
mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr; mod->gpl_future_crcs = (void *)sechdrs[gplfuturecrcindex].sh_addr;
#ifdef CONFIG_UNUSED_SYMBOLS
mod->num_unused_syms = sechdrs[unusedindex].sh_size /
sizeof(*mod->unused_syms);
mod->num_unused_gpl_syms = sechdrs[unusedgplindex].sh_size /
sizeof(*mod->unused_gpl_syms);
mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr; mod->unused_syms = (void *)sechdrs[unusedindex].sh_addr;
if (unusedcrcindex) if (unusedcrcindex)
mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr; mod->unused_crcs = (void *)sechdrs[unusedcrcindex].sh_addr;
@ -2064,13 +2079,17 @@ static struct module *load_module(void __user *umod,
if (unusedgplcrcindex) if (unusedgplcrcindex)
mod->unused_gpl_crcs mod->unused_gpl_crcs
= (void *)sechdrs[unusedgplcrcindex].sh_addr; = (void *)sechdrs[unusedgplcrcindex].sh_addr;
#endif
#ifdef CONFIG_MODVERSIONS #ifdef CONFIG_MODVERSIONS
if ((mod->num_syms && !crcindex) || if ((mod->num_syms && !crcindex)
(mod->num_gpl_syms && !gplcrcindex) || || (mod->num_gpl_syms && !gplcrcindex)
(mod->num_gpl_future_syms && !gplfuturecrcindex) || || (mod->num_gpl_future_syms && !gplfuturecrcindex)
(mod->num_unused_syms && !unusedcrcindex) || #ifdef CONFIG_UNUSED_SYMBOLS
(mod->num_unused_gpl_syms && !unusedgplcrcindex)) { || (mod->num_unused_syms && !unusedcrcindex)
|| (mod->num_unused_gpl_syms && !unusedgplcrcindex)
#endif
) {
printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name); printk(KERN_WARNING "%s: No versions for exported symbols.\n", mod->name);
err = try_to_force_load(mod, "nocrc"); err = try_to_force_load(mod, "nocrc");
if (err) if (err)