rust: kbuild: treat `build_error` and `rustdoc` as kernel objects
Subsystems (3)
Miguel Ojeda
maintainerPATCH 1/2 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.
--- rust/Makefile | 10 ++++++++++ 1 file changed, 10 insertions(+)
rust/Makefile +10 -0
@@ -127,9 +127,14 @@ rustdoc-core: private rustc_target_flags = --edition=$(core-edition) $(core-cfgs rustdoc-core: $(RUST_LIB_SRC)/core/src/lib.rs rustdoc-clean FORCE +$(call if_changed,rustdoc) +# Even if `rustdoc` targets are not kernel objects, they should still be +# treated as such so that we pass the same flags. Otherwise, for instance, +# `rustc` will complain about missing sanitizer flags causing an ABI mismatch. +rustdoc-compiler_builtins: private is-kernel-object := y rustdoc-compiler_builtins: $(src)/compiler_builtins.rs rustdoc-core FORCE +$(call if_changed,rustdoc) +rustdoc-ffi: private is-kernel-object := y rustdoc-ffi: $(src)/ffi.rs rustdoc-core FORCE +$(call if_changed,rustdoc)
@@ -147,6 +152,7 @@ rustdoc-pin_init: $(src)/pin-init/src/lib.rs rustdoc-pin_init_internal \ rustdoc-macros FORCE +$(call if_changed,rustdoc) +rustdoc-kernel: private is-kernel-object := y rustdoc-kernel: private rustc_target_flags = --extern ffi --extern pin_init \ --extern build_error --extern macros \ --extern bindings --extern uapi
@@ -522,6 +528,10 @@ $(obj)/pin_init.o: $(src)/pin-init/src/lib.rs $(obj)/compiler_builtins.o \ $(obj)/$(libpin_init_internal_name) $(obj)/$(libmacros_name) FORCE +$(call if_changed_rule,rustc_library) +# Even if normally `build_error` is not a kernel object, it should still be +# treated as such so that we pass the same flags. Otherwise, for instance, +# `rustc` will complain about missing sanitizer flags causing an ABI mismatch. +$(obj)/build_error.o: private is-kernel-object := y $(obj)/build_error.o: private skip_gendwarfksyms = 1 $(obj)/build_error.o: $(src)/build_error.rs $(obj)/compiler_builtins.o FORCE +$(call if_changed_rule,rustc_library)
Signature · 1 line
2.51.2
Miguel Ojeda
maintainerPATCH 2/2 rust: kbuild: workaround `rustdoc` doctests modifier bug
The rustdoc modifiers bug [1] was fixed in Rust 1.90.0 [2], for which we added a workaround in commit abbf9a449441 ("rust: workaround rustdoc target modifiers bug").
However, rustdoc's doctest generation still has a similar issue [3], being fixed at [4], which does not affect us because we apply the workaround to both, and now, starting with Rust 1.91.0 (released 2025-10-30), -Zsanitizer is a target modifier too [5], which means we fail with:
RUSTDOC TK rust/kernel/lib.rs
error: mixing -Zsanitizer will cause an ABI mismatch in crate kernel
--> rust/kernel/lib.rs:3:1
|
3 | //! The kernel crate.
| ^
|
= 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
A simple way around is to add the sanitizer to the list in the existing workaround (especially if we had not started to pass the sanitizer flags in the previous commit, since in that case that would not be necessary). However, that still applies the workaround in more cases than necessary.
Instead, only modify the doctests flags to ignore the check for sanitizers, so that it is more local (and thus the compiler keeps checking it for us in the normal rustdoc calls). Since the previous commit already treated the rustdoc calls as kernel objects, this should allow us in the future to easily remove this workaround when the time comes.
By the way, the -Cunsafe-allow-abi-mismatch flag overwrites previous ones rather than appending, so it needs to be all done in the same flag. Moreover, unknown modifiers are rejected, and thus we have to gate based on the version too.
Finally, -Zsanitizer-cfi-normalize-integers is not affected, so it is not needed in the workaround.
--- rust/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
rust/Makefile +4 -1
@@ -69,6 +69,9 @@ core-edition := $(if $(call rustc-min-version,108700),2024,2021) # the time being (https://github.com/rust-lang/rust/issues/144521). rustdoc_modifiers_workaround := $(if $(call rustc-min-version,108800),-Cunsafe-allow-abi-mismatch=fixed-x18) +# Similarly, for doctests (https://github.com/rust-lang/rust/issues/146465). +doctests_modifiers_workaround := $(rustdoc_modifiers_workaround)$(if $(call rustc-min-version,109100),$(comma)sanitizer) + # `rustc` recognizes `--remap-path-prefix` since 1.26.0, but `rustdoc` only # since Rust 1.81.0. Moreover, `rustdoc` ICEs on out-of-tree builds since Rust # 1.82.0 (https://github.com/rust-lang/rust/issues/138520). Thus workaround both
@@ -236,7 +239,7 @@ quiet_cmd_rustdoc_test_kernel = RUSTDOC TK $< --extern bindings --extern uapi \ --no-run --crate-name kernel -Zunstable-options \ --sysroot=/dev/null \ - $(rustdoc_modifiers_workaround) \ + $(doctests_modifiers_workaround) \ --test-builder $(objtree)/scripts/rustdoc_test_builder \ $< $(rustdoc_test_kernel_quiet); \ $(objtree)/scripts/rustdoc_test_gen
Signature · 1 line
2.51.2
Re: [PATCH 2/2] rust: kbuild: workaround `rustdoc` doctests modifier bug
Quoted 34 lines · Miguel Ojeda
The
rustdocmodifiers bug [1] was fixed in Rust 1.90.0 [2], for which we added a workaround in commitabbf9a449441("rust: workaroundrustdoctarget modifiers bug").However,
rustdoc's doctest generation still has a similar issue [3], being fixed at [4], which does not affect us because we apply the workaround to both, and now, starting with Rust 1.91.0 (released 2025-10-30),-Zsanitizeris a target modifier too [5], which means we fail with:RUSTDOC TK
rust/kernel/lib.rs
error: mixing-Zsanitizerwill cause an ABI mismatch in cratekernel
-->rust/kernel/lib.rs:3:1
|
3 | //! Thekernelcrate.
| ^
|
= help: the-Zsanitizerflag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely = note: unset-Zsanitizerin this crate is incompatible with-Zsanitizer=kernel-addressin dependencycore
= help: set-Zsanitizer=kernel-addressin this crate or unset-Zsanitizerincore
= help: if you are sure this will not cause problems, you may use-Cunsafe-allow-abi-mismatch=sanitizerto silence this errorA simple way around is to add the sanitizer to the list in the existing workaround (especially if we had not started to pass the sanitizer flags in the previous commit, since in that case that would not be necessary). However, that still applies the workaround in more cases than necessary.
Instead, only modify the doctests flags to ignore the check for sanitizers, so that it is more local (and thus the compiler keeps checking it for us in the normal
rustdoccalls). Since the previous commit already treated therustdoccalls as kernel objects, this should allow us in the future to easily remove this workaround when the time comes.
Quoted 4 lines
By the way, the
-Cunsafe-allow-abi-mismatchflag overwrites previous ones rather than appending, so it needs to be all done in the same flag. Moreover, unknown modifiers are rejected, and thus we have to gate based on the version too.
Ah .. we may want to file a bug for that.
Quoted 10 lines
Finally,
-Zsanitizer-cfi-normalize-integersis not affected, so it is not needed in the workaround.Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>
Justin Forbes
Tested-by Justin M. ForbesRe: [PATCH 2/2] rust: kbuild: workaround `rustdoc` doctests modifier bug
Quoted 54 lines · Alice Ryhl
Quoted 34 lines · Miguel Ojeda
The
rustdocmodifiers bug [1] was fixed in Rust 1.90.0 [2], for which we added a workaround in commitabbf9a449441("rust: workaroundrustdoctarget modifiers bug").However,
rustdoc's doctest generation still has a similar issue [3], being fixed at [4], which does not affect us because we apply the workaround to both, and now, starting with Rust 1.91.0 (released 2025-10-30),-Zsanitizeris a target modifier too [5], which means we fail with:RUSTDOC TK
rust/kernel/lib.rs
error: mixing-Zsanitizerwill cause an ABI mismatch in cratekernel
-->rust/kernel/lib.rs:3:1
|
3 | //! Thekernelcrate.
| ^
|
= help: the-Zsanitizerflag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely = note: unset-Zsanitizerin this crate is incompatible with-Zsanitizer=kernel-addressin dependencycore
= help: set-Zsanitizer=kernel-addressin this crate or unset-Zsanitizerincore
= help: if you are sure this will not cause problems, you may use-Cunsafe-allow-abi-mismatch=sanitizerto silence this errorA simple way around is to add the sanitizer to the list in the existing workaround (especially if we had not started to pass the sanitizer flags in the previous commit, since in that case that would not be necessary). However, that still applies the workaround in more cases than necessary.
Instead, only modify the doctests flags to ignore the check for sanitizers, so that it is more local (and thus the compiler keeps checking it for us in the normal
rustdoccalls). Since the previous commit already treated therustdoccalls as kernel objects, this should allow us in the future to easily remove this workaround when the time comes.Quoted 4 lines
By the way, the
-Cunsafe-allow-abi-mismatchflag overwrites previous ones rather than appending, so it needs to be all done in the same flag. Moreover, unknown modifiers are rejected, and thus we have to gate based on the version too.Ah .. we may want to file a bug for that.
Quoted 10 lines
Finally,
-Zsanitizer-cfi-normalize-integersis not affected, so it is not needed in the workaround.Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>
Quoted 1 line
Reviewed-by Alice Ryhl <[email protected]>
I can verify that this fixes kernel builds with rust 1.91 in Fedora.
Quoted 19 lines · Miguel Ojeda
Even if normally
build_errorisn't a kernel object, it should still be treated as such so that we pass the same flags. Similarly,rustdoctargets are never kernel objects, but we need to treat them as such.Otherwise, starting with Rust 1.91.0 (released 2025-10-30),
rustcwill complain about missing sanitizer flags since-Zsanitizeris a target modifier too [1]:error: mixing
-Zsanitizerwill cause an ABI mismatch in cratebuild_error
-->rust/build_error.rs:3:1
|
3 | //! Build-time error.
| ^
|
= help: the-Zsanitizerflag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely = note: unset-Zsanitizerin this crate is incompatible with-Zsanitizer=kernel-addressin dependencycore
= help: set-Zsanitizer=kernel-addressin this crate or unset-Zsanitizerincore
= help: if you are sure this will not cause problems, you may use-Cunsafe-allow-abi-mismatch=sanitizerto silence this error
Quoted 5 lines
Thus explicitly mark them as kernel objects.
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>
Justin Forbes
Tested-by Justin M. ForbesQuoted 21 lines · Alice Ryhl
Quoted 19 lines · Miguel Ojeda
Even if normally
build_errorisn't a kernel object, it should still be treated as such so that we pass the same flags. Similarly,rustdoctargets are never kernel objects, but we need to treat them as such.Otherwise, starting with Rust 1.91.0 (released 2025-10-30),
rustcwill complain about missing sanitizer flags since-Zsanitizeris a target modifier too [1]:error: mixing
-Zsanitizerwill cause an ABI mismatch in cratebuild_error
-->rust/build_error.rs:3:1
|
3 | //! Build-time error.
| ^
|
= help: the-Zsanitizerflag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely = note: unset-Zsanitizerin this crate is incompatible with-Zsanitizer=kernel-addressin dependencycore
= help: set-Zsanitizer=kernel-addressin this crate or unset-Zsanitizerincore
= help: if you are sure this will not cause problems, you may use-Cunsafe-allow-abi-mismatch=sanitizerto silence this error
Quoted 7 lines
Quoted 5 lines
Thus explicitly mark them as kernel objects.
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>Reviewed-by Alice Ryhl <[email protected]>
I can verify that this fixes kernel builds with rust 1.91 in Fedora.
Miguel Ojeda
AppliedQuoted 20 lines · Miguel Ojeda
Even if normally
build_errorisn't a kernel object, it should still be treated as such so that we pass the same flags. Similarly,rustdoctargets are never kernel objects, but we need to treat them as such.Otherwise, starting with Rust 1.91.0 (released 2025-10-30),
rustcwill complain about missing sanitizer flags since-Zsanitizeris a target modifier too [1]:error: mixing
-Zsanitizerwill cause an ABI mismatch in cratebuild_error
-->rust/build_error.rs:3:1
|
3 | //! Build-time error.
| ^
|
= help: the-Zsanitizerflag modifies the ABI so Rust crates compiled with different values of this flag cannot be used together safely = note: unset-Zsanitizerin this crate is incompatible with-Zsanitizer=kernel-addressin dependencycore
= help: set-Zsanitizer=kernel-addressin this crate or unset-Zsanitizerincore
= help: if you are sure this will not cause problems, you may use-Cunsafe-allow-abi-mismatch=sanitizerto silence this error
Quoted 5 lines
Thus explicitly mark them as kernel objects.
Cc [email protected] # Needed in 6.12.y and later (Rust is pinned in older LTSs).Signed-off-by Miguel Ojeda <[email protected]>
Applied series to rust-fixes -- thanks everyone!
I will send another less urgent one for 1.92.0 (in beta now) that goes on top of these here.
Cheers,
Miguel