Skip to content

Commit

Permalink
Bug 1663919: Report cranelift verifier errors as panics in debug buil…
Browse files Browse the repository at this point in the history
…ds; r=cfallin

Differential Revision: https://phabricator.services.mozilla.com/D89593
  • Loading branch information
bnjbvr committed Sep 9, 2020
1 parent 81ffbd9 commit 04b1352
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions js/src/wasm/cranelift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ use std::ptr;

use crate::bindings::{CompiledFunc, FuncCompileInput, ModuleEnvironment, StaticEnvironment};
use crate::compile::BatchCompiler;
use cranelift_codegen::CodegenError;

/// Initializes all the process-wide Cranelift state. It must be called at least once, before any
/// other use of this crate. It is not an issue if it is called more than once; subsequent calls
Expand Down Expand Up @@ -218,9 +219,21 @@ pub unsafe extern "C" fn cranelift_compile_function(
};

if let Err(e) = compiler.compile(data.stackmaps()) {
error!("Cranelift compilation error: {}\n", e);
info!("Compiled function: {}", compiler);
return false;
// Make sure to panic on verifier errors, so that fuzzers see those. Other errors are about
// unsupported features or implementation limits, so just report them as a user-facing
// error.
match e {
CodegenError::Verifier(verifier_error) => {
panic!("Cranelift verifier error: {}", verifier_error);
}
CodegenError::ImplLimitExceeded
| CodegenError::CodeTooLarge
| CodegenError::Unsupported(_) => {
error!("Cranelift compilation error: {}\n", e);
info!("Compiled function: {}", compiler);
return false;
}
}
};

// TODO(bbouvier) if destroy is called while one of these objects is alive, you're going to
Expand Down

0 comments on commit 04b1352

Please sign in to comment.