From 3a9486b7712f0328a96fe33449ce191385096f75 Mon Sep 17 00:00:00 2001 From: Andrew Mackenzie Date: Wed, 16 Sep 2026 08:21:45 +0200 Subject: [PATCH] Provide wcslen for x86_64-unknown-uefi target The uefi crate's FileInfo::from_uefi and RegularFile::get_info reference wcslen for wide string length calculation. The x86_64-unknown-uefi target has no C runtime providing this symbol, causing a linker error. Add a simple wcslen implementation to the UEFI bootloader binary. Use #[unsafe(no_mangle)] for compatibility with Rust 2024 edition. Fixes: https://github.com/rust-osdev/bootloader/issues/579 --- uefi/src/main.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/uefi/src/main.rs b/uefi/src/main.rs index 13a28526..db128a34 100644 --- a/uefi/src/main.rs +++ b/uefi/src/main.rs @@ -445,3 +445,20 @@ fn panic(info: &core::panic::PanicInfo) -> ! { unsafe { asm!("cli; hlt") }; } } + +/// Provide `wcslen` for the `uefi` crate which needs it for wide string +/// handling (e.g. `FileInfo::from_uefi`). The `x86_64-unknown-uefi` target +/// has no C runtime, so this must be supplied explicitly. +/// +/// See: https://github.com/rust-osdev/bootloader/issues/579 +#[unsafe(no_mangle)] +pub unsafe extern "C" fn wcslen(s: *const u16) -> usize { + let mut len = 0; + // SAFETY: caller guarantees `s` points to a null-terminated wide string. + unsafe { + while *s.add(len) != 0 { + len += 1; + } + } + len +}