Skip to content

Commit 6a84920

Browse files
kvanheesjfvogel
authored andcommitted
kallsyms: new /proc/kallmodsyms with builtin modules and symbol sizes
/proc/kallsyms is very useful for tracers and other tools that need to map kernel symbols to addresses. It would be useful if: - there were a mapping between kernel symbol and module name that only changed when the kernel source code is changed. This mapping should not change simply because a module becomes built into the kernel. - there were symbol size information to determine whether an address is within a symbol or outside it, especially given that there could be huge gaps between symbols. Therefore: - Introduce a new config parameter CONFIG_KALLMODSYMS. - Generate a file "modules_thick.builtin" that maps from the thin archives that make up built-in modules to their constituent object files. - Generate a linker map ".tmp_vmlinux.map", converting it into ".tmp_vmlinux.ranges", mapping address ranges to object files. - Change scripts/kallsyms.c stdin from "nm" to "nm -S" so that symbol sizes are available. Have sort_symbols() incorporate size info. Emit size info in the *.s output file. Skip the .init.scratch section. - If CONFIG_KALLMODSYMS, have scripts/kallsyms also read "modules_thick.builtin" and ".tmp_vmlinux.ranges" to map symbol addresses to built-in-module names and then write those module names and per-symbol module information to the *.s output file. - Change module_get_kallsym() to return symbol size as well. - In kernel/kallsyms: - Use new, accurate symbol size information in get_symbol_pos(), both to identify the correct symbol and to return correct size information. - Introduce a field builtin_module to say if the symbol is in a built-in module. - If CONFIG_KALLMODSYMS, produce a new /proc/kallmodsyms file, akin to /proc/kallsyms but with built-in-module names and symbol sizes. The resulting /proc/kallmodsyms file looks like this: ffffffff8b013d20 409 t pt_buffer_setup_aux ffffffff8b014130 11f T intel_pt_interrupt ffffffff8b014250 2d T cpu_emergency_stop_pt ffffffff8b014280 13a t rapl_pmu_event_init [intel_rapl_perf] ffffffff8b0143c0 bb t rapl_event_update [intel_rapl_perf] ffffffff8b014480 10 t rapl_pmu_event_read [intel_rapl_perf] ffffffff8b014490 a3 t rapl_cpu_offline [intel_rapl_perf] ffffffff8b014540 24 t __rapl_event_show [intel_rapl_perf] ffffffff8b014570 f2 t rapl_pmu_event_stop [intel_rapl_perf] This is emitted even if intel_rapl_perf is built into the kernel. As with /proc/kallsyms, non-root usage produces addresses that are all zero; symbol sizes are treated similarly. Programs that consume /proc/kallmodsyms should note that unlike /proc/kallsyms, kernel symbols for built-in modules may appear interspersed with other symbols that are part of different modules or of the kernel. Orabug: 30544408 Signed-off-by: Kris Van Hees <[email protected]> Signed-off-by: Nick Alcock <[email protected]> Signed-off-by: Eugene Loh <[email protected]> Reviewed-by: Nick Alcock <[email protected]> Reviewed-by: Kris Van Hees <[email protected]>
1 parent 1b16e9a commit 6a84920

File tree

11 files changed

+748
-67
lines changed

11 files changed

+748
-67
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
Module.symvers
4848
modules.builtin
4949
modules.order
50+
modules_thick.builtin
5051

5152
#
5253
# Top-level generic files

Documentation/dontdiff

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,7 @@ modpost
180180
modules.builtin
181181
modules.builtin.modinfo
182182
modules.order
183+
modules_thick.builtin
183184
modversions.h*
184185
nconf
185186
nconf-cfg

Makefile

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1080,7 +1080,7 @@ cmd_link-vmlinux = \
10801080
$(CONFIG_SHELL) $< $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) ; \
10811081
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
10821082

1083-
vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
1083+
vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) modules_thick.builtin FORCE
10841084
+$(call if_changed,link-vmlinux)
10851085

