Skip to content

Commit 9c3681f

Browse files
samitolvanenmasahir0y
authored andcommitted
kbuild: Add gendwarfksyms as an alternative to genksyms
When MODVERSIONS is enabled, allow selecting gendwarfksyms as the implementation, but default to genksyms. Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
1 parent d7476f2 commit 9c3681f

3 files changed

Lines changed: 52 additions & 7 deletions

File tree

kernel/module/Kconfig

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,13 +169,35 @@ config MODVERSIONS
169169
make them incompatible with the kernel you are running. If
170170
unsure, say N.
171171

172+
choice
173+
prompt "Module versioning implementation"
174+
depends on MODVERSIONS
175+
help
176+
Select the tool used to calculate symbol versions for modules.
177+
178+
If unsure, select GENKSYMS.
179+
180+
config GENKSYMS
181+
bool "genksyms (from source code)"
182+
help
183+
Calculate symbol versions from pre-processed source code using
184+
genksyms.
185+
186+
If unsure, say Y.
187+
172188
config GENDWARFKSYMS
173189
bool "gendwarfksyms (from debugging information)"
174190
depends on DEBUG_INFO
175191
# Requires full debugging information, split DWARF not supported.
176192
depends on !DEBUG_INFO_REDUCED && !DEBUG_INFO_SPLIT
177193
# Requires ELF object files.
178194
depends on !LTO
195+
help
196+
Calculate symbol versions from DWARF debugging information using
197+
gendwarfksyms. Requires DEBUG_INFO to be enabled.
198+
199+
If unsure, say N.
200+
endchoice
179201

180202
config ASM_MODVERSIONS
181203
bool

scripts/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ hostprogs += unifdef
5353
targets += module.lds
5454

5555
subdir-$(CONFIG_GCC_PLUGINS) += gcc-plugins
56-
subdir-$(CONFIG_MODVERSIONS) += genksyms
56+
subdir-$(CONFIG_GENKSYMS) += genksyms
5757
subdir-$(CONFIG_GENDWARFKSYMS) += gendwarfksyms
5858
subdir-$(CONFIG_SECURITY_SELINUX) += selinux
5959
subdir-$(CONFIG_SECURITY_IPE) += ipe

scripts/Makefile.build

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,13 +107,24 @@ cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
107107
$(obj)/%.i: $(obj)/%.c FORCE
108108
$(call if_changed_dep,cpp_i_c)
109109

110+
getexportsymbols = $(NM) $@ | sed -n 's/.* __export_symbol_\(.*\)/$(1)/p'
111+
112+
gendwarfksyms = $(objtree)/scripts/gendwarfksyms/gendwarfksyms \
113+
$(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes)) \
114+
$(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable)
115+
110116
genksyms = $(objtree)/scripts/genksyms/genksyms \
111117
$(if $(KBUILD_SYMTYPES), -T $(@:.o=.symtypes)) \
112118
$(if $(KBUILD_PRESERVE), -p) \
113119
$(addprefix -r , $(wildcard $(@:.o=.symref)))
114120

115121
# These mirror gensymtypes_S and co below, keep them in synch.
122+
ifdef CONFIG_GENDWARFKSYMS
123+
cmd_gensymtypes_c = $(if $(skip_gendwarfksyms),, \
124+
$(call getexportsymbols,\1) | $(gendwarfksyms) $@)
125+
else
116126
cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
127+
endif # CONFIG_GENDWARFKSYMS
117128

118129
# LLVM assembly
119130
# Generate .ll files from .c
@@ -286,14 +297,26 @@ $(obj)/%.rs: $(obj)/%.rs.S FORCE
286297
# This is convoluted. The .S file must first be preprocessed to run guards and
287298
# expand names, then the resulting exports must be constructed into plain
288299
# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
289-
# to make the genksyms input.
300+
# to make the genksyms input or compiled into an object for gendwarfksyms.
290301
#
291302
# These mirror gensymtypes_c and co above, keep them in synch.
292-
cmd_gensymtypes_S = \
293-
{ echo "\#include <linux/kernel.h>" ; \
294-
echo "\#include <asm/asm-prototypes.h>" ; \
295-
$(NM) $@ | sed -n 's/.* __export_symbol_\(.*\)/EXPORT_SYMBOL(\1);/p' ; } | \
296-
$(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
303+
getasmexports = \
304+
{ echo "\#include <linux/kernel.h>" ; \
305+
echo "\#include <linux/string.h>" ; \
306+
echo "\#include <asm/asm-prototypes.h>" ; \
307+
$(call getexportsymbols,EXPORT_SYMBOL(\1);) ; }
308+
309+
ifdef CONFIG_GENDWARFKSYMS
310+
cmd_gensymtypes_S = \
311+
$(getasmexports) | \
312+
$(CC) $(c_flags) -c -o $(@:.o=.gendwarfksyms.o) -xc -; \
313+
$(call getexportsymbols,\1) | \
314+
$(gendwarfksyms) $(@:.o=.gendwarfksyms.o)
315+
else
316+
cmd_gensymtypes_S = \
317+
$(getasmexports) | \
318+
$(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
319+
endif # CONFIG_GENDWARFKSYMS
297320

298321
quiet_cmd_cpp_s_S = CPP $(quiet_modtag) $@
299322
cmd_cpp_s_S = $(CPP) $(a_flags) -o $@ $<

0 commit comments

Comments
 (0)