win_driver_example
win_driver_example copied to clipboard
LNK2001: unresolved external symbol _fltused
When using rustc 1.43.0-nightly (e02974078 2020-02-18) and running cargo xbuild --target x86_64-kernel-windows-msvc.json on a new clone of master, I get the following linker error:
LNK2001: unresolved external symbol _fltused
= note: LINK : warning LNK4216: Exported entry point DriverEntry Creating object D:\dev\rust\win_driver_example\target\x86_64-kernel-windows-msvc\debug\deps\win_driver_example.dll.exp libcompiler_builtins-a5dc3a27f854a583.rlib(compiler_builtins-a5dc3a27f854a583.compiler_builtins.2hb76v1n-cgu.12.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcompiler_builtins-a5dc3a27f854a583.rlib(compiler_builtins-a5dc3a27f854a583.compiler_builtins.2hb76v1n-cgu.4.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcompiler_builtins-a5dc3a27f854a583.rlib(compiler_builtins-a5dc3a27f854a583.compiler_builtins.2hb76v1n-cgu.14.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcompiler_builtins-a5dc3a27f854a583.rlib(compiler_builtins-a5dc3a27f854a583.compiler_builtins.2hb76v1n-cgu.1.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcompiler_builtins-a5dc3a27f854a583.rlib(compiler_builtins-a5dc3a27f854a583.compiler_builtins.2hb76v1n-cgu.13.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcompiler_builtins-a5dc3a27f854a583.rlib(compiler_builtins-a5dc3a27f854a583.compiler_builtins.2hb76v1n-cgu.2.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcompiler_builtins-a5dc3a27f854a583.rlib(compiler_builtins-a5dc3a27f854a583.compiler_builtins.2hb76v1n-cgu.9.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcore-7339924e45ccdcb4.rlib(core-7339924e45ccdcb4.core.e6t8h8ow-cgu.12.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcore-7339924e45ccdcb4.rlib(core-7339924e45ccdcb4.core.e6t8h8ow-cgu.3.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcompiler_builtins-a5dc3a27f854a583.rlib(compiler_builtins-a5dc3a27f854a583.compiler_builtins.2hb76v1n-cgu.15.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcompiler_builtins-a5dc3a27f854a583.rlib(compiler_builtins-a5dc3a27f854a583.compiler_builtins.2hb76v1n-cgu.0.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcore-7339924e45ccdcb4.rlib(core-7339924e45ccdcb4.core.e6t8h8ow-cgu.7.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcore-7339924e45ccdcb4.rlib(core-7339924e45ccdcb4.core.e6t8h8ow-cgu.14.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcore-7339924e45ccdcb4.rlib(core-7339924e45ccdcb4.core.e6t8h8ow-cgu.6.rcgu.o) : error LNK2001: unresolved external symbol _fltused libcore-7339924e45ccdcb4.rlib(core-7339924e45ccdcb4.core.e6t8h8ow-cgu.5.rcgu.o) : error LNK2001: unresolved external symbol _fltused D:\dev\rust\win_driver_example\target\x86_64-kernel-windows-msvc\debug\deps\win_driver_example.sys : fatal error LNK1120: 1 unresolved externals error: aborting due to previous error
It looks like I'm experiencing the same problem demonstrated here, which I guess is an LLVM/Rust-core issue that uses floating point calculations - which aren't allowed when running in the Windows Kernel. I'm fairly new to Rust and therefore not sure how to handle this properly.
As demonstrated in the link I managed to work around the error by adding the following snippet to my lib.rs:
#[used]
#[no_mangle]
static _fltused: i32 = 0;
Thanks. Will fix it in the repository.
I believe that using the hack I described above is not safe, since the usage of MMX\SSE instructions might actually cause corruptions in certain conditions when running in the Kernel.
Defining _fltused will not do it in the long run.