Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

rust: Use gendwarfksyms + extended modversions for CONFIG_MODVERSIONS

Previously, two things stopped Rust from using MODVERSIONS:
1. Rust symbols are occasionally too long to be represented in the
original versions table
2. Rust types cannot be properly hashed by the existing genksyms
approach because:
* Looking up type definitions in Rust is more complex than C
* Type layout is potentially dependent on the compiler in Rust,
not just the source type declaration.

CONFIG_EXTENDED_MODVERSIONS addresses the first point, and
CONFIG_GENDWARFKSYMS the second. If Rust wants to use MODVERSIONS, allow
it to do so by selecting both features.

Signed-off-by: Sami Tolvanen <samitolvanen@google.com>
Co-developed-by: Matthew Maurer <mmaurer@google.com>
Signed-off-by: Matthew Maurer <mmaurer@google.com>
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

authored by

Sami Tolvanen and committed by
Masahiro Yamada
ac61506b 272f8a6d

+34 -3
+2 -1
init/Kconfig
··· 1956 1956 bool "Rust support" 1957 1957 depends on HAVE_RUST 1958 1958 depends on RUST_IS_AVAILABLE 1959 - depends on !MODVERSIONS 1959 + select EXTENDED_MODVERSIONS if MODVERSIONS 1960 + depends on !MODVERSIONS || GENDWARFKSYMS 1960 1961 depends on !GCC_PLUGIN_RANDSTRUCT 1961 1962 depends on !RANDSTRUCT 1962 1963 depends on !DEBUG_INFO_BTF || PAHOLE_HAS_LANG_EXCLUDE
+32 -2
rust/Makefile
··· 329 329 $(obj)/bindings/bindings_helpers_generated.rs: $(src)/helpers/helpers.c FORCE 330 330 $(call if_changed_dep,bindgen) 331 331 332 + rust_exports = $(NM) -p --defined-only $(1) | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ { printf $(2),$$3 }' 333 + 332 334 quiet_cmd_exports = EXPORTS $@ 333 335 cmd_exports = \ 334 - $(NM) -p --defined-only $< \ 335 - | awk '$$2~/(T|R|D|B)/ && $$3!~/__cfi/ {printf "EXPORT_SYMBOL_RUST_GPL(%s);\n",$$3}' > $@ 336 + $(call rust_exports,$<,"EXPORT_SYMBOL_RUST_GPL(%s);\n") > $@ 336 337 337 338 $(obj)/exports_core_generated.h: $(obj)/core.o FORCE 338 339 $(call if_changed,exports) ··· 402 401 __ashlti3 __lshrti3 403 402 endif 404 403 404 + ifdef CONFIG_MODVERSIONS 405 + cmd_gendwarfksyms = $(if $(skip_gendwarfksyms),, \ 406 + $(call rust_exports,$@,"%s\n") | \ 407 + scripts/gendwarfksyms/gendwarfksyms \ 408 + $(if $(KBUILD_GENDWARFKSYMS_STABLE), --stable) \ 409 + $(if $(KBUILD_SYMTYPES), --symtypes $(@:.o=.symtypes),) \ 410 + $@ >> $(dot-target).cmd) 411 + endif 412 + 405 413 define rule_rustc_library 406 414 $(call cmd_and_fixdep,rustc_library) 407 415 $(call cmd,gen_objtooldep) 416 + $(call cmd,gendwarfksyms) 408 417 endef 418 + 419 + define rule_rust_cc_library 420 + $(call if_changed_rule,cc_o_c) 421 + $(call cmd,force_checksrc) 422 + $(call cmd,gendwarfksyms) 423 + endef 424 + 425 + # helpers.o uses the same export mechanism as Rust libraries, so ensure symbol 426 + # versions are calculated for the helpers too. 427 + $(obj)/helpers/helpers.o: $(src)/helpers/helpers.c $(recordmcount_source) FORCE 428 + +$(call if_changed_rule,rust_cc_library) 429 + 430 + # Disable symbol versioning for exports.o to avoid conflicts with the actual 431 + # symbol versions generated from Rust objects. 432 + $(obj)/exports.o: private skip_gendwarfksyms = 1 409 433 410 434 $(obj)/core.o: private skip_clippy = 1 411 435 $(obj)/core.o: private skip_flags = -Wunreachable_pub ··· 443 417 $(obj)/core.o: scripts/target.json 444 418 endif 445 419 420 + $(obj)/compiler_builtins.o: private skip_gendwarfksyms = 1 446 421 $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*' 447 422 $(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE 448 423 +$(call if_changed_rule,rustc_library) 449 424 425 + $(obj)/build_error.o: private skip_gendwarfksyms = 1 450 426 $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE 451 427 +$(call if_changed_rule,rustc_library) 452 428 429 + $(obj)/ffi.o: private skip_gendwarfksyms = 1 453 430 $(obj)/ffi.o: $(src)/ffi.rs $(obj)/compiler_builtins.o FORCE 454 431 +$(call if_changed_rule,rustc_library) 455 432 ··· 464 435 +$(call if_changed_rule,rustc_library) 465 436 466 437 $(obj)/uapi.o: private rustc_target_flags = --extern ffi 438 + $(obj)/uapi.o: private skip_gendwarfksyms = 1 467 439 $(obj)/uapi.o: $(src)/uapi/lib.rs \ 468 440 $(obj)/ffi.o \ 469 441 $(obj)/uapi/uapi_generated.rs FORCE