[PATCH 13/27] rust: Annotate the intrinsic stubs as returnable
Josh Poimboeuf <[email protected]>
| Newsgroups | gmane.linux.kbuild.devel,gmane.linux.kernel,gmane.linux.kernel.rust |
|---|---|
| Message-ID | <00f55392e4640b835027a30b0dad79b4b53a56ad.1787890035.git.jpoimboe@kernel.org> |
When building the Rust core library, the compiler emits calls to compiler-rt builtins like __udivti3() for 128-bit arithmetic, which the kernel doesn't want, so objcopy is used to redirect those calls to stubs which just panic. Problem is, their call sites still expect them to return, which confuses objtool. Objtool doesn't report any warnings today because the stubs are weak, which noreturn detection currently ignores. In preparation for removing that restriction, annotate them as returnable. Signed-off-by: Josh Poimboeuf <[email protected]> --- rust/.gitignore | 1 + rust/Makefile | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/rust/.gitignore b/rust/.gitignore index d3829ffab80ba..c198d1a52e60e 100644 --- a/rust/.gitignore +++ b/rust/.gitignore @@ -6,5 +6,6 @@ doctests_kernel_generated.rs doctests_kernel_generated_kunit.c uapi_generated.rs exports_*_generated.h +intrinsics_annotate_generated.c doc/ test/ diff --git a/rust/Makefile b/rust/Makefile index 627ed79dc6f50..1cbee6f1ca098 100644 --- a/rust/Makefile +++ b/rust/Makefile @@ -33,6 +33,9 @@ endif obj-$(CONFIG_RUST) += exports.o +always-$(CONFIG_RUST) += intrinsics_annotate_generated.c +obj-$(CONFIG_RUST) += intrinsics_annotate_generated.o + always-$(CONFIG_RUST) += libproc_macro2.rlib libquote.rlib libsyn.rlib always-$(CONFIG_RUST_KERNEL_DOCTESTS) += doctests_kernel_generated.rs @@ -684,6 +687,20 @@ ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),) __ashlti3 __lshrti3 endif +# For objtool, annotate the redirect-intrinsics as returnable. Their call +# sites were compiled against the returnable intrinsics, but the redirected +# versions are noreturn. +quiet_cmd_intrinsics_annotate = GEN $@ + cmd_intrinsics_annotate = { \ + echo '/* Generated by rust/Makefile - do not edit */'; \ + echo '\#include <linux/annotate.h>'; \ + for s in $(redirect-intrinsics); do \ + echo "ANNOTATE_IGNORE_NORETURN(__rust$$s);"; \ + done; } > $@ + +$(obj)/intrinsics_annotate_generated.c: $(srctree)/rust/Makefile FORCE + $(call if_changed,intrinsics_annotate) + ifdef CONFIG_MODVERSIONS cmd_gendwarfksyms = $(if $(skip_gendwarfksyms),, \ $(call rust_exports,$@,"%s\n") | \ -- 2.55.0