10861086
targets := vmlinux
@@ -1295,17 +1295,6 @@ modules: $(if $(KBUILD_BUILTIN),vmlinux) modules.order modules.builtin
12951295
modules.order: descend
12961296
$(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
12971297

1298-
modbuiltin-dirs := $(addprefix _modbuiltin_, $(build-dirs))
1299-
1300-
modules.builtin: $(modbuiltin-dirs)
1301-
$(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
1302-
1303-
PHONY += $(modbuiltin-dirs)
1304-
# tristate.conf is not included from this Makefile. Add it as a prerequisite
1305-
# here to make it self-healing in case somebody accidentally removes it.
1306-
$(modbuiltin-dirs): include/config/tristate.conf
1307-
$(Q)$(MAKE) $(modbuiltin)=$(patsubst _modbuiltin_%,%,$@)
1308-
13091298
# Target to prepare building external modules
13101299
PHONY += modules_prepare
13111300
modules_prepare: prepare
@@ -1358,6 +1347,33 @@ modules modules_install:
13581347

13591348
endif # CONFIG_MODULES
13601349

1350+
# modules.builtin has a 'thick' form which maps from kernel modules (or rather
1351+
# the object file names they would have had had they not been built in) to their
1352+
# constituent object files: kallsyms uses this to determine which modules any
1353+
# given object file is part of. (We cannot eliminate the slight redundancy
1354+
# here without double-expansion.)
1355+
1356+
modbuiltin-dirs := $(addprefix _modbuiltin_, $(build-dirs))
1357+
1358+
modbuiltin-thick-dirs := $(addprefix _modbuiltin_thick_, $(build-dirs))
1359+
1360+
modules.builtin: $(modbuiltin-dirs)
1361+
$(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
1362+
1363+
modules_thick.builtin: $(modbuiltin-thick-dirs)
1364+
$(Q)$(AWK) '!x[$$0]++' $(addsuffix /$@, $(build-dirs)) > $@
1365+
1366+
PHONY += $(modbuiltin-dirs) $(modbuiltin-thick-dirs)
1367+
# tristate.conf is not included from this Makefile. Add it as a prerequisite
1368+
# here to make it self-healing in case somebody accidentally removes it.
1369+
$(modbuiltin-dirs): include/config/tristate.conf
1370+
$(Q)$(MAKE) $(modbuiltin)=$(patsubst _modbuiltin_%,%,$@) \
1371+
builtin-file=modules.builtin
1372+
1373+
$(modbuiltin-thick-dirs): include/config/tristate.conf
1374+
$(Q)$(MAKE) $(modbuiltin)=$(patsubst _modbuiltin_thick_%,%,$@) \
1375+
builtin-file=modules_thick.builtin
1376+
13611377
###
13621378
# Cleaning is done on three levels.
13631379
# make clean Delete most generated files
@@ -1677,6 +1693,7 @@ clean: $(clean-dirs)
16771693
-o -name '*.asn1.[ch]' \
16781694
-o -name '*.symtypes' -o -name 'modules.order' \
16791695
-o -name modules.builtin -o -name '.tmp_*.o.*' \
1696+
-o -name modules_thick.builtin \
16801697
-o -name '*.c.[012]*.*' \
16811698
-o -name '*.ll' \
16821699
-o -name '*.gcno' \) -type f -print | xargs rm -f

include/linux/module.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,8 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
592592
/* Returns 0 and fills in value, defined and namebuf, or -ERANGE if
593593
symnum out of range. */
594594
int module_get_kallsym(unsigned int symnum, unsigned long *value, char *type,
595-
char *name, char *module_name, int *exported);
595+
char *name, char *module_name, unsigned long *size,
596+
int *exported);
596597

597598
/* Look for this name: can be of form module:name. */
598599
unsigned long module_kallsyms_lookup_name(const char *name);
@@ -774,8 +775,8 @@ static inline int lookup_module_symbol_attrs(unsigned long addr, unsigned long *
774775
}
775776

776777
static inline int module_get_kallsym(unsigned int symnum, unsigned long *value,
777-
char *type, char *name,
778-
char *module_name, int *exported)
778+
char *type, char *name, char *module_name,
779+
unsigned long *size, int *exported)
779780
{
780781
return -ERANGE;
781782
}

init/Kconfig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1429,6 +1429,14 @@ config POSIX_TIMERS
14291429

14301430
If unsure say y.
14311431

1432+
config KALLMODSYMS
1433+
default y
1434+
bool "Enable support for /proc/kallmodsyms" if EXPERT
1435+
depends on KALLSYMS
1436+
help
1437+
This option enables the /proc/kallmodsyms file, which maps symbols
1438+
to addresses and their associated modules.
1439+
14321440
config PRINTK
14331441
default y
14341442
bool "Enable support for printk" if EXPERT

0 commit comments

Comments
 (0)