]> www.infradead.org Git - users/jedix/linux-maple.git/commit
kbuild: keep symbols for symbol_get() even with CONFIG_TRIM_UNUSED_KSYMS
authorMasahiro Yamada <masahiroy@kernel.org>
Sat, 1 Feb 2025 18:51:41 +0000 (03:51 +0900)
committerMasahiro Yamada <masahiroy@kernel.org>
Wed, 5 Feb 2025 16:08:58 +0000 (01:08 +0900)
commit4c56eb33e603c3b9eb4bd24efbfdd0283c1c37e4
tree99427a37db05f39281d56e993f132d1ea7e363d8
parent738fc998b639407346a9e026514f0562301462cd
kbuild: keep symbols for symbol_get() even with CONFIG_TRIM_UNUSED_KSYMS

Linus observed that the symbol_request(utf8_data_table) call fails when
CONFIG_UNICODE=y and CONFIG_TRIM_UNUSED_KSYMS=y.

symbol_get() relies on the symbol data being present in the ksymtab for
symbol lookups. However, EXPORT_SYMBOL_GPL(utf8_data_table) is dropped
due to CONFIG_TRIM_UNUSED_KSYMS, as no module references it in this case.

Probably, this has been broken since commit dbacb0ef670d ("kconfig option
for TRIM_UNUSED_KSYMS").

This commit addresses the issue by leveraging modpost. Symbol names
passed to symbol_get() are recorded in the special .no_trim_symbol
section, which is then parsed by modpost to forcibly keep such symbols.
The .no_trim_symbol section is discarded by the linker scripts, so there
is no impact on the size of the final vmlinux or modules.

This commit cannot resolve the issue for direct calls to __symbol_get()
because the symbol name is not known at compile-time.

Although symbol_get() may eventually be deprecated, this workaround
should be good enough meanwhile.

Reported-by: Linus Torvalds <torvalds@linux-foundation.org>
Suggested-by: Linus Torvalds <torvalds@linux-foundation.org>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
include/asm-generic/vmlinux.lds.h
include/linux/module.h
scripts/mod/modpost.c
scripts/mod/modpost.h
scripts/module.lds.S