Skip to content

Commit 9376571

Browse files
ojedaopsiff
authored andcommitted
rust: kbuild: treat build_error and rustdoc as kernel objects
[ Upstream commit 16c43a56b79e2c3220b043236369a129d508c65a ] Even if normally `build_error` isn't a kernel object, it should still be treated as such so that we pass the same flags. Similarly, `rustdoc` targets are never kernel objects, but we need to treat them as such. Otherwise, starting with Rust 1.91.0 (released 2025-10-30), `rustc` will complain about missing sanitizer flags since `-Zsanitizer` is a target modifier too [1]: error: mixing `-Zsanitizer` will cause an ABI mismatch in crate `build_error` --> rust/build_error.rs:3:1 | 3 | //! Build-time error. | ^ | = help: the `-Zsanitizer` flag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely = note: unset `-Zsanitizer` in this crate is incompatible with `-Zsanitizer=kernel-address` in dependency `core` = help: set `-Zsanitizer=kernel-address` in this crate or unset `-Zsanitizer` in `core` = help: if you are sure this will not cause problems, you may use `-Cunsafe-allow-abi-mismatch=sanitizer` to silence this error Thus explicitly mark them as kernel objects. Cc: [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs). Link: rust-lang/rust#138736 [1] Reviewed-by: Alice Ryhl <[email protected]> Tested-by: Justin M. Forbes <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Miguel Ojeda <[email protected]> [ Adjust context ] Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 3b987ebe6c4b33570e7c99940bda48f1b9cf534f) Signed-off-by: Wentao Guan <[email protected]>
1 parent f81ced9 commit 9376571

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

rust/Makefile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,12 +107,18 @@ rustdoc-core: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs
107107
rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs rustdoc-clean FORCE
108108
+$(call if_changed,rustdoc)
109109

110+
# Even if `rustdoc` targets are not kernel objects, they should still be
111+
# treated as such so that we pass the same flags. Otherwise, for instance,
112+
# `rustdoc` will complain about missing sanitizer flags causing an ABI mismatch.
113+
rustdoc-compiler_builtins: private is-kernel-object := y
110114
rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
111115
+$(call if_changed,rustdoc)
112116

117+
rustdoc-ffi: private is-kernel-object := y
113118
rustdoc-ffi: $(src)/ffi.rs rustdoc-core FORCE
114119
+$(call if_changed,rustdoc)
115120

121+
rustdoc-kernel: private is-kernel-object := y
116122
rustdoc-kernel: private rustc_target_flags = --extern ffi \
117123
--extern build_error --extern macros=$(objtree)/$(obj)/libmacros.so \
118124
--extern bindings --extern uapi
@@ -433,6 +439,10 @@ $(obj)/compiler_builtins.o: private rustc_objcopy = -w -W '__*'
433439
$(obj)/compiler_builtins.o: $(src)/compiler_builtins.rs $(obj)/core.o FORCE
434440
+$(call if_changed_rule,rustc_library)
435441

442+
# Even if normally `build_error` is not a kernel object, it should still be
443+
# treated as such so that we pass the same flags. Otherwise, for instance,
444+
# `rustc` will complain about missing sanitizer flags causing an ABI mismatch.
445+
$(obj)/build_error.o: private is-kernel-object := y
436446
$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
437447
+$(call if_changed_rule,rustc_library)
438448

0 commit comments

Comments
 (0)