Closed karfield closed 1 year ago
Can you find the exact instruction which causes the exception using debugger? Do you manually enable any target features (e.g. by using target-cpu=native
)?
I assume your CPU on the windows server does not support the SHA extension, correct? Can you check whether cpufeatures
detects it or not?
The cpu tested is Xeon Platinum 8269CY @ 2.5GHz.
I built by cargo +nightly build --release --target x86_64-pc-windows-gnu
, not specialized target-cpu
.
By checking with cpufeautres, it seems the cpu has SHA feature
fn main() {
cpufeatures::new!(cpuid_sha, "sha");
let token: cpuid_sha::InitToken = cpuid_sha::init();
if !token.get() {
println!("sha not supported");
} else {
println!("the cpu has sha feature");
}
let mut h = Sha256::new();
h.update(b"e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855");
let x = format!("{:x}", h.finalize());
}
the results(no backtrace shows):
the cpu has sha feature
Illegal instruction
I have No idea to use debugger on Windows yet, any suggestions to find out exact inst?
What about is_x86_feature_detected!("sha")
? According to a cursory search you have a Cascade Lake CPU and it does not support the SHA extension. So either the cpufeatures
code is somehow incorrect or your system configuration is wrong and returns incorrect CPUID data. As a temporary workaround you can enable the force-soft
feature.
What about
is_x86_feature_detected!("sha")
? According to a cursory search you have a Cascade Lake CPU and it does not support the SHA extension. So either thecpufeatures
code is somehow incorrect or your system configuration is wrong and returns incorrect CPUID data. As a temporary workaround you can enable theforce-soft
feature.
force-soft
can work temporarily. So why not detect ISA extension before using hw instruction (e.g. SHA) rather than throws 'Illegal instruction' ?
@karfield that’s exactly what cpufeatures
is supposed to do, but it seems there’s a bug where it’s getting a false positive.
Can you check is_x86_feature_detected!("sha")
to see if it works or has the same problem?
@tarcieri is_x86_feature_detected!("sha") returns true
, but cpu-z shows no SHA extension
No idea what's happening then. Is there some sort of virtualization involved?
I use cloud hosted Windows which sold as 'bare-metal' service, should not on virtualization. I closed this as not a bug for sha2
anyway.
Not sure what's happening then, but it seems like there is a discrepancy between what CPUID is reporting and what instructions are actually available
"Illegal instruction" in windows-server 2019 prompted when I simply use sha2:
sha2 version: 0.10.6 rust version:1.68.0 cross target: x86_64-pc-windows-gnu host env: linux-mingw64
expect: should be tested okay in win* targets.