Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

STATUS_ACCESS_VIOLATION in cranelift-codegen build script #900

Closed
novacrazy opened this issue Aug 15, 2019 · 12 comments
Closed

STATUS_ACCESS_VIOLATION in cranelift-codegen build script #900

novacrazy opened this issue Aug 15, 2019 · 12 comments
Labels
bug A bug or panic in the compiler or generated code. meta Everything related to the meta-language.

Comments

@novacrazy
Copy link

novacrazy commented Aug 15, 2019

When attempting to add cranelift to a project of mine for use as a JIT compiler, I get:

error: failed to run custom build command for `cranelift-codegen v0.38.0`

Caused by:
  process didn't exit successfully: `F:\code\projects\active\untitled\target\debug\build\cranelift-codegen-c6b973378c2b1052\build-script-build` (exit code: 0xc0000005, STATUS_ACCESS_VIOLATION)
--- stdout
cargo:rerun-if-changed=C:\Users\novacrazy\.cargo\registry\src\github.com-1ecc6299db9ec823\cranelift-codegen-0.38.0\build.rs

warning: build failed, waiting for other jobs to finish...
error: build failed

This seems to be caused by my build configuration in Cargo.toml:

[profile.dev]
debug = true
opt-level = 2
incremental = false
debug-assertions = true
codegen-units = 32

[profile.release]
opt-level = 3
debug = true # helps with profiling
lto = 'fat'
incremental = false
debug-assertions = false
codegen-units = 1

[profile.bench]
opt-level = 3
debug = false
lto = 'fat'
debug-assertions = false
incremental = false
codegen-units = 1

which upon adding to the SimpleJIT demo config causes the same STATUS_ACCESS_VIOLATION

I'm on Windows 10 Pro for Workstations with a AMD Zen 1 Threadripper 1950X, compiling with RUSTFLAGS = "-C target-cpu=native", so znver1.

Compiling without target-cpu=native seems to work, but I kind of use that...

So it's a mix of those config options and target-cpu=native.

I'm using rustc 1.38.0-nightly (60960a260 2019-08-12), which is after an LLVM update known to cause issues on Zen 1

@novacrazy
Copy link
Author

No, just tested it on an older version before that LLVM update, and the STATUS_ACCESS_VIOLATION still occurs, so it's not LLVM.

@sunfishcode
Copy link
Member

This is the first report of such a problem, so I don't know what might be causing it.

Are you able to run the build-script-build program in a debugger? It needs the TARGET environment variable set to your target triple, possibly "x86_64-pc-windows-msvc", and OUT_DIR set to the path of an empty directory. It would be interesting if we could determine where it's failing.

@novacrazy
Copy link
Author

To be honest all I have to debug it is Visual Studio, and I'm not well versed on how to use that with Rust.

Given the stdout in the build error message, though, it seems to fail at this piece of code:

if let Err(err) = meta::generate(&isas, &out_dir) {
    eprintln!("Error: {}", err);
    process::exit(1);
}

so it got past the environment variable checks.

@novacrazy
Copy link
Author

I've narrowed it down to this chunk of code in cranelift\cranelift-codegen\meta\src\shared\legalize.rs

for cc in &["eq", "ne", "ugt", "ult", "uge", "ule"] {
    let w_cc = Literal::enumerator_for(intcc, cc);
    widen.legalize(
        def!(a = icmp_imm.int_ty(w_cc, b, c)),
        vec![def!(x = uextend.I32(b)), def!(a = icmp_imm(w_cc, x, c))],
    );
    widen.legalize(
        def!(a = icmp.int_ty(w_cc, b, c)),
        vec![
            def!(x = uextend.I32(b)),
            def!(y = uextend.I32(c)),
            def!(a = icmp.I32(w_cc, x, y)),
        ],
    );
}

@bnjbvr
Copy link
Member

bnjbvr commented Aug 16, 2019

Looks like a rustc compiler bug. Does it reproduce when using Rustc stable? Does it reproduce in all of your profiles with Rustc nightly?

If you add print statements to this code to print what the cc code causing this is, does it still reproduce, and if so, what's the output?

@novacrazy
Copy link
Author

It does still occur on stable rustc 1.37.0.

By adding some printlns to that code, I found the error occurs inside the first call to widen.legalize, not in the generation of the parameters.

@novacrazy
Copy link
Author

Huh. Oddly enough, this is the exact same code that is in https://github.com/CraneStation/cranelift/issues/896

@bnjbvr bnjbvr added bug A bug or panic in the compiler or generated code. meta Everything related to the meta-language. labels Aug 19, 2019
@bnjbvr
Copy link
Member

bnjbvr commented Oct 4, 2019

ping @novacrazy, does it still happen with latest Rustc, out of curiosity?

@bjorn3
Copy link
Contributor

bjorn3 commented Oct 4, 2019

#63959 is still open. And a comment from yesterday there says that it is still reproducable.

@bnjbvr
Copy link
Member

bnjbvr commented Dec 9, 2019

rust-lang/rust#63959 (comment) is solved and hopefully in the current Rust nightly.

@novacrazy Can you try again please with the latest Rust nightly, and let us know if this is fixed? Thanks!

@novacrazy
Copy link
Author

I haven’t had time to check recently, but I will soon. JIT compilation is still very much on my radar.

Given the details of the aforementioned LLVM bug, it makes sense that the error happened unexpectedly within a loop, so hopefully it will be fixed now.

@novacrazy
Copy link
Author

I think this has been fixed by that LLVM patch. It's extremely odd that it was still failing before the LLVM 9 upgrade back in August, but oh well. The SimpleJIT example compiles and runs fine now.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug A bug or panic in the compiler or generated code. meta Everything related to the meta-language.
Projects
None yet
Development

No branches or pull requests

4 participants