Always STATUS_ACCESS_VIOLATION error in "cargo build"

Suddenly after upgrading rustup to ver 1.83, I got a strange error when I try to build any rust code even if it is a "hello world" example.

The error after "cargo build" for 'hello world' sample is,

D:\tmp\test1>cargo build
   Compiling test1 v0.1.0 (D:\tmp\test1)
error: could not compile `test1` (bin "test1")

Caused by:
  process didn't exit successfully: `C:\Users\hj7.park\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\rustc.exe --crate-name test1 --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=119 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg cfg(docsrs) --check-cfg "cfg(feature, values())" -C metadata=99d5b0c255016219 --out-dir D:\tmp\test1\target\debug\deps -C incremental=D:\tmp\test1\target\debug\incremental -L dependency=D:\tmp\test1\target\debug\deps` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

D:\tmp\test1>rustc --version
rustc 1.83.0 (90b35a623 2024-11-26)

To solve this problem, I tried below but it is not solved yet,

  • uninstall all rust toolchain with "rustup self uninstall" and re-install rust.
  • re-install to another version of rust such as v1.50
  • remove all "C++ build tool" and re-install it.
  • try to build in the another hard drive, that is, "d:" drive to "c:" drive

I can't find any more tring to solve this problem.

The reason why I tried to upgrade rust version was to use Rc::new_ininit() function which is written to be supported from v1.82.
So, I upgraded my rust version using "rustup update".
After that I tested my code as below:

#![feature(get_mut_unchecked)]

use std::rc::Rc;

fn main() {
    let mut five = Rc::<u32>::new_uninit();

    // Deferred initialization:
    Rc::get_mut(&mut five).unwrap().write(5);

    let five = unsafe { five.assume_init() };

    assert_eq!(*five, 5)
}

After that, my rust executing environment is crashed. Any code couldn't be built even though a sample "hello word" code, and even though I down-graded the rust version to v1.5 and v1.7 but the problem is same.

Could anyone can suggest what can I try more ?

Have you cleaned compilation caches in between toolchain updates?

1 Like

I tried "cargo clean" and after that "cargo build" but it didn't work.
And also, after re-installation for new rust version, I made a new project with "cargo new test1" and tried to build it but it faild with the same error.
Just making a new project with "cargo new test1" and then without any modification of the code, I tried to build it, but it faild neither.

Do you, by any chance, have a 13th of 14th generation Intel CPU?

1 Like

Potentially relevant, Windows __fastfail (an intrinsic Rust abort/rtabort!) causes a program abort via STATUS_ACCESS_VIOLATION.

Something has gone horribly wrong if a full uninstall and reinstall of rustup means that even old toolchains that previously worked are crashing. I suspect that's not the case, and you're accidentally running not the toolchain of Rust you think you are.

1 Like

my CPU is, "11th Gen Intel(R) Core(TM) i7-11600H @ 2.90GHz 2.92 GHz"

To ensure that I'm not accidentally running a strange toolchain for rust, I did once again as below steps, but the problem is same.

1)uninstall current Rust toolchain by "rustup self uninstall"

2)check if there is any remained Rust executable in my PC

  • rustc --> not working
  • cargo --> not working

3)install again with 'rustup-init.exe' with default option
There are two warnings during installation.

...
info: profile set to 'complete'
info: setting default host triple to x86_64-pc-windows-msvc
info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
info: latest update on 2024-11-28, rust version 1.83.0 (90b35a623 2024-11-26)
warning: Force-skipping unavailable component 'miri-x86_64-pc-windows-msvc'
warning: Force-skipping unavailable component 'rustc-codegen-cranelift-x86_64-pc-windows-msvc'
info: downloading component 'cargo'
info: downloading component 'clippy'

4)make a new project with 'cargo new test2' and build it

D:\tmp>cargo new test2
    Creating binary (application) `test2` package
note: see more `Cargo.toml` keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

D:\tmp>cd test2

D:\tmp\test2>cargo build
   Compiling test2 v0.1.0 (D:\tmp\test2)
