Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable introspecting pulley at runtime #9886

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/c-api/include/wasmtime/config.h
Original file line number Diff line number Diff line change
@@ -382,8 +382,6 @@ wasmtime_config_cache_config_load(wasm_config_t *, const char *);

#endif // WASMTIME_FEATURE_CACHE

#ifdef WASMTIME_FEATURE_COMPILER

/**
* \brief Configures the target triple that this configuration will produce
* machine code for.
@@ -398,6 +396,8 @@ wasmtime_config_cache_config_load(wasm_config_t *, const char *);
*/
WASMTIME_CONFIG_PROP(wasmtime_error_t *, target, const char *)

#ifdef WASMTIME_FEATURE_COMPILER

/**
* \brief Enables a target-specific flag in Cranelift.
*
6 changes: 6 additions & 0 deletions crates/c-api/include/wasmtime/engine.h
Original file line number Diff line number Diff line change
@@ -35,6 +35,12 @@ WASM_API_EXTERN wasm_engine_t *wasmtime_engine_clone(wasm_engine_t *engine);
*/
WASM_API_EXTERN void wasmtime_engine_increment_epoch(wasm_engine_t *engine);

/**
* \brief Returns whether this engine is using the Pulley interpreter to execute
* WebAssembly code.
*/
WASM_API_EXTERN bool wasmtime_engine_is_pulley(wasm_engine_t *engine);

#ifdef __cplusplus
} // extern "C"
#endif
1 change: 0 additions & 1 deletion crates/c-api/src/config.rs
Original file line number Diff line number Diff line change
@@ -249,7 +249,6 @@ pub extern "C" fn wasmtime_config_native_unwind_info_set(c: &mut wasm_config_t,
}

#[no_mangle]
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub unsafe extern "C" fn wasmtime_config_target_set(
c: &mut wasm_config_t,
target: *const c_char,
5 changes: 5 additions & 0 deletions crates/c-api/src/engine.rs
Original file line number Diff line number Diff line change
@@ -47,3 +47,8 @@ pub extern "C" fn wasmtime_engine_clone(engine: &wasm_engine_t) -> Box<wasm_engi
pub extern "C" fn wasmtime_engine_increment_epoch(engine: &wasm_engine_t) {
engine.engine.increment_epoch();
}

#[no_mangle]
pub extern "C" fn wasmtime_engine_is_pulley(engine: &wasm_engine_t) -> bool {
engine.engine.is_pulley()
}
6 changes: 2 additions & 4 deletions crates/cli-flags/src/lib.rs
Original file line number Diff line number Diff line change
@@ -568,10 +568,8 @@ impl CommonOptions {
collector => config.collector(collector),
_ => err,
}
match_feature! {
["cranelift" : &self.target]
target => config.target(target)?,
_ => err,
if let Some(target) = &self.target {
config.target(target)?;
}
match_feature! {
["cranelift" : self.codegen.cranelift_debug_verifier]
13 changes: 6 additions & 7 deletions crates/wasmtime/src/config.rs
Original file line number Diff line number Diff line change
@@ -126,6 +126,7 @@ impl core::hash::Hash for ModuleVersionStrategy {
pub struct Config {
#[cfg(any(feature = "cranelift", feature = "winch"))]
compiler_config: CompilerConfig,
target: Option<target_lexicon::Triple>,
#[cfg(feature = "gc")]
collector: Collector,
profiling_strategy: ProfilingStrategy,
@@ -171,7 +172,6 @@ pub struct Config {
#[derive(Debug, Clone)]
struct CompilerConfig {
strategy: Option<Strategy>,
target: Option<target_lexicon::Triple>,
settings: HashMap<String, String>,
flags: HashSet<String>,
#[cfg(all(feature = "incremental-cache", feature = "cranelift"))]
@@ -185,7 +185,6 @@ impl CompilerConfig {
fn new() -> Self {
Self {
strategy: Strategy::Auto.not_auto(),
target: None,
settings: HashMap::new(),
flags: HashSet::new(),
#[cfg(all(feature = "incremental-cache", feature = "cranelift"))]
@@ -230,6 +229,7 @@ impl Config {
tunables: ConfigTunables::default(),
#[cfg(any(feature = "cranelift", feature = "winch"))]
compiler_config: CompilerConfig::default(),
target: None,
#[cfg(feature = "gc")]
collector: Collector::default(),
#[cfg(feature = "cache")]
@@ -305,9 +305,8 @@ impl Config {
/// # Errors
///
/// This method will error if the given target triple is not supported.
#[cfg(any(feature = "cranelift", feature = "winch"))]
pub fn target(&mut self, target: &str) -> Result<&mut Self> {
self.compiler_config.target =
self.target =
Some(target_lexicon::Triple::from_str(target).map_err(|e| anyhow::anyhow!(e))?);

Ok(self)
@@ -2053,10 +2052,10 @@ impl Config {
}

/// Returns the configured compiler target for this `Config`.
fn compiler_target(&self) -> target_lexicon::Triple {
pub(crate) fn compiler_target(&self) -> target_lexicon::Triple {
// If a target is explicitly configured, always use that.
#[cfg(any(feature = "cranelift", feature = "winch"))]
if let Some(target) = self.compiler_config.target.clone() {
if let Some(target) = self.target.clone() {
return target;
}

@@ -2256,7 +2255,7 @@ impl Config {
// specified (which indicates no feature inference) and the target
// matches the host.
let target_for_builder =
if self.compiler_config.target.is_none() && target == target_lexicon::Triple::host() {
if self.target.is_none() && target == target_lexicon::Triple::host() {
None
} else {
Some(target.clone())
22 changes: 13 additions & 9 deletions crates/wasmtime/src/engine.rs
Original file line number Diff line number Diff line change
@@ -16,7 +16,7 @@ use object::SectionKind;
use std::{fs::File, path::Path};
use wasmparser::WasmFeatures;
use wasmtime_environ::obj;
use wasmtime_environ::{FlagValue, ObjectKind, Tunables};
use wasmtime_environ::{FlagValue, ObjectKind, TripleExt, Tunables};

mod serialization;

@@ -223,13 +223,7 @@ impl Engine {
/// Returns the target triple which this engine is compiling code for
/// and/or running code for.
pub(crate) fn target(&self) -> target_lexicon::Triple {
// If a compiler is configured, use that target.
#[cfg(any(feature = "cranelift", feature = "winch"))]
return self.compiler().triple().clone();

// ... otherwise it's the native target
#[cfg(not(any(feature = "cranelift", feature = "winch")))]
return target_lexicon::Triple::host();
return self.config().compiler_target();
}

/// Verify that this engine's configuration is compatible with loading
@@ -258,7 +252,6 @@ impl Engine {
#[cfg(any(feature = "cranelift", feature = "winch"))]
{
use target_lexicon::Triple;
use wasmtime_environ::TripleExt;

let compiler = self.compiler();

@@ -529,6 +522,17 @@ impl Engine {
)),
}
}

/// Returns whether this [`Engine`] is configured to execute with Pulley,
/// Wasmtime's interpreter.
///
/// Note that Pulley is the default for host platforms that do not have a
/// Cranelift backend to support them. For example at the time of this
/// writing 32-bit x86 is not supported in Cranelift so the
/// `i686-unknown-linux-gnu` target would by default return `true` here.
pub fn is_pulley(&self) -> bool {
self.target().is_pulley()
}
}

#[cfg(any(feature = "cranelift", feature = "winch"))]