Skip to content

Commit a0267d0

Browse files
committed
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>
1 parent daf833b commit a0267d0

File tree

3 files changed

+53
-8
lines changed

3 files changed

+53
-8
lines changed

kernel/module/Kconfig

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,13 +168,36 @@ config MODVERSIONS
168168
make them incompatible with the kernel you are running. If
169169
unsure, say N.
170170

171+
choice
172+
prompt "Module versioning implementation"
173+
depends on MODVERSIONS
174+
default GENKSYMS
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+
171188
config GENDWARFKSYMS
172-
bool
189+
bool "gendwarfksyms (from debugging information)"
173190
depends on DEBUG_INFO
174191
# Requires full debugging information, split DWARF not supported.
175192
depends on !DEBUG_INFO_REDUCED && !DEBUG_INFO_SPLIT
176193
# Requires ELF object files.
177194
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
178201

179202
config ASM_MODVERSIONS
180203
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

scripts/Makefile.build

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,22 @@ cmd_cpp_i_c = $(CPP) $(c_flags) -o $@ $<
122122
$(obj)/%.i: $(obj)/%.c FORCE
123123
$(call if_changed_dep,cpp_i_c)
124124

125+
gendwarfksyms := scripts/gendwarfksyms/gendwarfksyms
126+
getexportsymbols = $(NM) $(1) | sed -n 's/.* __export_symbol_\(.*\)/$(2)/p'
127+
125128
genksyms = scripts/genksyms/genksyms \
126129
$(if $(1), -T $(2)) \
127130
$(if $(KBUILD_PRESERVE), -p) \
128131
-r $(or $(wildcard $(2:.symtypes=.symref)), /dev/null)
129132

130133
# These mirror gensymtypes_S and co below, keep them in synch.
134+
ifdef CONFIG_GENDWARFKSYMS
135+
cmd_gensymtypes_c = $(if $(skip_gendwarfksyms),, \
136+
$(call getexportsymbols,$(2:.symtypes=.o),\1) | \
137+
$(gendwarfksyms) $(2:.symtypes=.o) $(if $(1), --symtypes $(2)))
138+
else
131139
cmd_gensymtypes_c = $(CPP) -D__GENKSYMS__ $(c_flags) $< | $(genksyms)
140+
endif # CONFIG_GENDWARFKSYMS
132141

133142
quiet_cmd_cc_symtypes_c = SYM $(quiet_modtag) $@
134143
cmd_cc_symtypes_c = $(call cmd_gensymtypes_c,true,$@) >/dev/null
@@ -324,14 +333,27 @@ $(obj)/%.ll: $(obj)/%.rs FORCE
324333
# This is convoluted. The .S file must first be preprocessed to run guards and
325334
# expand names, then the resulting exports must be constructed into plain
326335
# EXPORT_SYMBOL(symbol); to build our dummy C file, and that gets preprocessed
327-
# to make the genksyms input.
336+
# to make the genksyms input or compiled into an object for gendwarfksyms.
328337
#
329338
# These mirror gensymtypes_c and co above, keep them in synch.
330-
cmd_gensymtypes_S = \
331-
{ echo "\#include <linux/kernel.h>" ; \
332-
echo "\#include <asm/asm-prototypes.h>" ; \
333-
$(NM) $@ | sed -n 's/.* __export_symbol_\(.*\)/EXPORT_SYMBOL(\1);/p' ; } | \
334-
$(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
339+
getasmexports = \
340+
{ echo "\#include <linux/kernel.h>" ; \
341+
echo "\#include <linux/string.h>" ; \
342+
echo "\#include <asm/asm-prototypes.h>" ; \
343+
$(call getexportsymbols,$@,EXPORT_SYMBOL(\1);) ; }
344+
345+
ifdef CONFIG_GENDWARFKSYMS
346+
cmd_gensymtypes_S = \
347+
$(getasmexports) | \
348+
$(CC) $(c_flags) -c -o $(@:.o=.gendwarfksyms.o) -xc -; \
349+
$(call getexportsymbols,$@,\1) | \
350+
$(gendwarfksyms) $(@:.o=.gendwarfksyms.o) \
351+
$(if $(1), --symtypes $(2))
352+
else
353+
cmd_gensymtypes_S = \
354+
$(getasmexports) | \
355+
$(CPP) -D__GENKSYMS__ $(c_flags) -xc - | $(genksyms)
356+
endif # CONFIG_GENDWARFKSYMS
335357

336358
quiet_cmd_cc_symtypes_S = SYM $(quiet_modtag) $@
337359
cmd_cc_symtypes_S = $(call cmd_gensymtypes_S,true,$@) >/dev/null

0 commit comments

Comments
 (0)