error: could not compile `test2` (bin "test2")

Caused by:
  process didn't exit successfully: `C:\Users\hj7.park\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\rustc.exe --crate-name test2 --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=119 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg cfg(docsrs) --check-cfg "cfg(feature, values())" -C metadata=da726d1c57389c3a --out-dir D:\tmp\test2\target\debug\deps -C incremental=D:\tmp\test2\target\debug\incremental -L dependency=D:\tmp\test2\target\debug\deps` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

In the above, during installation, there were two warngins:

warning: Force-skipping unavailable component 'miri-x86_64-pc-windows-msvc'
warning: Force-skipping unavailable component 'rustc-codegen-cranelift-x86_64-pc-windows-msvc'

Could this warning be related to the problem?
Then, how can I install without these warngings?

these should not be the problem, these two components are not essential for the toolchain to work.

based on your description, my guess is the it is probably due to some system files (e.g. essential dll libraries) being corrupted (or hijacked). did you recently update the operating system or any system software (such as hardware drivers, firewalls, or anti-virus)?

also, is there any log entries in the system event viewer? especially, in what module (i.e. which exe or dll file) did the exception happen?

1 Like

There was no OS update nor patch update.

1)(22:00) I was testing some code in VS Code and wanted to make Rc object with no argument.
--> this time, there was no problem to make code and build in the VS Code.
2)(22:10) I found "Rc::get_mut()" method is supported from the version 1.82 in the Rust doc site.
3)(22:15) I updated rust version using "rustup update" while VS Code programm is running.
4)(22:20)after updating, in the VS Code, I coded like below (I couldn't remember exact code)

#![feature(get_mut_unchecked)]
fn main(){
    let mut r = Rc::<String>::new_uninit();
    Rc::get_mut(&mut r).unwrap().write("hello");
    let s1 = unsafe ( r.assume_init() };

    let s2 = Rc::clone(&s1);
    let s3 = Rc::clone(&s1);

    println!("{s1}");
    println!("{s2}");
    println!("{s3}");
}
  1. (22:25) With the above code, I pressed "Run" button in the VS Code, and then, there was a error message in the VS Code. That was a starting the error occurance and after that I can't build anything

If I guess too much, I can think of whether Rc's assume_init() or clone() has damaged OS dll, but I'll have to look through the log file of Windows as you advised.

A couple other steps:

  • When testing Rust compilation, try using rustc instead of cargo by creating a new file test.rs with a hello world, then rustc test.rs.
  • After rustup self uninstall, try clearing any .cargo or .rustup folders in your user directory before reinstalling Rust.
  • Windows has tools to verify your system files. It will also fix corruption issues for you.
1 Like

I did as your guide, but it didn't work neither.

  • When testing Rust compilation, try using rustc instead of cargo by creating a new file test.rs with a hello world, then rustc test.rs.

I made a "test.rs" file with text editor not using cargo and comiled it with 'rustc' but it didn't work. There was no error message but there was no exe file generated. After "rustc src\test.rs", a strange folder named "rmeta00ETvZ" was generated but it contains no files in it.

  • After rustup self uninstall, try clearing any .cargo or .rustup folders in your user directory before reinstalling Rust.

Yes, I checked the folders were gone after "rustup self uninstall" in my folder.

  • Windows has tools to verify your system files. It will also fix corruption issues for you.

Yes, I did as the guide.

  1. Update all the remaining Windows updates in the "Update Windows" page. It took around 30 mins.
  2. Clean the system with "DIM.exe" and "sfc /scannow"

All of them was invalid. Additionally I changed "windows/system32/ntdll.dll" file with another PC's ntdll.dll file. But it didn't work neither.

In the Windows system log, I couldn't find what dll file was damaged but only find the time when the error was started.At that time, the error message is just "error: rustc.exe" and "error: ntdll.dll". So, I deleted 'ntdll.dll' file and copied newly from the another PC. But, it didn't work neither.

I think some dll file was damaged but I couldn't fild it.
Maybe, there is only thing remaind : re-install my Windows newly. :sob:

Oof, that is not something you ever want to do, that can only ever make it worse. error: ntdll.dll doesn't mean that the DLL is bad, just that an error happened in code owned in that DLL, but the error could result from someone calling into the DLL incorrectly.

You don't ever modify OS/system files manually.

Thankfully, modern Windows supports installation which doesn't touch/lose most user data, it just reinstalls all of the system files. Given you suspect OS corruption and the tools to verify system files weren't able to fix the issue, that seems like a reasonable (if annoying and time consuming) thing to try.

Hopefully it isn't a hardware issue.

4 Likes

I re-installed Windows 11 newly, it took around 2 hours, thanks to I divided C drive and D drive and it was easy b/c I can install Windows by formatting only the C drive and not deleting the data on the D drive.
The first thing I did after reinstalling Windows was that install the Rust toolchains and testing the 'Cargo build'. But, I got the same error. Oh no!!!!

C:\tmp\test1>cargo build
   Compiling test1 v0.1.0 (C:\tmp\test1)
error: could not compile `test1` (bin "test1")

Caused by:
  process didn't exit successfully: `C:\Users\hj7.park\.rustup\toolchains\stable-x86_64-pc-windows-msvc\bin\rustc.exe --crate-name test1 --edition=2021 src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --diagnostic-width=119 --crate-type bin --emit=dep-info,link -C embed-bitcode=no -C debuginfo=2 --check-cfg cfg(docsrs) --check-cfg "cfg(feature, values())" -C metadata=99d5b0c255016219 --out-dir C:\tmp\test1\target\debug\deps -C incremental=C:\tmp\test1\target\debug\incremental -L dependency=C:\tmp\test1\target\debug\deps` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)

Compiling by 'rustc' is also not working. By the command of rustc src\main.rs, there was no reply from the rustc and only a strange folder is generated. That's it. The folder name is "rmetaf4hy3k".

C:\tmp\test1>rustc src\main.rs

C:\tmp\test1>dir /w

[.]           [..]          .gitignore    Cargo.lock    Cargo.toml    [rmetaf4hy3K] [src]         [target]
              

The main.rs code is made by default command of cargo new test1.

fn main() {
    println!("Hello, world!");
}

Re-install Windows > install "MS C++ build tools" > install Rust by 'rustup_init.exe' > Test > Error

I can't find no more solution. My laptop is not changed anything. Suddenly 'cargo build' has been not working from one time after doing after rust version up and test some code.

Could someone guide me what can I do more to solve this problem?

What sort of anti-malware software is installed?

1 Like

"AhnLab V3 Internet Security 9.0" is installed which is the default Anti-mallware s/w in our company.

I'll try to remove it and re-test Rust build now.
--> I removed "AhnLab V3 Internet Security 9.0" program and test "Cargo build" again but it didn't work neither.

The only remaining the creepy program is a DRM software which is default program by our company's policy, but I can't remove this program. It's locked not to remove.
However, other PC's are OK even though it is installed the DRM software.

I tested it on the another PC in our company. The result is the same error came out. !!!!

Maybe, out company's security policy was changed suddenly, and it cause the problem.
The suspicious programs are ESCORT(PC Management S/W), NASCA(PC DRM S/W).
These security software is so annoying, I couldn't understand why these kind of S/W are used. :frowning:

I'll try to solve the problem, and I'll report the result again in here. Thanks ..

I don't know about the company's policy, just a reminder:

you can install rust under WSL2, you can still cross-compile .exe files for Windows, but with extra efforts. if you decided to go this way, you can learn how to setup the Windows SDK with rust in this blog post:

https://jake-shadle.github.io/xwin/

oh, as a last resort, you can do your rust development in a VM, if all other attempts failed.

4 Likes

The problem is very likely a buggy application that is injecting code into every running program. If that’s true then it’s a security vulnerability.

I believe there’s a way to get Windows to emit a stack dump for exceptions like the one you’re seeing. That may help.

1 Like

Good guide. I'll try to install WSL2 and over there install Rust. If I success, I'll let you know.
Thanks.