Skip to content

Commit c2c51f6

Browse files
committed
rust: kbuild: treat build_error and rustdoc as kernel objects
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: stable@vger.kernel.org # Needed in 6.12.y and later (Rust is pinned in older LTSs). Link: rust-lang/rust#138736 [1] Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
1 parent 6146a0f commit c2c51f6

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
@@ -127,9 +127,14 @@ rustdoc-core: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs
127127
rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs rustdoc-clean FORCE
128128
+$(call if_changed,rustdoc)
129129

130+
# Even if `rustdoc` targets are not kernel objects, they should still be
131+
# treated as such so that we pass the same flags. Otherwise, for instance,
132+
# `rustc` will complain about missing sanitizer flags causing an ABI mismatch.
133+
rustdoc-compiler_builtins: private is-kernel-object := y
130134
rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE
131135
+$(call if_changed,rustdoc)
132136

137+
rustdoc-ffi: private is-kernel-object := y
133138
rustdoc-ffi: $(src)/ffi.rs rustdoc-core FORCE
134139
+$(call if_changed,rustdoc)
135140

@@ -147,6 +152,7 @@ rustdoc-pin_init: $(src)/pin-init/src/lib.rs rustdoc-pin_init_internal \
147152
rustdoc-macros FORCE
148153
+$(call if_changed,rustdoc)
149154

155+
rustdoc-kernel: private is-kernel-object := y
150156
rustdoc-kernel: private rustc_target_flags = --extern ffi --extern pin_init \
151157
--extern build_error --extern macros \
152158
--extern bindings --extern uapi
@@ -522,6 +528,10 @@ $(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \
522528
$(obj)/$(libpin_init_internal_name) $(obj)/$(libmacros_name) FORCE
523529
+$(call if_changed_rule,rustc_library)
524530

531+
# Even if normally `build_error` is not a kernel object, it should still be
532+
# treated as such so that we pass the same flags. Otherwise, for instance,
533+
# `rustc` will complain about missing sanitizer flags causing an ABI mismatch.
534+
$(obj)/build_error.o: private is-kernel-object := y
525535
$(obj)/build_error.o: private skip_gendwarfksyms = 1
526536
$(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE
527537
+$(call if_changed_rule,rustc_library)

0 commit comments

Comments
 (0)