Skip to content

Commit b236920

Browse files
committed
Merge tag 'rust-fixes-6.17-2' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux
Pull rust fixes from Miguel Ojeda: - Two changes to prepare for the future Rust 1.91.0 release (expected 2025-10-30, currently in nightly): a target specification format change and a renamed, soon-to-be-stabilized 'core' function. * tag 'rust-fixes-6.17-2' of git://git.kernel.org/pub/scm/linux/kernel/git/ojeda/linux: rust: support Rust >= 1.91.0 target spec rust: use the new name Location::file_as_c_str() in Rust >= 1.91.0
2 parents d1d10ce + 8851e27 commit b236920

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

init/Kconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ config RUSTC_HAS_UNNECESSARY_TRANSMUTES
146146
config RUSTC_HAS_FILE_WITH_NUL
147147
def_bool RUSTC_VERSION >= 108900
148148

149+
config RUSTC_HAS_FILE_AS_C_STR
150+
def_bool RUSTC_VERSION >= 109100
151+
149152
config PAHOLE_VERSION
150153
int
151154
default $(shell,$(srctree)/scripts/pahole-version.sh $(PAHOLE))

rust/kernel/lib.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ macro_rules! asm {
296296

297297
/// Gets the C string file name of a [`Location`].
298298
///
299-
/// If `file_with_nul()` is not available, returns a string that warns about it.
299+
/// If `Location::file_as_c_str()` is not available, returns a string that warns about it.
300300
///
301301
/// [`Location`]: core::panic::Location
302302
///
@@ -310,8 +310,8 @@ macro_rules! asm {
310310
/// let caller = core::panic::Location::caller();
311311
///
312312
/// // Output:
313-
/// // - A path like "rust/kernel/example.rs" if file_with_nul() is available.
314-
/// // - "<Location::file_with_nul() not supported>" otherwise.
313+
/// // - A path like "rust/kernel/example.rs" if `file_as_c_str()` is available.
314+
/// // - "<Location::file_as_c_str() not supported>" otherwise.
315315
/// let caller_file = file_from_location(caller);
316316
///
317317
/// // Prints out the message with caller's file name.
@@ -326,14 +326,19 @@ macro_rules! asm {
326326
/// ```
327327
#[inline]
328328
pub fn file_from_location<'a>(loc: &'a core::panic::Location<'a>) -> &'a core::ffi::CStr {
329-
#[cfg(CONFIG_RUSTC_HAS_FILE_WITH_NUL)]
329+
#[cfg(CONFIG_RUSTC_HAS_FILE_AS_C_STR)]
330+
{
331+
loc.file_as_c_str()
332+
}
333+
334+
#[cfg(all(CONFIG_RUSTC_HAS_FILE_WITH_NUL, not(CONFIG_RUSTC_HAS_FILE_AS_C_STR)))]
330335
{
331336
loc.file_with_nul()
332337
}
333338

334339
#[cfg(not(CONFIG_RUSTC_HAS_FILE_WITH_NUL))]
335340
{
336341
let _ = loc;
337-
c"<Location::file_with_nul() not supported>"
342+
c"<Location::file_as_c_str() not supported>"
338343
}
339344
}

scripts/generate_rust_target.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,11 @@ fn main() {
225225
ts.push("features", features);
226226
ts.push("llvm-target", "x86_64-linux-gnu");
227227
ts.push("supported-sanitizers", ["kcfi", "kernel-address"]);
228-
ts.push("target-pointer-width", "64");
228+
if cfg.rustc_version_atleast(1, 91, 0) {
229+
ts.push("target-pointer-width", 64);
230+
} else {
231+
ts.push("target-pointer-width", "64");
232+
}
229233
} else if cfg.has("X86_32") {
230234
// This only works on UML, as i386 otherwise needs regparm support in rustc
231235
if !cfg.has("UML") {
@@ -245,7 +249,11 @@ fn main() {
245249
}
246250
ts.push("features", features);
247251
ts.push("llvm-target", "i386-unknown-linux-gnu");
248-
ts.push("target-pointer-width", "32");
252+
if cfg.rustc_version_atleast(1, 91, 0) {
253+
ts.push("target-pointer-width", 32);
254+
} else {
255+
ts.push("target-pointer-width", "32");
256+
}
249257
} else if cfg.has("LOONGARCH") {
250258
panic!("loongarch uses the builtin rustc loongarch64-unknown-none-softfloat target");
251259
} else {

0 commit comments

Comments
 (0)