Skip to content

Commit e60b6e6

Browse files
authored
Enable warnings if cranelift is disabled (bytecodealliance#10157)
Continuation of work in bytecodealliance#10131.
1 parent a727985 commit e60b6e6

File tree

9 files changed

+74
-75
lines changed

9 files changed

+74
-75
lines changed

crates/environ/src/builtin.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,6 @@ macro_rules! declare_builtin_index_constructors {
253253
/// Returns a symbol name for this builtin.
254254
pub fn name(&self) -> &'static str {
255255
$(
256-
$( #[$attr] )*
257256
if *self == Self::$name() {
258257
return stringify!($name);
259258
}
@@ -286,7 +285,6 @@ macro_rules! declare_builtin_index_constructors {
286285
$rest_name:ident;
287286
)*
288287
) => {
289-
$( #[$this_attr] )*
290288
#[allow(missing_docs, reason = "macro-generated")]
291289
pub const fn $this_name() -> Self {
292290
Self($index)

crates/wasmtime/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,7 @@ std = [
327327
'wasmtime-fiber?/std',
328328
'pulley-interpreter/std',
329329
'wasmtime-math/std',
330+
'addr2line?/std',
330331
]
331332

332333
# Enables support for the `Store::call_hook` API which enables injecting custom

crates/wasmtime/src/config.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use crate::hash_map::HashMap;
2-
use crate::hash_set::HashSet;
31
use crate::prelude::*;
42
use alloc::sync::Arc;
53
use bitflags::Flags;
@@ -172,8 +170,8 @@ pub struct Config {
172170
#[derive(Debug, Clone)]
173171
struct CompilerConfig {
174172
strategy: Option<Strategy>,
175-
settings: HashMap<String, String>,
176-
flags: HashSet<String>,
173+
settings: crate::hash_map::HashMap<String, String>,
174+
flags: crate::hash_set::HashSet<String>,
177175
#[cfg(all(feature = "incremental-cache", feature = "cranelift"))]
178176
cache_store: Option<Arc<dyn CacheStore>>,
179177
clif_dir: Option<std::path::PathBuf>,
@@ -185,8 +183,8 @@ impl CompilerConfig {
185183
fn new() -> Self {
186184
Self {
187185
strategy: Strategy::Auto.not_auto(),
188-
settings: HashMap::new(),
189-
flags: HashSet::new(),
186+
settings: Default::default(),
187+
flags: Default::default(),
190188
#[cfg(all(feature = "incremental-cache", feature = "cranelift"))]
191189
cache_store: None,
192190
clif_dir: None,
@@ -2433,7 +2431,7 @@ impl Config {
24332431
compiler.enable(flag)?;
24342432
}
24352433

2436-
#[cfg(feature = "incremental-cache")]
2434+
#[cfg(all(feature = "incremental-cache", feature = "cranelift"))]
24372435
if let Some(cache_store) = &self.compiler_config.cache_store {
24382436
compiler.enable_incremental_compilation(cache_store.clone())?;
24392437
}
@@ -2629,6 +2627,7 @@ pub enum Strategy {
26292627
Winch,
26302628
}
26312629

2630+
#[cfg(any(feature = "winch", feature = "cranelift"))]
26322631
impl Strategy {
26332632
fn not_auto(&self) -> Option<Strategy> {
26342633
match self {

crates/wasmtime/src/engine.rs

Lines changed: 46 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@ pub use crate::runtime::code_memory::CustomCodeMemory;
55
use crate::runtime::type_registry::TypeRegistry;
66
#[cfg(feature = "runtime")]
77
use crate::runtime::vm::GcRuntime;
8-
use crate::sync::OnceLock;
98
use crate::Config;
109
use alloc::sync::Arc;
1110
#[cfg(target_has_atomic = "64")]
1211
use core::sync::atomic::{AtomicU64, Ordering};
1312
#[cfg(any(feature = "cranelift", feature = "winch"))]
1413
use object::write::{Object, StandardSegment};
15-
use object::SectionKind;
1614
#[cfg(feature = "std")]
1715
use std::{fs::File, path::Path};
1816
use wasmparser::WasmFeatures;
19-
use wasmtime_environ::obj;
2017
use wasmtime_environ::{FlagValue, ObjectKind, TripleExt, Tunables};
2118

2219
mod serialization;
@@ -68,7 +65,7 @@ struct EngineInner {
6865
/// One-time check of whether the compiler's settings, if present, are
6966
/// compatible with the native host.
7067
#[cfg(any(feature = "cranelift", feature = "winch"))]
71-
compatible_with_native_host: OnceLock<Result<(), String>>,
68+
compatible_with_native_host: crate::sync::OnceLock<Result<(), String>>,
7269
}
7370

7471
impl core::fmt::Debug for Engine {
@@ -134,7 +131,7 @@ impl Engine {
134131
#[cfg(all(feature = "runtime", target_has_atomic = "64"))]
135132
epoch: AtomicU64::new(0),
136133
#[cfg(any(feature = "cranelift", feature = "winch"))]
137-
compatible_with_native_host: OnceLock::new(),
134+
compatible_with_native_host: Default::default(),
138135
config,
139136
tunables,
140137
features,
@@ -251,64 +248,56 @@ impl Engine {
251248
/// engine can indeed load modules for the configured compiler (if any).
252249
/// Note that if cranelift is disabled this trivially returns `Ok` because
253250
/// loaded serialized modules are checked separately.
251+
#[cfg(any(feature = "cranelift", feature = "winch"))]
254252
pub(crate) fn check_compatible_with_native_host(&self) -> Result<()> {
255-
#[cfg(any(feature = "cranelift", feature = "winch"))]
256-
{
257-
self.inner
258-
.compatible_with_native_host
259-
.get_or_init(|| self._check_compatible_with_native_host())
260-
.clone()
261-
.map_err(anyhow::Error::msg)
262-
}
263-
#[cfg(not(any(feature = "cranelift", feature = "winch")))]
264-
{
265-
Ok(())
266-
}
253+
self.inner
254+
.compatible_with_native_host
255+
.get_or_init(|| self._check_compatible_with_native_host())
256+
.clone()
257+
.map_err(anyhow::Error::msg)
267258
}
268259

260+
#[cfg(any(feature = "cranelift", feature = "winch"))]
269261
fn _check_compatible_with_native_host(&self) -> Result<(), String> {
270-
#[cfg(any(feature = "cranelift", feature = "winch"))]
271-
{
272-
use target_lexicon::Triple;
273-
274-
let compiler = self.compiler();
275-
276-
let target = compiler.triple();
277-
let host = Triple::host();
278-
let target_matches_host = || {
279-
// If the host target and target triple match, then it's valid
280-
// to run results of compilation on this host.
281-
if host == *target {
282-
return true;
283-
}
284-
285-
// If there's a mismatch and the target is a compatible pulley
286-
// target, then that's also ok to run.
287-
if cfg!(feature = "pulley")
288-
&& target.is_pulley()
289-
&& target.pointer_width() == host.pointer_width()
290-
&& target.endianness() == host.endianness()
291-
{
292-
return true;
293-
}
262+
use target_lexicon::Triple;
294263

295-
// ... otherwise everything else is considered not a match.
296-
false
297-
};
264+
let compiler = self.compiler();
298265

299-
if !target_matches_host() {
300-
return Err(format!(
301-
"target '{target}' specified in the configuration does not match the host"
302-
));
266+
let target = compiler.triple();
267+
let host = Triple::host();
268+
let target_matches_host = || {
269+
// If the host target and target triple match, then it's valid
270+
// to run results of compilation on this host.
271+
if host == *target {
272+
return true;
303273
}
304274

305-
// Also double-check all compiler settings
306-
for (key, value) in compiler.flags().iter() {
307-
self.check_compatible_with_shared_flag(key, value)?;
308-
}
309-
for (key, value) in compiler.isa_flags().iter() {
310-
self.check_compatible_with_isa_flag(key, value)?;
275+
// If there's a mismatch and the target is a compatible pulley
276+
// target, then that's also ok to run.
277+
if cfg!(feature = "pulley")
278+
&& target.is_pulley()
279+
&& target.pointer_width() == host.pointer_width()
280+
&& target.endianness() == host.endianness()
281+
{
282+
return true;
311283
}
284+
285+
// ... otherwise everything else is considered not a match.
286+
false
287+
};
288+
289+
if !target_matches_host() {
290+
return Err(format!(
291+
"target '{target}' specified in the configuration does not match the host"
292+
));
293+
}
294+
295+
// Also double-check all compiler settings
296+
for (key, value) in compiler.flags().iter() {
297+
self.check_compatible_with_shared_flag(key, value)?;
298+
}
299+
for (key, value) in compiler.isa_flags().iter() {
300+
self.check_compatible_with_isa_flag(key, value)?;
312301
}
313302

314303
// Double-check that this configuration isn't requesting capabilities
@@ -622,8 +611,8 @@ impl Engine {
622611
pub(crate) fn append_bti(&self, obj: &mut Object<'_>) {
623612
let section = obj.add_section(
624613
obj.segment_name(StandardSegment::Data).to_vec(),
625-
obj::ELF_WASM_BTI.as_bytes().to_vec(),
626-
SectionKind::ReadOnlyData,
614+
wasmtime_environ::obj::ELF_WASM_BTI.as_bytes().to_vec(),
615+
object::SectionKind::ReadOnlyData,
627616
);
628617
let contents = if self.compiler().is_branch_protection_enabled() {
629618
1
@@ -682,7 +671,7 @@ impl Engine {
682671
self.inner.profiler.as_ref()
683672
}
684673

685-
#[cfg(feature = "cache")]
674+
#[cfg(all(feature = "cache", any(feature = "cranelift", feature = "winch")))]
686675
pub(crate) fn cache_config(&self) -> &wasmtime_cache::CacheConfig {
687676
&self.config().cache_config
688677
}

crates/wasmtime/src/engine/serialization.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use core::str::FromStr;
2727
use object::endian::Endianness;
2828
#[cfg(any(feature = "cranelift", feature = "winch"))]
2929
use object::write::{Object, StandardSegment};
30-
use object::{read::elf::ElfFile64, FileFlags, Object as _, ObjectSection, SectionKind};
30+
use object::{read::elf::ElfFile64, FileFlags, Object as _, ObjectSection};
3131
use serde_derive::{Deserialize, Serialize};
3232
use wasmtime_environ::obj;
3333
use wasmtime_environ::{FlagValue, ObjectKind, Tunables};
@@ -122,7 +122,7 @@ pub fn append_compiler_info(engine: &Engine, obj: &mut Object<'_>, metadata: &Me
122122
let section = obj.add_section(
123123
obj.segment_name(StandardSegment::Data).to_vec(),
124124
obj::ELF_WASM_ENGINE.as_bytes().to_vec(),
125-
SectionKind::ReadOnlyData,
125+
object::SectionKind::ReadOnlyData,
126126
);
127127
let mut data = Vec::new();
128128
data.push(VERSION);

crates/wasmtime/src/lib.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -284,11 +284,7 @@
284284
// NB: this list is currently being burned down to remove all features listed
285285
// here to get warnings in all configurations of Wasmtime.
286286
#![cfg_attr(
287-
any(
288-
not(feature = "cranelift"),
289-
not(feature = "runtime"),
290-
not(feature = "std"),
291-
),
287+
any(not(feature = "runtime"), not(feature = "std")),
292288
allow(dead_code, unused_imports)
293289
)]
294290
// Allow broken links when the default features is disabled because most of our

crates/wasmtime/src/runtime/module.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::prelude::*;
22
#[cfg(feature = "std")]
33
use crate::runtime::vm::open_file_for_mmap;
4-
use crate::runtime::vm::{CompiledModuleId, MmapVec, ModuleMemoryImages, VMWasmCallFunction};
4+
use crate::runtime::vm::{CompiledModuleId, ModuleMemoryImages, VMWasmCallFunction};
55
use crate::sync::OnceLock;
66
use crate::{
77
code::CodeObject,
@@ -153,6 +153,7 @@ struct ModuleInner {
153153
memory_images: OnceLock<Option<ModuleMemoryImages>>,
154154

155155
/// Flag indicating whether this module can be serialized or not.
156+
#[cfg(any(feature = "cranelift", feature = "winch"))]
156157
serializable: bool,
157158

158159
/// Runtime offset information for `VMContext`.
@@ -344,7 +345,7 @@ impl Module {
344345
#[cfg(all(feature = "std", any(feature = "cranelift", feature = "winch")))]
345346
pub unsafe fn from_trusted_file(engine: &Engine, file: impl AsRef<Path>) -> Result<Module> {
346347
let open_file = open_file_for_mmap(file.as_ref())?;
347-
let mmap = MmapVec::from_file(open_file)?;
348+
let mmap = crate::runtime::vm::MmapVec::from_file(open_file)?;
348349
if &mmap[0..4] == b"\x7fELF" {
349350
let code = engine.load_code(mmap, ObjectKind::Module)?;
350351
return Module::from_parts(engine, code, None);
@@ -510,12 +511,15 @@ impl Module {
510511
.allocator()
511512
.validate_module(module.module(), &offsets)?;
512513

514+
let _ = serializable;
515+
513516
Ok(Self {
514517
inner: Arc::new(ModuleInner {
515518
engine: engine.clone(),
516519
code,
517520
memory_images: OnceLock::new(),
518521
module,
522+
#[cfg(any(feature = "cranelift", feature = "winch"))]
519523
serializable,
520524
offsets,
521525
}),

crates/wasmtime/src/sync_nostd.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,12 @@ impl<T> OnceLock<T> {
8888
}
8989
}
9090

91+
impl<T> Default for OnceLock<T> {
92+
fn default() -> OnceLock<T> {
93+
OnceLock::new()
94+
}
95+
}
96+
9197
#[derive(Debug, Default)]
9298
pub struct RwLock<T> {
9399
val: UnsafeCell<T>,

crates/wasmtime/src/sync_std.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,12 @@ impl<T> OnceLock<T> {
3030
}
3131
}
3232

33+
impl<T> Default for OnceLock<T> {
34+
fn default() -> OnceLock<T> {
35+
OnceLock::new()
36+
}
37+
}
38+
3339
/// Small wrapper around `std::sync::RwLock` which undoes poisoning.
3440
#[derive(Debug, Default)]
3541
pub struct RwLock<T>(std::sync::RwLock<T>);

0 commit comments

Comments
 (0)