From: Nick Alcock Date: Mon, 3 Aug 2015 12:40:29 +0000 (+0100) Subject: kallsyms: make it possible to disable /proc/kallmodsyms X-Git-Tag: v4.1.12-92~303^2~2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=28df3b99a76e7a1bc9c9765706ff922ca36d1c29;p=users%2Fjedix%2Flinux-maple.git kallsyms: make it possible to disable /proc/kallmodsyms This allows you to build UEK without elfutils present at all, just like you can with the upstream. It requires a bit of fiddling about in kernel/kallsyms.c to make kallsyms work with a NULL kallsyms_symbol_modules, and a bit of code motion to keep the number of ifdefs down. Verified that /proc/kallsyms has identical output (modulo only addresses, dtrace-related symbols and, of course, the symbols ifdeffed out in this patch) when the new CONFIG_KALLMODSYMS option is flipped. Signed-off-by: Nick Alcock Acked-by: Kris Van Hees Orabug: 21539840 --- diff --git a/init/Kconfig b/init/Kconfig index 75242761fe6d..598f817c43e2 100644 --- a/init/Kconfig +++ b/init/Kconfig @@ -1434,6 +1434,15 @@ config KALLSYMS_ALL Say N unless you really need all symbols. +config KALLMODSYMS + default y + bool "Enable support for /proc/kallmodsyms" if EXPERT + depends on KALLSYMS + help + This option enables the /proc/kallmodsyms file, which maps symbols + to addresses and their associated modules. This support requires + a fairly recent elfutils. + config PRINTK default y bool "Enable support for printk" if EXPERT diff --git a/kernel/dtrace/Kconfig b/kernel/dtrace/Kconfig index 80aadd503d4a..80a0262d3d94 100644 --- a/kernel/dtrace/Kconfig +++ b/kernel/dtrace/Kconfig @@ -9,6 +9,7 @@ menuconfig DTRACE depends on ARCH_SUPPORTS_DTRACE depends on !DEBUG_LOCK_ALLOC select KALLSYMS + select KALLMODSYMS select WAITFD select CTF if (!DT_DISABLE_CTF) help diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c index c3cf2a24f29b..d76c562b8b9c 100644 --- a/kernel/kallsyms.c +++ b/kernel/kallsyms.c @@ -486,9 +486,12 @@ static int get_ksymbol_mod(struct kallsym_iter *iter) static unsigned long get_ksymbol_core(struct kallsym_iter *iter) { unsigned off = iter->nameoff; - u32 mod_index = kallsyms_symbol_modules[iter->pos]; + u32 mod_index = 0; - if (mod_index == 0) { + if (kallsyms_symbol_modules) + mod_index = kallsyms_symbol_modules[iter->pos]; + + if (mod_index == 0 || kallsyms_modules == NULL) { iter->module_name[0] = '\0'; iter->builtin_module = 0; } else { @@ -593,11 +596,6 @@ static int s_show(struct seq_file *m, void *p) return s_show_internal(m, p, 0); } -static int s_mod_show(struct seq_file *m, void *p) -{ - return s_show_internal(m, p, 1); -} - static const struct seq_operations kallsyms_op = { .start = s_start, .next = s_next, @@ -605,12 +603,19 @@ static const struct seq_operations kallsyms_op = { .show = s_show }; +#ifdef CONFIG_KALLMODSYMS +static int s_mod_show(struct seq_file *m, void *p) +{ + return s_show_internal(m, p, 1); +} + static const struct seq_operations kallmodsyms_op = { .start = s_start, .next = s_next, .stop = s_stop, .show = s_mod_show }; +#endif static int kallsyms_open_internal(struct inode *inode, struct file *file, const struct seq_operations *ops) @@ -634,10 +639,12 @@ static int kallsyms_open(struct inode *inode, struct file *file) return kallsyms_open_internal(inode, file, &kallsyms_op); } +#ifdef CONFIG_KALLMODSYMS static int kallmodsyms_open(struct inode *inode, struct file *file) { return kallsyms_open_internal(inode, file, &kallmodsyms_op); } +#endif #ifdef CONFIG_KGDB_KDB const char *kdb_walk_kallsyms(loff_t *pos) @@ -666,17 +673,21 @@ static const struct file_operations kallsyms_operations = { .release = seq_release_private, }; +#ifdef CONFIG_KALLMODSYMS static const struct file_operations kallmodsyms_operations = { .open = kallmodsyms_open, .read = seq_read, .llseek = seq_lseek, .release = seq_release_private, }; +#endif static int __init kallsyms_init(void) { proc_create("kallsyms", 0444, NULL, &kallsyms_operations); +#ifdef CONFIG_KALLMODSYMS proc_create("kallmodsyms", 0444, NULL, &kallmodsyms_operations); +#endif return 0; } device_initcall(kallsyms_init); diff --git a/scripts/Makefile b/scripts/Makefile index e7e81b87841d..a9f02e69f6dd 100644 --- a/scripts/Makefile +++ b/scripts/Makefile @@ -22,11 +22,15 @@ HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include always := $(hostprogs-y) $(hostprogs-m) -kallsyms-objs := kallsyms.o eu_simple.o +kallsyms-objs := kallsyms.o + +ifeq ($(CONFIG_KALLMODSYMS),y) +kallsyms-objs += eu_simple.o HOSTCFLAGS_eu_simple.o := -I$(srctree)/scripts HOSTCFLAGS_kallsyms.o := $(shell pkg-config --cflags glib-2.0) -I$(srctree)/scripts HOSTLOADLIBES_kallsyms := $(shell pkg-config --libs glib-2.0) -ldw +endif # The following hostprogs-y programs are only build on demand hostprogs-y += unifdef docproc diff --git a/scripts/kallsyms.c b/scripts/kallsyms.c index 9b3941d50aa0..b55aa633e9c4 100644 --- a/scripts/kallsyms.c +++ b/scripts/kallsyms.c @@ -28,6 +28,7 @@ #include #include +#ifdef CONFIG_KALLMODSYMS #include #include #include @@ -35,6 +36,7 @@ #include #include +#endif #ifndef ARRAY_SIZE #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) @@ -82,18 +84,13 @@ int token_profit[0x10000]; unsigned char best_table[256][2]; unsigned char best_table_len[256]; +#ifdef CONFIG_KALLMODSYMS /* * The list of builtin module names. */ static char **builtin_modules; static unsigned int builtin_module_size, builtin_module_len; -/* - * For each builtin module, its offset from the start of the builtin_module - * list, assuming consecutive placement. - */ -static unsigned int *builtin_module_offsets; - /* * A mapping from symbol name to the index of the module it is part of in the * builtin_modules list. Symbols within the same module share pointers to the @@ -101,6 +98,13 @@ static unsigned int *builtin_module_offsets; * quite space-efficient). */ static GHashTable *symbol_to_module; +#endif + +/* + * For each builtin module, its offset from the start of the builtin_module + * list, assuming consecutive placement. + */ +static unsigned int *builtin_module_offsets; static void usage(void) { @@ -194,8 +198,12 @@ static int read_symbol(FILE *in, struct sym_entry *s) else if (stype == 'N') return -1; +#ifdef CONFIG_KALLMODSYMS /* look up the builtin module this is part of (if any). */ module = g_hash_table_lookup(symbol_to_module, sym); +#else + module = 0; +#endif if (module) s->module = builtin_module_offsets[*module]; @@ -463,6 +471,7 @@ static void write_src(void) printf("\t.short\t%d\n", best_idx[i]); printf("\n"); +#ifdef CONFIG_KALLMODSYMS output_label("kallsyms_modules"); for (i = 0; i < builtin_module_len; i++) printf("\t.asciz\t\"%s\"\n", builtin_modules[i]); @@ -472,6 +481,7 @@ static void write_src(void) for (i = 0; i < table_cnt; i++) printf("\t.int\t%d\n", table[i].module); printf("\n"); +#endif } /* table lookup compression functions */ @@ -739,6 +749,7 @@ static void make_percpus_absolute(void) table[i].sym[0] = 'A'; } +#ifdef CONFIG_KALLMODSYMS /* Built-in module list computation. */ /* @@ -979,6 +990,9 @@ static void read_modules(const char *modules_builtin) fclose(f); g_hash_table_destroy(module_symbol_seen); } +#else +static void read_modules(const char *unused) {} +#endif /* CONFIG_KALLMODSYMS */ int main(int argc, char **argv) {