Skip to content

Commit

Permalink
kallsyms: introduce sections needed to map symbols to built-in modules
Browse files Browse the repository at this point in the history
The mapping consists of three new symbols, computed by integrating the
information in the (just-added) .tmp_vmlinux.ranges and
modules_thick.builtin: taken together, they map address ranges
(corresponding to object files on the input) to the names of zero or
more modules containing those address ranges.

 - kallsyms_module_addresses/kallsyms_module_offsets encodes the
   address/offset of each object file (derived from the linker map), in
   exactly the same way as kallsyms_addresses/kallsyms_offsets does
   for symbols.  There is no size: instead, the object files are assumed
   to tile the address space.  (This is slightly more space-efficient
   than using a size).  Non-text-section addresses are skipped: for now,
   all the users of this interface only need module/non-module
   information for instruction pointer addresses, not absolute-addressed
   symbols and the like.  This restriction can easily be lifted in
   future.  (Regarding the name: right now the entries correspond pretty
   closely to object files, so we could call the section
   kallsyms_objfiles or something, but the optimizer added in the next
   commit will change this.)

 - kallsyms_module_names encodes the name of each module in a modified
   form of strtab: notably, if an object file appears in *multiple*
   modules, all of which are built in, this is encoded via a zero byte,
   a one-byte module count, then a series of that many null-terminated
   strings.  As a special case, the table starts with a single zero byte
   which does *not* represent the start of a multi-module list.

 - kallsyms_modules connects the two, encoding a table associated 1:1
   with kallsyms_module_addresses / kallsyms_module_offsets, pointing
   at an offset in kallsyms_module_names describing which module (or
   modules, for a multi-module list) the code occupying this address
   range is part of.  If an address range is part of no module (always
   built-in) it points at 0 (the null byte at the start of the
   kallsyms_module_names list).

There is no optimization yet: kallsyms_modules and
kallsyms_module_names will almost certainly contain many duplicate
entries, and kallsyms_module_{addresses,offsets} may contain
consecutive entries that point to the same place.  The size hit is
fairly substantial as a result, though still much less than a naive
implementation mapping each symbol to a module name would be: 50KiB or
so.

Signed-off-by: Nick Alcock <nick.alcock@oracle.com>
  • Loading branch information
nickalcock authored and intel-lab-lkp committed Dec 16, 2021
1 parent 05cf02b commit 54ce07d
Show file tree
Hide file tree
Showing 4 changed files with 371 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1157,7 +1157,7 @@ cmd_link-vmlinux = \
$(CONFIG_SHELL) $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \
$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)

vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) modules_thick.builtin FORCE
+$(call if_changed_dep,link-vmlinux)

targets := vmlinux
Expand Down
8 changes: 8 additions & 0 deletions init/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,14 @@ config POSIX_TIMERS

If unsure say y.

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.

config PRINTK
default y
bool "Enable support for printk" if EXPERT
Expand Down
6 changes: 6 additions & 0 deletions scripts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ HOSTCFLAGS_sorttable.o += -DUNWINDER_ORC_ENABLED
HOSTLDLIBS_sorttable = -lpthread
endif

kallsyms-objs := kallsyms.o

ifdef CONFIG_KALLMODSYMS
kallsyms-objs += modules_thick.o
endif

# The following programs are only built on demand
hostprogs += unifdef

Expand Down

0 comments on commit 54ce07d

Please sign in to comment.