@@ -5,18 +5,15 @@ pub use crate::runtime::code_memory::CustomCodeMemory;
55use crate :: runtime:: type_registry:: TypeRegistry ;
66#[ cfg( feature = "runtime" ) ]
77use crate :: runtime:: vm:: GcRuntime ;
8- use crate :: sync:: OnceLock ;
98use crate :: Config ;
109use alloc:: sync:: Arc ;
1110#[ cfg( target_has_atomic = "64" ) ]
1211use core:: sync:: atomic:: { AtomicU64 , Ordering } ;
1312#[ cfg( any( feature = "cranelift" , feature = "winch" ) ) ]
1413use object:: write:: { Object , StandardSegment } ;
15- use object:: SectionKind ;
1614#[ cfg( feature = "std" ) ]
1715use std:: { fs:: File , path:: Path } ;
1816use wasmparser:: WasmFeatures ;
19- use wasmtime_environ:: obj;
2017use wasmtime_environ:: { FlagValue , ObjectKind , TripleExt , Tunables } ;
2118
2219mod 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
7471impl 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 }
0 commit comments