From e6f39e74b03590b7bd4765ad864c4092792d5dd3 Mon Sep 17 00:00:00 2001 From: "Hamid R. K. Pisghadam" Date: Thu, 26 Jan 2023 14:34:47 +0330 Subject: [PATCH 01/12] bump inkwell to 0.1.0 --- Cargo.lock | 38 ++++++-- lib/compiler-llvm/Cargo.toml | 2 +- lib/compiler-llvm/src/abi/aarch64_systemv.rs | 2 +- lib/compiler-llvm/src/abi/x86_64_systemv.rs | 2 +- lib/compiler-llvm/src/trampoline/wasm.rs | 16 ++-- lib/compiler-llvm/src/translator/code.rs | 6 +- .../src/translator/intrinsics.rs | 86 ++++++++++--------- 7 files changed, 89 insertions(+), 63 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ce7ebaec..593a97c38 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1719,24 +1719,23 @@ dependencies = [ [[package]] name = "inkwell" -version = "0.1.0-beta.4" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2223d0eba0ae6d40a3e4680c6a3209143471e1f38b41746ea309aa36dde9f90b" +checksum = "f6572fb91d5e09a2a40c99721bdf94ed554a74b09db684276cb1bba39e844da4" dependencies = [ "either", "inkwell_internals", "libc", "llvm-sys", "once_cell", - "parking_lot", - "regex", + "parking_lot 0.12.1", ] [[package]] name = "inkwell_internals" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c7090af3d300424caa81976b8c97bca41cd70e861272c072e188ae082fb49f9" +checksum = "87d00c17e264ce02be5bc23d7bff959188ec7137beddd06b8b6b05a7c680ea85" dependencies = [ "proc-macro2", "quote", @@ -2317,7 +2316,17 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core", + "parking_lot_core 0.8.6", +] + +[[package]] +name = "parking_lot" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +dependencies = [ + "lock_api", + "parking_lot_core 0.9.6", ] [[package]] @@ -2334,6 +2343,19 @@ dependencies = [ "winapi", ] +[[package]] +name = "parking_lot_core" +version = "0.9.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "redox_syscall 0.2.16", + "smallvec", + "windows-sys 0.42.0", +] + [[package]] name = "paste" version = "1.0.11" @@ -3245,7 +3267,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d" dependencies = [ "lazy_static", - "parking_lot", + "parking_lot 0.11.2", "serial_test_derive", ] diff --git a/lib/compiler-llvm/Cargo.toml b/lib/compiler-llvm/Cargo.toml index c7e36216e..3c6429665 100644 --- a/lib/compiler-llvm/Cargo.toml +++ b/lib/compiler-llvm/Cargo.toml @@ -27,7 +27,7 @@ rayon = "1.5" [dependencies.inkwell] package = "inkwell" -version = "=0.1.0-beta.4" +version = "0.1.0" default-features = false features = ["llvm12-0", "target-x86", "target-aarch64"] diff --git a/lib/compiler-llvm/src/abi/aarch64_systemv.rs b/lib/compiler-llvm/src/abi/aarch64_systemv.rs index 8bcb65a00..89e07a80c 100644 --- a/lib/compiler-llvm/src/abi/aarch64_systemv.rs +++ b/lib/compiler-llvm/src/abi/aarch64_systemv.rs @@ -207,7 +207,7 @@ impl Abi for Aarch64SystemV { .collect::>()?; let sret = context.struct_type(&basic_types, false); - let sret_ptr = sret.ptr_type(AddressSpace::Generic); + let sret_ptr = sret.ptr_type(AddressSpace::default()); let param_types = std::iter::once(Ok(sret_ptr.as_basic_type_enum())).chain(param_types); diff --git a/lib/compiler-llvm/src/abi/x86_64_systemv.rs b/lib/compiler-llvm/src/abi/x86_64_systemv.rs index 707519308..bf02a1f45 100644 --- a/lib/compiler-llvm/src/abi/x86_64_systemv.rs +++ b/lib/compiler-llvm/src/abi/x86_64_systemv.rs @@ -263,7 +263,7 @@ impl Abi for X86_64SystemV { .collect::>()?; let sret = context.struct_type(&basic_types, false); - let sret_ptr = sret.ptr_type(AddressSpace::Generic); + let sret_ptr = sret.ptr_type(AddressSpace::default()); let param_types = std::iter::once(Ok(sret_ptr.as_basic_type_enum())).chain(param_types); diff --git a/lib/compiler-llvm/src/trampoline/wasm.rs b/lib/compiler-llvm/src/trampoline/wasm.rs index c3166dd2b..c0eafe8b8 100644 --- a/lib/compiler-llvm/src/trampoline/wasm.rs +++ b/lib/compiler-llvm/src/trampoline/wasm.rs @@ -59,9 +59,9 @@ impl FuncTrampoline { .func_type_to_llvm(&self.ctx, &intrinsics, None, ty)?; let trampoline_ty = intrinsics.void_ty.fn_type( &[ - intrinsics.ctx_ptr_ty.into(), // vmctx ptr - callee_ty.ptr_type(AddressSpace::Generic).into(), // callee function address - intrinsics.i128_ptr_ty.into(), // in/out values ptr + intrinsics.ctx_ptr_ty.into(), // vmctx ptr + callee_ty.ptr_type(AddressSpace::default()).into(), // callee function address + intrinsics.i128_ptr_ty.into(), // in/out values ptr ], false, ); @@ -69,7 +69,7 @@ impl FuncTrampoline { let trampoline_func = module.add_function(name, trampoline_ty, Some(Linkage::External)); trampoline_func .as_global_value() - .set_section(FUNCTION_SECTION); + .set_section(Some(FUNCTION_SECTION)); trampoline_func .as_global_value() .set_linkage(Linkage::DLLExport); @@ -189,7 +189,7 @@ impl FuncTrampoline { } trampoline_func .as_global_value() - .set_section(FUNCTION_SECTION); + .set_section(Some(FUNCTION_SECTION)); trampoline_func .as_global_value() .set_linkage(Linkage::DLLExport); @@ -359,7 +359,7 @@ impl FuncTrampoline { ) }; let ptr = - builder.build_pointer_cast(ptr, v.get_type().ptr_type(AddressSpace::Generic), ""); + builder.build_pointer_cast(ptr, v.get_type().ptr_type(AddressSpace::default()), ""); builder.build_store(ptr, *v); if v.get_type() == intrinsics.i128_ty.as_basic_type_enum() { idx += 1; @@ -424,12 +424,12 @@ impl FuncTrampoline { ], false, ) - .ptr_type(AddressSpace::Generic); + .ptr_type(AddressSpace::default()); let vmctx = self.abi.get_vmctx_ptr_param(&trampoline_func); let callee = builder .build_load( builder - .build_bitcast(vmctx, callee_ty.ptr_type(AddressSpace::Generic), "") + .build_bitcast(vmctx, callee_ty.ptr_type(AddressSpace::default()), "") .into_pointer_value(), "", ) diff --git a/lib/compiler-llvm/src/translator/code.rs b/lib/compiler-llvm/src/translator/code.rs index 8bdd06553..cd99c53f2 100644 --- a/lib/compiler-llvm/src/translator/code.rs +++ b/lib/compiler-llvm/src/translator/code.rs @@ -106,7 +106,7 @@ impl FuncTranslator { func.add_attribute(AttributeLoc::Function, intrinsics.stack_probe); func.set_personality_function(intrinsics.personality); - func.as_global_value().set_section(FUNCTION_SECTION); + func.as_global_value().set_section(Some(FUNCTION_SECTION)); func.set_linkage(Linkage::DLLExport); func.as_global_value() .set_dll_storage_class(DLLStorageClass::Export); @@ -2334,7 +2334,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { // element type. let casted_table_base = self.builder.build_pointer_cast( table_base, - self.intrinsics.funcref_ty.ptr_type(AddressSpace::Generic), + self.intrinsics.funcref_ty.ptr_type(AddressSpace::default()), "casted_table_base", ); @@ -2503,7 +2503,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let typed_func_ptr = self.builder.build_pointer_cast( func_ptr, - llvm_func_type.ptr_type(AddressSpace::Generic), + llvm_func_type.ptr_type(AddressSpace::default()), "typed_func_ptr", ); diff --git a/lib/compiler-llvm/src/translator/intrinsics.rs b/lib/compiler-llvm/src/translator/intrinsics.rs index 028b0a37a..96ebe2714 100644 --- a/lib/compiler-llvm/src/translator/intrinsics.rs +++ b/lib/compiler-llvm/src/translator/intrinsics.rs @@ -40,8 +40,8 @@ pub fn type_to_llvm_ptr<'ctx>( Type::F32 => Ok(intrinsics.f32_ptr_ty), Type::F64 => Ok(intrinsics.f64_ptr_ty), Type::V128 => Ok(intrinsics.i128_ptr_ty), - Type::FuncRef => Ok(intrinsics.funcref_ty.ptr_type(AddressSpace::Generic)), - Type::ExternRef => Ok(intrinsics.externref_ty.ptr_type(AddressSpace::Generic)), + Type::FuncRef => Ok(intrinsics.funcref_ty.ptr_type(AddressSpace::default())), + Type::ExternRef => Ok(intrinsics.externref_ty.ptr_type(AddressSpace::default())), } } @@ -304,14 +304,14 @@ impl<'ctx> Intrinsics<'ctx> { let f64x2_ty = f64_ty.vec_type(2); let i32x8_ty = i32_ty.vec_type(8); - let i8_ptr_ty = i8_ty.ptr_type(AddressSpace::Generic); - let i16_ptr_ty = i16_ty.ptr_type(AddressSpace::Generic); - let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::Generic); - let i64_ptr_ty = i64_ty.ptr_type(AddressSpace::Generic); - let i128_ptr_ty = i128_ty.ptr_type(AddressSpace::Generic); - let isize_ptr_ty = isize_ty.ptr_type(AddressSpace::Generic); - let f32_ptr_ty = f32_ty.ptr_type(AddressSpace::Generic); - let f64_ptr_ty = f64_ty.ptr_type(AddressSpace::Generic); + let i8_ptr_ty = i8_ty.ptr_type(AddressSpace::default()); + let i16_ptr_ty = i16_ty.ptr_type(AddressSpace::default()); + let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::default()); + let i64_ptr_ty = i64_ty.ptr_type(AddressSpace::default()); + let i128_ptr_ty = i128_ty.ptr_type(AddressSpace::default()); + let isize_ptr_ty = isize_ty.ptr_type(AddressSpace::default()); + let f32_ptr_ty = f32_ty.ptr_type(AddressSpace::default()); + let f64_ptr_ty = f64_ty.ptr_type(AddressSpace::default()); let i1_zero = i1_ty.const_int(0, false); let i8_zero = i8_ty.const_int(0, false); @@ -358,7 +358,7 @@ impl<'ctx> Intrinsics<'ctx> { let md_ty_basic_md: BasicMetadataTypeEnum = md_ty.into(); let ctx_ty = i8_ty; - let ctx_ptr_ty = ctx_ty.ptr_type(AddressSpace::Generic); + let ctx_ptr_ty = ctx_ty.ptr_type(AddressSpace::default()); let ctx_ptr_ty_basic = ctx_ptr_ty.as_basic_type_enum(); let ctx_ptr_ty_basic_md: BasicMetadataTypeEnum = ctx_ptr_ty.into(); @@ -368,7 +368,7 @@ impl<'ctx> Intrinsics<'ctx> { &[i8_ptr_ty_basic, sigindex_ty.into(), ctx_ptr_ty_basic], false, ); - let funcref_ty = anyfunc_ty.ptr_type(AddressSpace::Generic); + let funcref_ty = anyfunc_ty.ptr_type(AddressSpace::default()); let externref_ty = funcref_ty; let anyref_ty = i8_ptr_ty; let anyref_ty_basic_md: BasicMetadataTypeEnum = anyref_ty.into(); @@ -1094,13 +1094,13 @@ impl<'ctx> Intrinsics<'ctx> { vmfunction_import_ptr_ty: context .struct_type(&[i8_ptr_ty_basic, i8_ptr_ty_basic], false) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), vmfunction_import_body_element: 0, vmfunction_import_vmctx_element: 1, vmmemory_definition_ptr_ty: context .struct_type(&[i8_ptr_ty_basic, isize_ty.into()], false) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), vmmemory_definition_base_element: 0, vmmemory_definition_current_length_element: 1, @@ -1109,19 +1109,19 @@ impl<'ctx> Intrinsics<'ctx> { &[ctx_ptr_ty_basic_md, i32_ty_basic_md, i32_ty_basic_md], false, ) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), imported_memory32_grow_ptr_ty: i32_ty .fn_type( &[ctx_ptr_ty_basic_md, i32_ty_basic_md, i32_ty_basic_md], false, ) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), memory32_size_ptr_ty: i32_ty .fn_type(&[ctx_ptr_ty_basic_md, i32_ty_basic_md], false) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), imported_memory32_size_ptr_ty: i32_ty .fn_type(&[ctx_ptr_ty_basic_md, i32_ty_basic_md], false) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), memory32_wait32_ptr_ty: i32_ty .fn_type( &[ @@ -1133,7 +1133,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), imported_memory32_wait32_ptr_ty: i32_ty .fn_type( &[ @@ -1145,7 +1145,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), memory32_wait64_ptr_ty: i32_ty .fn_type( &[ @@ -1157,7 +1157,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), imported_memory32_wait64_ptr_ty: i32_ty .fn_type( &[ @@ -1169,7 +1169,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), memory32_notify_ptr_ty: i32_ty .fn_type( &[ @@ -1180,7 +1180,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), imported_memory32_notify_ptr_ty: i32_ty .fn_type( &[ @@ -1191,7 +1191,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::Generic), + .ptr_type(AddressSpace::default()), ctx_ptr_ty, }; @@ -1316,7 +1316,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let memory_definition_ptr_ptr = cache_builder .build_bitcast( memory_definition_ptr_ptr, - intrinsics.i8_ptr_ty.ptr_type(AddressSpace::Generic), + intrinsics.i8_ptr_ty.ptr_type(AddressSpace::default()), "", ) .into_pointer_value(); @@ -1400,7 +1400,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let ptr_to_base_ptr = cache_builder .build_bitcast( ptr_to_base_ptr, - intrinsics.i8_ptr_ty.ptr_type(AddressSpace::Generic), + intrinsics.i8_ptr_ty.ptr_type(AddressSpace::default()), "", ) .into_pointer_value(); @@ -1426,7 +1426,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let definition_ptr_ptr = cache_builder .build_bitcast( definition_ptr_ptr, - intrinsics.i8_ptr_ty.ptr_type(AddressSpace::Generic), + intrinsics.i8_ptr_ty.ptr_type(AddressSpace::default()), "", ) .into_pointer_value(); @@ -1448,7 +1448,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let ptr_to_base_ptr = cache_builder .build_bitcast( ptr_to_base_ptr, - intrinsics.i8_ptr_ty.ptr_type(AddressSpace::Generic), + intrinsics.i8_ptr_ty.ptr_type(AddressSpace::default()), "", ) .into_pointer_value(); @@ -1570,7 +1570,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let global_ptr_ptr = cache_builder .build_bitcast( global_ptr_ptr, - intrinsics.i32_ptr_ty.ptr_type(AddressSpace::Generic), + intrinsics.i32_ptr_ty.ptr_type(AddressSpace::default()), "", ) .into_pointer_value(); @@ -1710,7 +1710,11 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { .unwrap(); let body_ptr = cache_builder.build_load(body_ptr_ptr, ""); let body_ptr = cache_builder - .build_bitcast(body_ptr, llvm_func_type.ptr_type(AddressSpace::Generic), "") + .build_bitcast( + body_ptr, + llvm_func_type.ptr_type(AddressSpace::default()), + "", + ) .into_pointer_value(); let vmctx_ptr_ptr = cache_builder .build_struct_gep( @@ -1760,7 +1764,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let grow_fn_ptr_ptr = cache_builder .build_bitcast( grow_fn_ptr_ptr, - grow_fn_ty.ptr_type(AddressSpace::Generic), + grow_fn_ty.ptr_type(AddressSpace::default()), "", ) .into_pointer_value(); @@ -1801,7 +1805,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let size_fn_ptr_ptr = cache_builder .build_bitcast( size_fn_ptr_ptr, - size_fn_ty.ptr_type(AddressSpace::Generic), + size_fn_ty.ptr_type(AddressSpace::default()), "", ) .into_pointer_value(); @@ -1843,7 +1847,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let size_fn_ptr_ptr = cache_builder .build_bitcast( size_fn_ptr_ptr, - size_fn_ty.ptr_type(AddressSpace::Generic), + size_fn_ty.ptr_type(AddressSpace::default()), "", ) .into_pointer_value(); @@ -1885,7 +1889,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let size_fn_ptr_ptr = cache_builder .build_bitcast( size_fn_ptr_ptr, - size_fn_ty.ptr_type(AddressSpace::Generic), + size_fn_ty.ptr_type(AddressSpace::default()), "", ) .into_pointer_value(); @@ -1927,7 +1931,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let size_fn_ptr_ptr = cache_builder .build_bitcast( size_fn_ptr_ptr, - size_fn_ty.ptr_type(AddressSpace::Generic), + size_fn_ty.ptr_type(AddressSpace::default()), "", ) .into_pointer_value(); @@ -1966,12 +1970,12 @@ pub fn tbaa_label<'ctx>( let context = module.get_context(); - // TODO: StoreRef can't return us the lifetime from module through Deref. - // This could be fixed once generic_associated_types is stable. - let context = { - let context2 = &*context; - unsafe { std::mem::transmute::<&Context, &'ctx Context>(context2) } - }; + //// TODO: StoreRef can't return us the lifetime from module through Deref. + //// This could be fixed once generic_associated_types is stable. + //let context = { + // let context2 = &*context; + // unsafe { std::mem::transmute::<&Context, &'ctx Context>(context2) } + //}; // `!wasmer_tbaa_root = {}`, the TBAA root node for wasmer. let tbaa_root = module From d99d400a613d3408f82acb66319f2f2ea4b41a97 Mon Sep 17 00:00:00 2001 From: "Hamid R. K. Pisghadam" Date: Thu, 26 Jan 2023 15:06:33 +0330 Subject: [PATCH 02/12] Remove unnecessary code --- lib/compiler-llvm/src/translator/intrinsics.rs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/compiler-llvm/src/translator/intrinsics.rs b/lib/compiler-llvm/src/translator/intrinsics.rs index 96ebe2714..f25ba0365 100644 --- a/lib/compiler-llvm/src/translator/intrinsics.rs +++ b/lib/compiler-llvm/src/translator/intrinsics.rs @@ -1970,13 +1970,6 @@ pub fn tbaa_label<'ctx>( let context = module.get_context(); - //// TODO: StoreRef can't return us the lifetime from module through Deref. - //// This could be fixed once generic_associated_types is stable. - //let context = { - // let context2 = &*context; - // unsafe { std::mem::transmute::<&Context, &'ctx Context>(context2) } - //}; - // `!wasmer_tbaa_root = {}`, the TBAA root node for wasmer. let tbaa_root = module .get_global_metadata("wasmer_tbaa_root") From 9e83e8a4663e4f5f8e95a8d823e96b8a6390ec50 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 30 Jan 2023 11:49:57 +0100 Subject: [PATCH 03/12] Reduce libwasmer-headless size --- Makefile | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) diff --git a/Makefile b/Makefile index 0038e4fd6..bc90e4d77 100644 --- a/Makefile +++ b/Makefile @@ -451,11 +451,11 @@ build-capi-llvm-universal: build-capi-headless: ifeq ($(CARGO_TARGET_FLAG),) - RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) build --target $(HOST_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features compiler-headless,wasi,webc_runner --target-dir target/headless + RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) +nightly build --target $(HOST_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ + --no-default-features --features compiler-headless,wasi,webc_runner --target-dir target/headless -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort else - RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features compiler-headless,wasi,webc_runner --target-dir target/headless + RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) +nightly build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \ + --no-default-features --features compiler-headless,wasi,webc_runner --target-dir target/headless -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort endif build-capi-headless-ios: @@ -695,39 +695,13 @@ package-capi: cp target/$(HOST_TARGET)/release/libwasmer.a package/lib/libwasmer.a ;\ fi -package-capi-headless: build-capi-headless - mkdir -p "package/include" - mkdir -p "package/lib" - cp lib/c-api/wasmer.h* package/include - cp lib/c-api/wasmer_wasm.h* package/include - cp lib/c-api/wasm.h* package/include - cp lib/c-api/README.md package/include/README.md - - if [ -f $(TARGET_DIR)/wasmer.dll ]; then \ - cp $(TARGET_DIR)/wasmer.dll package/lib/wasmer-headless.dll ;\ - fi - if [ -f $(TARGET_DIR)/wasmer.lib ]; then \ - cp $(TARGET_DIR)/wasmer.lib package/lib/wasmer-headless.lib ;\ - fi - - if [ -f $(TARGET_DIR)/libwasmer.dylib ]; then \ - cp $(TARGET_DIR)/libwasmer.dylib package/lib/libwasmer-headless.dylib ;\ - fi - - if [ -f $(TARGET_DIR)/libwasmer.so ]; then \ - cp $(TARGET_DIR)/libwasmer.so package/lib/libwasmer-headless.so ;\ - fi - if [ -f $(TARGET_DIR)/libwasmer.a ]; then \ - cp $(TARGET_DIR)/libwasmer.a package/lib/libwasmer-headless.a ;\ - fi - package-docs: build-docs build-docs-capi mkdir -p "package/docs/crates" cp -R target/doc/ package/docs/crates echo '' > package/docs/index.html echo '' > package/docs/crates/index.html -package: package-wasmer package-minimal-headless-wasmer package-capi package-capi-headless +package: package-wasmer package-minimal-headless-wasmer package-capi tar-capi: ls -R package From a91d2474619388f72b682196ccf70d75289e1745 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 30 Jan 2023 12:06:31 +0100 Subject: [PATCH 04/12] Add cargo nightly to GitHub CI --- .github/workflows/build.yml | 22 +++++++++++++++++++++- .github/workflows/test.yaml | 5 +++++ Makefile | 8 ++++---- 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 9a3dfc56f..b24a907ed 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -102,6 +102,11 @@ jobs: with: toolchain: 1.64 target: ${{ matrix.target }} + - name: Install Rust nightly (to build capi-headless) + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly + target: ${{ matrix.metadata.target }} - uses: Swatinem/rust-cache@v1 if: matrix.use_sccache != true - name: Install LLVM (macOS Apple Silicon) @@ -273,6 +278,11 @@ jobs: - uses: dtolnay/rust-toolchain@stable with: target: x86_64-pc-windows-gnu + - name: Install Rust nightly (to build capi-headless) + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly + target: x86_64-pc-windows-gnu - name: Install Windows-GNU target shell: bash run: | @@ -301,9 +311,19 @@ jobs: - name: Build Wasmer C-API without LLVM shell: bash run: | - cargo build --release --target x86_64-pc-windows-gnu --manifest-path lib/c-api/Cargo.toml --no-default-features --features wat,compiler,wasi,middlewares,webc_runner --features cranelift,singlepass,wasmer-artifact-create,static-artifact-create,wasmer-artifact-load,static-artifact-load + make build-capi env: RUSTFLAGS: -Cpanic=abort + CARGO_TARGET: x86_64-pc-windows-gnu + ENABLE_LLVM: 0 + - name: Build Wasmer C-API headless without LLVM + shell: bash + run: | + make build-capi-headless + env: + RUSTFLAGS: -Cpanic=abort + CARGO_TARGET: x86_64-pc-windows-gnu + ENABLE_LLVM: 0 - name: Dist run: | make distribution-gnu diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index b8e25e5f4..87a339e19 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -263,6 +263,11 @@ jobs: with: toolchain: 1.64 target: ${{ matrix.metadata.target }} + - name: Install Rust nightly (to build capi-headless) + uses: dtolnay/rust-toolchain@stable + with: + toolchain: nightly + target: ${{ matrix.metadata.target }} - name: Install Windows-GNU linker if: ${{ matrix.metadata.build == 'windows-gnu' }} shell: bash diff --git a/Makefile b/Makefile index bc90e4d77..ded8856d9 100644 --- a/Makefile +++ b/Makefile @@ -451,11 +451,11 @@ build-capi-llvm-universal: build-capi-headless: ifeq ($(CARGO_TARGET_FLAG),) - RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) +nightly build --target $(HOST_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features compiler-headless,wasi,webc_runner --target-dir target/headless -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort + RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) build --target $(HOST_TARGET) --manifest-path lib/c-api/Cargo.toml --release \ + --no-default-features --features compiler-headless,wasi,webc_runner --target-dir target/headless else - RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) +nightly build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \ - --no-default-features --features compiler-headless,wasi,webc_runner --target-dir target/headless -Z build-std=std,panic_abort -Z build-std-features=panic_immediate_abort + RUSTFLAGS="${RUSTFLAGS} -C panic=abort -C link-dead-code -C lto -O -C embed-bitcode=yes" $(CARGO_BINARY) build $(CARGO_TARGET_FLAG) --manifest-path lib/c-api/Cargo.toml --release \ + --no-default-features --features compiler-headless,wasi,webc_runner --target-dir target/headless endif build-capi-headless-ios: From a23c02f927470d2dda3106d12e551de086af5536 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Sch=C3=BCtt?= Date: Mon, 30 Jan 2023 13:49:14 +0100 Subject: [PATCH 05/12] Add package-capi-headless back --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index ded8856d9..5a2f6b8ed 100644 --- a/Makefile +++ b/Makefile @@ -617,6 +617,8 @@ ifeq ($(IS_DARWIN), 1) endif endif +package-capi-headless: build-capi-headless package-capi + package-capi: mkdir -p "package/include" mkdir -p "package/lib" From f0374ce478613c272a4026aaa56ab0fc8b61e87e Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Wed, 1 Feb 2023 16:40:32 +0100 Subject: [PATCH 06/12] Revert "bump inkwell to 0.1.0" --- Cargo.lock | 38 ++------- lib/compiler-llvm/Cargo.toml | 2 +- lib/compiler-llvm/src/abi/aarch64_systemv.rs | 2 +- lib/compiler-llvm/src/abi/x86_64_systemv.rs | 2 +- lib/compiler-llvm/src/trampoline/wasm.rs | 16 ++-- lib/compiler-llvm/src/translator/code.rs | 6 +- .../src/translator/intrinsics.rs | 81 ++++++++++--------- 7 files changed, 64 insertions(+), 83 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 593a97c38..6ce7ebaec 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1719,23 +1719,24 @@ dependencies = [ [[package]] name = "inkwell" -version = "0.1.0" +version = "0.1.0-beta.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6572fb91d5e09a2a40c99721bdf94ed554a74b09db684276cb1bba39e844da4" +checksum = "2223d0eba0ae6d40a3e4680c6a3209143471e1f38b41746ea309aa36dde9f90b" dependencies = [ "either", "inkwell_internals", "libc", "llvm-sys", "once_cell", - "parking_lot 0.12.1", + "parking_lot", + "regex", ] [[package]] name = "inkwell_internals" -version = "0.7.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87d00c17e264ce02be5bc23d7bff959188ec7137beddd06b8b6b05a7c680ea85" +checksum = "3c7090af3d300424caa81976b8c97bca41cd70e861272c072e188ae082fb49f9" dependencies = [ "proc-macro2", "quote", @@ -2316,17 +2317,7 @@ checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", "lock_api", - "parking_lot_core 0.8.6", -] - -[[package]] -name = "parking_lot" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" -dependencies = [ - "lock_api", - "parking_lot_core 0.9.6", + "parking_lot_core", ] [[package]] @@ -2343,19 +2334,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "parking_lot_core" -version = "0.9.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ba1ef8814b5c993410bb3adfad7a5ed269563e4a2f90c41f5d85be7fb47133bf" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "windows-sys 0.42.0", -] - [[package]] name = "paste" version = "1.0.11" @@ -3267,7 +3245,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e0bccbcf40c8938196944a3da0e133e031a33f4d6b72db3bda3cc556e361905d" dependencies = [ "lazy_static", - "parking_lot 0.11.2", + "parking_lot", "serial_test_derive", ] diff --git a/lib/compiler-llvm/Cargo.toml b/lib/compiler-llvm/Cargo.toml index 3c6429665..c7e36216e 100644 --- a/lib/compiler-llvm/Cargo.toml +++ b/lib/compiler-llvm/Cargo.toml @@ -27,7 +27,7 @@ rayon = "1.5" [dependencies.inkwell] package = "inkwell" -version = "0.1.0" +version = "=0.1.0-beta.4" default-features = false features = ["llvm12-0", "target-x86", "target-aarch64"] diff --git a/lib/compiler-llvm/src/abi/aarch64_systemv.rs b/lib/compiler-llvm/src/abi/aarch64_systemv.rs index 89e07a80c..8bcb65a00 100644 --- a/lib/compiler-llvm/src/abi/aarch64_systemv.rs +++ b/lib/compiler-llvm/src/abi/aarch64_systemv.rs @@ -207,7 +207,7 @@ impl Abi for Aarch64SystemV { .collect::>()?; let sret = context.struct_type(&basic_types, false); - let sret_ptr = sret.ptr_type(AddressSpace::default()); + let sret_ptr = sret.ptr_type(AddressSpace::Generic); let param_types = std::iter::once(Ok(sret_ptr.as_basic_type_enum())).chain(param_types); diff --git a/lib/compiler-llvm/src/abi/x86_64_systemv.rs b/lib/compiler-llvm/src/abi/x86_64_systemv.rs index bf02a1f45..707519308 100644 --- a/lib/compiler-llvm/src/abi/x86_64_systemv.rs +++ b/lib/compiler-llvm/src/abi/x86_64_systemv.rs @@ -263,7 +263,7 @@ impl Abi for X86_64SystemV { .collect::>()?; let sret = context.struct_type(&basic_types, false); - let sret_ptr = sret.ptr_type(AddressSpace::default()); + let sret_ptr = sret.ptr_type(AddressSpace::Generic); let param_types = std::iter::once(Ok(sret_ptr.as_basic_type_enum())).chain(param_types); diff --git a/lib/compiler-llvm/src/trampoline/wasm.rs b/lib/compiler-llvm/src/trampoline/wasm.rs index c0eafe8b8..c3166dd2b 100644 --- a/lib/compiler-llvm/src/trampoline/wasm.rs +++ b/lib/compiler-llvm/src/trampoline/wasm.rs @@ -59,9 +59,9 @@ impl FuncTrampoline { .func_type_to_llvm(&self.ctx, &intrinsics, None, ty)?; let trampoline_ty = intrinsics.void_ty.fn_type( &[ - intrinsics.ctx_ptr_ty.into(), // vmctx ptr - callee_ty.ptr_type(AddressSpace::default()).into(), // callee function address - intrinsics.i128_ptr_ty.into(), // in/out values ptr + intrinsics.ctx_ptr_ty.into(), // vmctx ptr + callee_ty.ptr_type(AddressSpace::Generic).into(), // callee function address + intrinsics.i128_ptr_ty.into(), // in/out values ptr ], false, ); @@ -69,7 +69,7 @@ impl FuncTrampoline { let trampoline_func = module.add_function(name, trampoline_ty, Some(Linkage::External)); trampoline_func .as_global_value() - .set_section(Some(FUNCTION_SECTION)); + .set_section(FUNCTION_SECTION); trampoline_func .as_global_value() .set_linkage(Linkage::DLLExport); @@ -189,7 +189,7 @@ impl FuncTrampoline { } trampoline_func .as_global_value() - .set_section(Some(FUNCTION_SECTION)); + .set_section(FUNCTION_SECTION); trampoline_func .as_global_value() .set_linkage(Linkage::DLLExport); @@ -359,7 +359,7 @@ impl FuncTrampoline { ) }; let ptr = - builder.build_pointer_cast(ptr, v.get_type().ptr_type(AddressSpace::default()), ""); + builder.build_pointer_cast(ptr, v.get_type().ptr_type(AddressSpace::Generic), ""); builder.build_store(ptr, *v); if v.get_type() == intrinsics.i128_ty.as_basic_type_enum() { idx += 1; @@ -424,12 +424,12 @@ impl FuncTrampoline { ], false, ) - .ptr_type(AddressSpace::default()); + .ptr_type(AddressSpace::Generic); let vmctx = self.abi.get_vmctx_ptr_param(&trampoline_func); let callee = builder .build_load( builder - .build_bitcast(vmctx, callee_ty.ptr_type(AddressSpace::default()), "") + .build_bitcast(vmctx, callee_ty.ptr_type(AddressSpace::Generic), "") .into_pointer_value(), "", ) diff --git a/lib/compiler-llvm/src/translator/code.rs b/lib/compiler-llvm/src/translator/code.rs index cd99c53f2..8bdd06553 100644 --- a/lib/compiler-llvm/src/translator/code.rs +++ b/lib/compiler-llvm/src/translator/code.rs @@ -106,7 +106,7 @@ impl FuncTranslator { func.add_attribute(AttributeLoc::Function, intrinsics.stack_probe); func.set_personality_function(intrinsics.personality); - func.as_global_value().set_section(Some(FUNCTION_SECTION)); + func.as_global_value().set_section(FUNCTION_SECTION); func.set_linkage(Linkage::DLLExport); func.as_global_value() .set_dll_storage_class(DLLStorageClass::Export); @@ -2334,7 +2334,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { // element type. let casted_table_base = self.builder.build_pointer_cast( table_base, - self.intrinsics.funcref_ty.ptr_type(AddressSpace::default()), + self.intrinsics.funcref_ty.ptr_type(AddressSpace::Generic), "casted_table_base", ); @@ -2503,7 +2503,7 @@ impl<'ctx, 'a> LLVMFunctionCodeGenerator<'ctx, 'a> { let typed_func_ptr = self.builder.build_pointer_cast( func_ptr, - llvm_func_type.ptr_type(AddressSpace::default()), + llvm_func_type.ptr_type(AddressSpace::Generic), "typed_func_ptr", ); diff --git a/lib/compiler-llvm/src/translator/intrinsics.rs b/lib/compiler-llvm/src/translator/intrinsics.rs index f25ba0365..028b0a37a 100644 --- a/lib/compiler-llvm/src/translator/intrinsics.rs +++ b/lib/compiler-llvm/src/translator/intrinsics.rs @@ -40,8 +40,8 @@ pub fn type_to_llvm_ptr<'ctx>( Type::F32 => Ok(intrinsics.f32_ptr_ty), Type::F64 => Ok(intrinsics.f64_ptr_ty), Type::V128 => Ok(intrinsics.i128_ptr_ty), - Type::FuncRef => Ok(intrinsics.funcref_ty.ptr_type(AddressSpace::default())), - Type::ExternRef => Ok(intrinsics.externref_ty.ptr_type(AddressSpace::default())), + Type::FuncRef => Ok(intrinsics.funcref_ty.ptr_type(AddressSpace::Generic)), + Type::ExternRef => Ok(intrinsics.externref_ty.ptr_type(AddressSpace::Generic)), } } @@ -304,14 +304,14 @@ impl<'ctx> Intrinsics<'ctx> { let f64x2_ty = f64_ty.vec_type(2); let i32x8_ty = i32_ty.vec_type(8); - let i8_ptr_ty = i8_ty.ptr_type(AddressSpace::default()); - let i16_ptr_ty = i16_ty.ptr_type(AddressSpace::default()); - let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::default()); - let i64_ptr_ty = i64_ty.ptr_type(AddressSpace::default()); - let i128_ptr_ty = i128_ty.ptr_type(AddressSpace::default()); - let isize_ptr_ty = isize_ty.ptr_type(AddressSpace::default()); - let f32_ptr_ty = f32_ty.ptr_type(AddressSpace::default()); - let f64_ptr_ty = f64_ty.ptr_type(AddressSpace::default()); + let i8_ptr_ty = i8_ty.ptr_type(AddressSpace::Generic); + let i16_ptr_ty = i16_ty.ptr_type(AddressSpace::Generic); + let i32_ptr_ty = i32_ty.ptr_type(AddressSpace::Generic); + let i64_ptr_ty = i64_ty.ptr_type(AddressSpace::Generic); + let i128_ptr_ty = i128_ty.ptr_type(AddressSpace::Generic); + let isize_ptr_ty = isize_ty.ptr_type(AddressSpace::Generic); + let f32_ptr_ty = f32_ty.ptr_type(AddressSpace::Generic); + let f64_ptr_ty = f64_ty.ptr_type(AddressSpace::Generic); let i1_zero = i1_ty.const_int(0, false); let i8_zero = i8_ty.const_int(0, false); @@ -358,7 +358,7 @@ impl<'ctx> Intrinsics<'ctx> { let md_ty_basic_md: BasicMetadataTypeEnum = md_ty.into(); let ctx_ty = i8_ty; - let ctx_ptr_ty = ctx_ty.ptr_type(AddressSpace::default()); + let ctx_ptr_ty = ctx_ty.ptr_type(AddressSpace::Generic); let ctx_ptr_ty_basic = ctx_ptr_ty.as_basic_type_enum(); let ctx_ptr_ty_basic_md: BasicMetadataTypeEnum = ctx_ptr_ty.into(); @@ -368,7 +368,7 @@ impl<'ctx> Intrinsics<'ctx> { &[i8_ptr_ty_basic, sigindex_ty.into(), ctx_ptr_ty_basic], false, ); - let funcref_ty = anyfunc_ty.ptr_type(AddressSpace::default()); + let funcref_ty = anyfunc_ty.ptr_type(AddressSpace::Generic); let externref_ty = funcref_ty; let anyref_ty = i8_ptr_ty; let anyref_ty_basic_md: BasicMetadataTypeEnum = anyref_ty.into(); @@ -1094,13 +1094,13 @@ impl<'ctx> Intrinsics<'ctx> { vmfunction_import_ptr_ty: context .struct_type(&[i8_ptr_ty_basic, i8_ptr_ty_basic], false) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), vmfunction_import_body_element: 0, vmfunction_import_vmctx_element: 1, vmmemory_definition_ptr_ty: context .struct_type(&[i8_ptr_ty_basic, isize_ty.into()], false) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), vmmemory_definition_base_element: 0, vmmemory_definition_current_length_element: 1, @@ -1109,19 +1109,19 @@ impl<'ctx> Intrinsics<'ctx> { &[ctx_ptr_ty_basic_md, i32_ty_basic_md, i32_ty_basic_md], false, ) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), imported_memory32_grow_ptr_ty: i32_ty .fn_type( &[ctx_ptr_ty_basic_md, i32_ty_basic_md, i32_ty_basic_md], false, ) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), memory32_size_ptr_ty: i32_ty .fn_type(&[ctx_ptr_ty_basic_md, i32_ty_basic_md], false) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), imported_memory32_size_ptr_ty: i32_ty .fn_type(&[ctx_ptr_ty_basic_md, i32_ty_basic_md], false) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), memory32_wait32_ptr_ty: i32_ty .fn_type( &[ @@ -1133,7 +1133,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), imported_memory32_wait32_ptr_ty: i32_ty .fn_type( &[ @@ -1145,7 +1145,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), memory32_wait64_ptr_ty: i32_ty .fn_type( &[ @@ -1157,7 +1157,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), imported_memory32_wait64_ptr_ty: i32_ty .fn_type( &[ @@ -1169,7 +1169,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), memory32_notify_ptr_ty: i32_ty .fn_type( &[ @@ -1180,7 +1180,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), imported_memory32_notify_ptr_ty: i32_ty .fn_type( &[ @@ -1191,7 +1191,7 @@ impl<'ctx> Intrinsics<'ctx> { ], false, ) - .ptr_type(AddressSpace::default()), + .ptr_type(AddressSpace::Generic), ctx_ptr_ty, }; @@ -1316,7 +1316,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let memory_definition_ptr_ptr = cache_builder .build_bitcast( memory_definition_ptr_ptr, - intrinsics.i8_ptr_ty.ptr_type(AddressSpace::default()), + intrinsics.i8_ptr_ty.ptr_type(AddressSpace::Generic), "", ) .into_pointer_value(); @@ -1400,7 +1400,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let ptr_to_base_ptr = cache_builder .build_bitcast( ptr_to_base_ptr, - intrinsics.i8_ptr_ty.ptr_type(AddressSpace::default()), + intrinsics.i8_ptr_ty.ptr_type(AddressSpace::Generic), "", ) .into_pointer_value(); @@ -1426,7 +1426,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let definition_ptr_ptr = cache_builder .build_bitcast( definition_ptr_ptr, - intrinsics.i8_ptr_ty.ptr_type(AddressSpace::default()), + intrinsics.i8_ptr_ty.ptr_type(AddressSpace::Generic), "", ) .into_pointer_value(); @@ -1448,7 +1448,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let ptr_to_base_ptr = cache_builder .build_bitcast( ptr_to_base_ptr, - intrinsics.i8_ptr_ty.ptr_type(AddressSpace::default()), + intrinsics.i8_ptr_ty.ptr_type(AddressSpace::Generic), "", ) .into_pointer_value(); @@ -1570,7 +1570,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let global_ptr_ptr = cache_builder .build_bitcast( global_ptr_ptr, - intrinsics.i32_ptr_ty.ptr_type(AddressSpace::default()), + intrinsics.i32_ptr_ty.ptr_type(AddressSpace::Generic), "", ) .into_pointer_value(); @@ -1710,11 +1710,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { .unwrap(); let body_ptr = cache_builder.build_load(body_ptr_ptr, ""); let body_ptr = cache_builder - .build_bitcast( - body_ptr, - llvm_func_type.ptr_type(AddressSpace::default()), - "", - ) + .build_bitcast(body_ptr, llvm_func_type.ptr_type(AddressSpace::Generic), "") .into_pointer_value(); let vmctx_ptr_ptr = cache_builder .build_struct_gep( @@ -1764,7 +1760,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let grow_fn_ptr_ptr = cache_builder .build_bitcast( grow_fn_ptr_ptr, - grow_fn_ty.ptr_type(AddressSpace::default()), + grow_fn_ty.ptr_type(AddressSpace::Generic), "", ) .into_pointer_value(); @@ -1805,7 +1801,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let size_fn_ptr_ptr = cache_builder .build_bitcast( size_fn_ptr_ptr, - size_fn_ty.ptr_type(AddressSpace::default()), + size_fn_ty.ptr_type(AddressSpace::Generic), "", ) .into_pointer_value(); @@ -1847,7 +1843,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let size_fn_ptr_ptr = cache_builder .build_bitcast( size_fn_ptr_ptr, - size_fn_ty.ptr_type(AddressSpace::default()), + size_fn_ty.ptr_type(AddressSpace::Generic), "", ) .into_pointer_value(); @@ -1889,7 +1885,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let size_fn_ptr_ptr = cache_builder .build_bitcast( size_fn_ptr_ptr, - size_fn_ty.ptr_type(AddressSpace::default()), + size_fn_ty.ptr_type(AddressSpace::Generic), "", ) .into_pointer_value(); @@ -1931,7 +1927,7 @@ impl<'ctx, 'a> CtxType<'ctx, 'a> { let size_fn_ptr_ptr = cache_builder .build_bitcast( size_fn_ptr_ptr, - size_fn_ty.ptr_type(AddressSpace::default()), + size_fn_ty.ptr_type(AddressSpace::Generic), "", ) .into_pointer_value(); @@ -1970,6 +1966,13 @@ pub fn tbaa_label<'ctx>( let context = module.get_context(); + // TODO: StoreRef can't return us the lifetime from module through Deref. + // This could be fixed once generic_associated_types is stable. + let context = { + let context2 = &*context; + unsafe { std::mem::transmute::<&Context, &'ctx Context>(context2) } + }; + // `!wasmer_tbaa_root = {}`, the TBAA root node for wasmer. let tbaa_root = module .get_global_metadata("wasmer_tbaa_root") From deae5ef823b51525c4248a682dead5689373c9a4 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 2 Feb 2023 12:14:02 +0100 Subject: [PATCH 07/12] Updated Cranelift to 0.91 --- Cargo.lock | 53 +++++++---- lib/compiler-cranelift/Cargo.toml | 8 +- lib/compiler-cranelift/src/address_map.rs | 2 +- lib/compiler-cranelift/src/compiler.rs | 39 ++++++-- lib/compiler-cranelift/src/config.rs | 5 + lib/compiler-cranelift/src/func_environ.rs | 4 +- .../src/trampoline/dynamic_function.rs | 9 +- .../src/trampoline/function_call.rs | 5 +- .../src/translator/code_translator.rs | 92 +++++++++---------- .../src/translator/func_environ.rs | 4 +- .../src/translator/func_translator.rs | 3 +- .../src/translator/unwind.rs | 2 + 12 files changed, 129 insertions(+), 97 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6ce7ebaec..658e3bf3d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -580,26 +580,29 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "529ffacce2249ac60edba2941672dfedf3d96558b415d0d8083cd007456e0f55" +checksum = "fc952b310b24444fc14ab8b9cbe3fafd7e7329e3eec84c3a9b11d2b5cf6f3be1" dependencies = [ "cranelift-entity", ] [[package]] name = "cranelift-codegen" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "427d105f617efc8cb55f8d036a7fded2e227892d8780b4985e5551f8d27c4a92" +checksum = "e73470419b33011e50dbf0f6439cbccbaabe9381de172da4e1b6efcda4bb8fa7" dependencies = [ + "arrayvec 0.7.2", + "bumpalo", "cranelift-bforest", "cranelift-codegen-meta", "cranelift-codegen-shared", + "cranelift-egraph", "cranelift-entity", "cranelift-isle", "gimli 0.26.2", - "hashbrown 0.11.2", + "hashbrown 0.12.3", "log", "regalloc2", "smallvec", @@ -608,33 +611,47 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "551674bed85b838d45358e3eab4f0ffaa6790c70dc08184204b9a54b41cdb7d1" +checksum = "911a1872464108a11ac9965c2b079e61bbdf1bc2e0b9001264264add2e12a38f" dependencies = [ "cranelift-codegen-shared", ] [[package]] name = "cranelift-codegen-shared" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b3a63ae57498c3eb495360944a33571754241e15e47e3bcae6082f40fec5866" +checksum = "e036f3f07adb24a86fb46e977e8fe03b18bb16b1eada949cf2c48283e5f8a862" + +[[package]] +name = "cranelift-egraph" +version = "0.91.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d6c623f4b5d2a6bad32c403f03765d4484a827eb93ee78f8cb6219ef118fd59" +dependencies = [ + "cranelift-entity", + "fxhash", + "hashbrown 0.12.3", + "indexmap", + "log", + "smallvec", +] [[package]] name = "cranelift-entity" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11aa8aa624c72cc1c94ea3d0739fa61248260b5b14d3646f51593a88d67f3e6e" +checksum = "74385eb5e405b3562f0caa7bcc4ab9a93c7958dd5bcd0e910bffb7765eacd6fc" [[package]] name = "cranelift-frontend" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "544ee8f4d1c9559c9aa6d46e7aaeac4a13856d620561094f35527356c7d21bd0" +checksum = "8a4ac920422ee36bff2c66257fec861765e3d95a125cdf58d8c0f3bba7e40e61" dependencies = [ "cranelift-codegen", - "hashbrown 0.11.2", + "hashbrown 0.12.3", "log", "smallvec", "target-lexicon 0.12.5", @@ -642,9 +659,9 @@ dependencies = [ [[package]] name = "cranelift-isle" -version = "0.86.1" +version = "0.91.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed16b14363d929b8c37e3c557d0a7396791b383ecc302141643c054343170aad" +checksum = "c541263fb37ad2baa53ec8c37218ee5d02fa0984670d9419dedd8002ea68ff08" [[package]] name = "crc" @@ -2736,9 +2753,9 @@ checksum = "a0d51660a68078997855ba5602f73ab3a5031bd7ad480a9d4c90fbbf04e1fff0" [[package]] name = "regalloc2" -version = "0.3.2" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d43a209257d978ef079f3d446331d0f1794f5e0fc19b306a199983857833a779" +checksum = "300d4fbfb40c1c66a78ba3ddd41c1110247cf52f97b87d0f2fc9209bd49b030c" dependencies = [ "fxhash", "log", diff --git a/lib/compiler-cranelift/Cargo.toml b/lib/compiler-cranelift/Cargo.toml index 9e5a3a492..12122ea3c 100644 --- a/lib/compiler-cranelift/Cargo.toml +++ b/lib/compiler-cranelift/Cargo.toml @@ -14,9 +14,9 @@ edition = "2018" [dependencies] wasmer-compiler = { path = "../compiler", version = "=3.2.0-alpha.1", features = ["translator", "compiler"], default-features = false } wasmer-types = { path = "../types", version = "=3.2.0-alpha.1", default-features = false, features = ["std"] } -cranelift-entity = { version = "0.86.1", default-features = false } -cranelift-codegen = { version = "0.86.1", default-features = false, features = ["x86", "arm64"] } -cranelift-frontend = { version = "0.86.1", default-features = false } +cranelift-entity = { version = "0.91.0", default-features = false } +cranelift-codegen = { version = "0.91.0", default-features = false, features = ["x86", "arm64"] } +cranelift-frontend = { version = "0.91.0", default-features = false } tracing = "0.1" hashbrown = { version = "0.11", optional = true } rayon = { version = "1.5", optional = true } @@ -26,7 +26,7 @@ smallvec = "1.6" target-lexicon = { version = "0.12.2", default-features = false } [dev-dependencies] -cranelift-codegen = { version = "0.86.1", features = ["all-arch"] } +cranelift-codegen = { version = "0.91.0", features = ["all-arch"] } lazy_static = "1.4" [badges] diff --git a/lib/compiler-cranelift/src/address_map.rs b/lib/compiler-cranelift/src/address_map.rs index 3f6e22c54..2fe92429f 100644 --- a/lib/compiler-cranelift/src/address_map.rs +++ b/lib/compiler-cranelift/src/address_map.rs @@ -15,7 +15,7 @@ pub fn get_function_address_map( // New-style backend: we have a `MachCompileResult` that will give us `MachSrcLoc` mapping // tuples. - let mcr = context.mach_compile_result.as_ref().unwrap(); + let mcr = context.compiled_code().unwrap(); for &MachSrcLoc { start, end, loc } in mcr.buffer.get_srclocs_sorted() { instructions.push(InstructionAddressMap { srcloc: SourceLoc::new(loc.bits()), diff --git a/lib/compiler-cranelift/src/compiler.rs b/lib/compiler-cranelift/src/compiler.rs index 9f2481bb0..f638e278c 100644 --- a/lib/compiler-cranelift/src/compiler.rs +++ b/lib/compiler-cranelift/src/compiler.rs @@ -12,8 +12,7 @@ use crate::translator::{ compiled_function_unwind_info, irlibcall_to_libcall, irreloc_to_relocationkind, signature_to_cranelift_ir, CraneliftUnwindInfo, FuncTranslator, }; -use cranelift_codegen::ir::ExternalName; -use cranelift_codegen::print_errors::pretty_error; +use cranelift_codegen::ir::{ExternalName, UserFuncName}; use cranelift_codegen::{ir, MachReloc}; use cranelift_codegen::{Context, MachTrap}; #[cfg(feature = "unwind")] @@ -127,7 +126,18 @@ impl Compiler for CraneliftCompiler { &memory_styles, &table_styles, ); - context.func.name = get_function_name(func_index); + context.func.name = match get_function_name(func_index) { + ExternalName::User(nameref) => { + if context.func.params.user_named_funcs().is_valid(nameref) { + let name = &context.func.params.user_named_funcs()[nameref]; + UserFuncName::User(name.clone()) + } else { + ExternalName::default() + } + } + ExternalName::TestCase(testcase) => UserFuncName::Testcase(testcase), + _ => UserFuncName::default(), + }; context.func.signature = signatures[module.functions[func_index]].clone(); // if generate_debug_info { // context.func.collect_debug_info(); @@ -228,7 +238,18 @@ impl Compiler for CraneliftCompiler { memory_styles, table_styles, ); - context.func.name = get_function_name(func_index); + context.func.name = match get_function_name(func_index) { + ExternalName::User(nameref) => { + if context.func.params.user_named_funcs().is_valid(nameref) { + let name = &context.func.params.user_named_funcs()[nameref]; + UserFuncName::User(name.clone()) + } else { + UserFuncName::default() + } + } + ExternalName::TestCase(testcase) => UserFuncName::Testcase(testcase), + _ => UserFuncName::default(), + }; context.func.signature = signatures[module.functions[func_index]].clone(); // if generate_debug_info { // context.func.collect_debug_info(); @@ -252,9 +273,9 @@ impl Compiler for CraneliftCompiler { let mut code_buf: Vec = Vec::new(); context .compile_and_emit(&*isa, &mut code_buf) - .map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?; + .map_err(|error| CompileError::Codegen(error.inner.to_string()))?; - let result = context.mach_compile_result.as_ref().unwrap(); + let result = context.compiled_code().unwrap(); let func_relocs = result .buffer .relocs() @@ -401,11 +422,11 @@ fn mach_reloc_to_reloc(module: &ModuleInfo, reloc: &MachReloc) -> Relocation { ref name, addend, } = reloc; - let reloc_target = if let ExternalName::User { namespace, index } = *name { - debug_assert_eq!(namespace, 0); + let reloc_target = if let ExternalName::User(extname_ref) = *name { + //debug_assert_eq!(namespace, 0); RelocationTarget::LocalFunc( module - .local_func_index(FunctionIndex::from_u32(index)) + .local_func_index(FunctionIndex::from_u32(extname_ref.as_u32())) .expect("The provided function should be local"), ) } else if let ExternalName::LibCall(libcall) = *name { diff --git a/lib/compiler-cranelift/src/config.rs b/lib/compiler-cranelift/src/config.rs index 5c757c9ef..dff2ba119 100644 --- a/lib/compiler-cranelift/src/config.rs +++ b/lib/compiler-cranelift/src/config.rs @@ -124,6 +124,11 @@ impl Cranelift { pub fn flags(&self) -> settings::Flags { let mut flags = settings::builder(); + // Enable probestack + flags + .enable("enable_probestack") + .expect("should be valid flag"); + // There are two possible traps for division, and this way // we get the proper one if code traps. flags diff --git a/lib/compiler-cranelift/src/func_environ.rs b/lib/compiler-cranelift/src/func_environ.rs index 0608b7add..d71153235 100644 --- a/lib/compiler-cranelift/src/func_environ.rs +++ b/lib/compiler-cranelift/src/func_environ.rs @@ -27,7 +27,7 @@ use wasmer_types::{WasmError, WasmResult}; /// Compute an `ir::ExternalName` for a given wasm function index. pub fn get_function_name(func_index: FunctionIndex) -> ir::ExternalName { - ir::ExternalName::user(0, func_index.as_u32()) + ir::ExternalName::user(ir::UserExternalNameRef::from_u32(func_index.as_u32())) } /// The type of the `current_elements` field. @@ -1028,7 +1028,7 @@ impl<'module_environment> BaseFuncEnvironment for FuncEnvironment<'module_enviro _ => unreachable!(), }; - Ok(pos.ins().bint(ir::types::I32, bool_is_null)) + Ok(pos.ins().uextend(ir::types::I32, bool_is_null)) } fn translate_ref_func( diff --git a/lib/compiler-cranelift/src/trampoline/dynamic_function.rs b/lib/compiler-cranelift/src/trampoline/dynamic_function.rs index 37ea9d46f..f7f84edc3 100644 --- a/lib/compiler-cranelift/src/trampoline/dynamic_function.rs +++ b/lib/compiler-cranelift/src/trampoline/dynamic_function.rs @@ -6,10 +6,9 @@ use crate::translator::{compiled_function_unwind_info, signature_to_cranelift_ir}; use cranelift_codegen::ir; use cranelift_codegen::ir::{ - ExternalName, Function, InstBuilder, MemFlags, StackSlotData, StackSlotKind, + Function, InstBuilder, MemFlags, StackSlotData, StackSlotKind, UserFuncName, }; use cranelift_codegen::isa::TargetIsa; -use cranelift_codegen::print_errors::pretty_error; use cranelift_codegen::Context; use std::cmp; use std::mem; @@ -43,9 +42,9 @@ pub fn make_trampoline_dynamic_function( (value_size * cmp::max(signature.params.len() - 1, signature.returns.len())) as u32; let mut context = Context::new(); - context.func = Function::with_name_signature(ExternalName::user(0, 0), signature.clone()); + context.func = Function::with_name_signature(UserFuncName::user(0, 0), signature.clone()); - let ss = context.func.create_stack_slot(StackSlotData::new( + let ss = context.func.create_sized_stack_slot(StackSlotData::new( StackSlotKind::ExplicitSlot, values_vec_len, )); @@ -107,7 +106,7 @@ pub fn make_trampoline_dynamic_function( let mut code_buf = Vec::new(); context .compile_and_emit(isa, &mut code_buf) - .map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?; + .map_err(|error| CompileError::Codegen(error.inner.to_string()))?; let unwind_info = compiled_function_unwind_info(isa, &context)?.maybe_into_to_windows_unwind(); diff --git a/lib/compiler-cranelift/src/trampoline/function_call.rs b/lib/compiler-cranelift/src/trampoline/function_call.rs index 12d8d2eb7..8d6741d3d 100644 --- a/lib/compiler-cranelift/src/trampoline/function_call.rs +++ b/lib/compiler-cranelift/src/trampoline/function_call.rs @@ -12,7 +12,6 @@ use crate::translator::{compiled_function_unwind_info, signature_to_cranelift_ir use cranelift_codegen::ir; use cranelift_codegen::ir::InstBuilder; use cranelift_codegen::isa::TargetIsa; -use cranelift_codegen::print_errors::pretty_error; use cranelift_codegen::Context; use cranelift_frontend::{FunctionBuilder, FunctionBuilderContext}; use std::mem; @@ -42,7 +41,7 @@ pub fn make_trampoline_function_call( wrapper_sig.params.push(ir::AbiParam::new(pointer_type)); let mut context = Context::new(); - context.func = ir::Function::with_name_signature(ir::ExternalName::user(0, 0), wrapper_sig); + context.func = ir::Function::with_name_signature(ir::UserFuncName::user(0, 0), wrapper_sig); let value_size = mem::size_of::(); { @@ -105,7 +104,7 @@ pub fn make_trampoline_function_call( context .compile_and_emit(isa, &mut code_buf) - .map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?; + .map_err(|error| CompileError::Codegen(error.inner.to_string()))?; let unwind_info = compiled_function_unwind_info(isa, &context)?.maybe_into_to_windows_unwind(); diff --git a/lib/compiler-cranelift/src/translator/code_translator.rs b/lib/compiler-cranelift/src/translator/code_translator.rs index 6b42a8e6c..fb2de48eb 100644 --- a/lib/compiler-cranelift/src/translator/code_translator.rs +++ b/lib/compiler-cranelift/src/translator/code_translator.rs @@ -124,7 +124,7 @@ pub fn translate_operator( * disappear in the Cranelift Code ***********************************************************************************/ Operator::LocalGet { local_index } => { - let val = builder.use_var(Variable::with_u32(*local_index)); + let val = builder.use_var(Variable::from_u32(*local_index)); state.push1(val); let label = ValueLabel::from_u32(*local_index); builder.set_val_label(val, label); @@ -138,7 +138,7 @@ pub fn translate_operator( val = optionally_bitcast_vector(val, I8X16, builder); } - builder.def_var(Variable::with_u32(*local_index), val); + builder.def_var(Variable::from_u32(*local_index), val); let label = ValueLabel::from_u32(*local_index); builder.set_val_label(val, label); } @@ -151,7 +151,7 @@ pub fn translate_operator( val = optionally_bitcast_vector(val, I8X16, builder); } - builder.def_var(Variable::with_u32(*local_index), val); + builder.def_var(Variable::from_u32(*local_index), val); let label = ValueLabel::from_u32(*local_index); builder.set_val_label(val, label); } @@ -368,8 +368,7 @@ pub fn translate_operator( Operator::End => { let frame = state.control_stack.pop().unwrap(); let next_block = frame.following_code(); - - if !builder.is_unreachable() || !builder.is_pristine() { + if !builder.is_unreachable() || builder.func.layout.first_inst(next_block).is_some() { let return_count = frame.num_return_values(); let return_args = state.peekn(return_count); canonicalise_then_jump(builder, frame.following_code(), return_args); @@ -519,11 +518,8 @@ pub fn translate_operator( state.reachable = false; } Operator::Return => { - let (return_count, br_destination) = { + let (return_count, _br_destination) = { let frame = &mut state.control_stack[0]; - if environ.return_mode() == ReturnMode::FallthroughReturn { - frame.set_branched_to_exit(); - } let return_count = frame.num_return_values(); (return_count, frame.br_destination()) }; @@ -536,9 +532,6 @@ pub fn translate_operator( bitcast_arguments(return_args, &return_types, builder); match environ.return_mode() { ReturnMode::NormalReturns => builder.ins().return_(return_args), - ReturnMode::FallthroughReturn => { - canonicalise_then_jump(builder, br_destination, return_args) - } }; } state.popn(return_count); @@ -861,19 +854,19 @@ pub fn translate_operator( } Operator::F32ReinterpretI32 => { let val = state.pop1(); - state.push1(builder.ins().bitcast(F32, val)); + state.push1(builder.ins().bitcast(F32, MemFlags::new(), val)); } Operator::F64ReinterpretI64 => { let val = state.pop1(); - state.push1(builder.ins().bitcast(F64, val)); + state.push1(builder.ins().bitcast(F64, MemFlags::new(), val)); } Operator::I32ReinterpretF32 => { let val = state.pop1(); - state.push1(builder.ins().bitcast(I32, val)); + state.push1(builder.ins().bitcast(I32, MemFlags::new(), val)); } Operator::I64ReinterpretF64 => { let val = state.pop1(); - state.push1(builder.ins().bitcast(I64, val)); + state.push1(builder.ins().bitcast(I64, MemFlags::new(), val)); } Operator::I32Extend8S => { let val = state.pop1(); @@ -1022,7 +1015,7 @@ pub fn translate_operator( Operator::I32Eqz | Operator::I64Eqz => { let arg = state.pop1(); let val = builder.ins().icmp_imm(IntCC::Equal, arg, 0); - state.push1(builder.ins().bint(I32, val)); + state.push1(builder.ins().uextend(I32, val)); } Operator::I32Eq | Operator::I64Eq => translate_icmp(IntCC::Equal, builder, state), Operator::F32Eq | Operator::F64Eq => translate_fcmp(FloatCC::Equal, builder, state), @@ -1583,7 +1576,7 @@ pub fn translate_operator( } Operator::I8x16MinS | Operator::I16x8MinS | Operator::I32x4MinS => { let (a, b) = pop2_with_bitcast(state, type_of(op), builder); - state.push1(builder.ins().imin(a, b)) + state.push1(builder.ins().smin(a, b)) } Operator::I8x16MinU | Operator::I16x8MinU | Operator::I32x4MinU => { let (a, b) = pop2_with_bitcast(state, type_of(op), builder); @@ -1591,7 +1584,7 @@ pub fn translate_operator( } Operator::I8x16MaxS | Operator::I16x8MaxS | Operator::I32x4MaxS => { let (a, b) = pop2_with_bitcast(state, type_of(op), builder); - state.push1(builder.ins().imax(a, b)) + state.push1(builder.ins().smax(a, b)) } Operator::I8x16MaxU | Operator::I16x8MaxU | Operator::I32x4MaxU => { let (a, b) = pop2_with_bitcast(state, type_of(op), builder); @@ -1672,7 +1665,7 @@ pub fn translate_operator( Operator::V128AnyTrue => { let a = pop1_with_bitcast(state, type_of(op), builder); let bool_result = builder.ins().vany_true(a); - state.push1(builder.ins().bint(I32, bool_result)) + state.push1(builder.ins().uextend(I32, bool_result)) } Operator::I8x16AllTrue | Operator::I16x8AllTrue @@ -1680,7 +1673,7 @@ pub fn translate_operator( | Operator::I64x2AllTrue => { let a = pop1_with_bitcast(state, type_of(op), builder); let bool_result = builder.ins().vall_true(a); - state.push1(builder.ins().bint(I32, bool_result)) + state.push1(builder.ins().uextend(I32, bool_result)) } Operator::I8x16Bitmask | Operator::I16x8Bitmask @@ -2253,7 +2246,9 @@ fn get_heap_addr( }; debug_assert!(adjusted_offset > 0); // want to bounds check at least 1 byte let check_size = u32::try_from(adjusted_offset).unwrap_or(u32::MAX); - let base = builder.ins().heap_addr(addr_ty, heap, addr32, check_size); + let base = builder + .ins() + .heap_addr(addr_ty, heap, addr32, 0u32, check_size as u8); // Native load/store instructions take a signed `Offset32` immediate, so adjust the base // pointer if necessary. @@ -2359,7 +2354,7 @@ fn mem_op_size(opcode: ir::Opcode, ty: Type) -> u32 { fn translate_icmp(cc: IntCC, builder: &mut FunctionBuilder, state: &mut FuncTranslationState) { let (arg0, arg1) = state.pop2(); let val = builder.ins().icmp(cc, arg0, arg1); - state.push1(builder.ins().bint(I32, val)); + state.push1(builder.ins().uextend(I32, val)); } fn fold_atomic_mem_addr( @@ -2375,12 +2370,10 @@ fn fold_atomic_mem_addr( let a = builder .ins() .iadd_imm(linear_mem_addr, memarg.offset as i64); - let cflags = builder.ins().ifcmp_imm(a, 0x1_0000_0000i64); - builder.ins().trapif( - IntCC::UnsignedGreaterThanOrEqual, - cflags, - ir::TrapCode::HeapOutOfBounds, - ); + let r = builder + .ins() + .icmp_imm(IntCC::UnsignedGreaterThanOrEqual, a, 0x1_0000_0000i64); + builder.ins().trapnz(r, ir::TrapCode::HeapOutOfBounds); builder.ins().ireduce(I32, a) } else { linear_mem_addr @@ -2391,10 +2384,8 @@ fn fold_atomic_mem_addr( .band_imm(final_lma, i64::from(access_ty_bytes - 1)); let f = builder .ins() - .ifcmp_imm(final_lma_misalignment, i64::from(0)); - builder - .ins() - .trapif(IntCC::NotEqual, f, ir::TrapCode::HeapMisaligned); + .icmp_imm(IntCC::Equal, final_lma_misalignment, i64::from(0)); + builder.ins().trapz(f, ir::TrapCode::HeapMisaligned); final_lma } @@ -2415,12 +2406,10 @@ fn finalise_atomic_mem_addr( let a = builder .ins() .iadd_imm(linear_mem_addr, memarg.offset as i64); - let cflags = builder.ins().ifcmp_imm(a, 0x1_0000_0000i64); - builder.ins().trapif( - IntCC::UnsignedGreaterThanOrEqual, - cflags, - ir::TrapCode::HeapOutOfBounds, - ); + let r = builder + .ins() + .icmp_imm(IntCC::UnsignedGreaterThanOrEqual, a, 0x1_0000_0000i64); + builder.ins().trapnz(r, ir::TrapCode::HeapOutOfBounds); builder.ins().ireduce(I32, a) } else { linear_mem_addr @@ -2433,10 +2422,8 @@ fn finalise_atomic_mem_addr( .band_imm(final_lma, i64::from(access_ty_bytes - 1)); let f = builder .ins() - .ifcmp_imm(final_lma_misalignment, i64::from(0)); - builder - .ins() - .trapif(IntCC::NotEqual, f, ir::TrapCode::HeapMisaligned); + .icmp_imm(IntCC::Equal, final_lma_misalignment, i64::from(0)); + builder.ins().trapz(f, ir::TrapCode::HeapMisaligned); } // Compute the final effective address. @@ -2647,7 +2634,7 @@ fn translate_vector_icmp( fn translate_fcmp(cc: FloatCC, builder: &mut FunctionBuilder, state: &mut FuncTranslationState) { let (arg0, arg1) = state.pop2(); let val = builder.ins().fcmp(cc, arg0, arg1); - state.push1(builder.ins().bint(I32, val)); + state.push1(builder.ins().uextend(I32, val)); } fn translate_vector_fcmp( @@ -2913,7 +2900,11 @@ fn optionally_bitcast_vector( builder: &mut FunctionBuilder, ) -> Value { if builder.func.dfg.value_type(value) != needed_type { - builder.ins().raw_bitcast(needed_type, value) + builder.ins().bitcast( + needed_type, + MemFlags::new().with_endianness(ir::Endianness::Little), + value, + ) } else { value } @@ -2921,10 +2912,7 @@ fn optionally_bitcast_vector( #[inline(always)] fn is_non_canonical_v128(ty: ir::Type) -> bool { - matches!( - ty, - B8X16 | B16X8 | B32X4 | B64X2 | I64X2 | I32X4 | I16X8 | F32X4 | F64X2 - ) + matches!(ty, I64X2 | I32X4 | I16X8 | F32X4 | F64X2) } /// Cast to I8X16, any vector values in `values` that are of "non-canonical" type (meaning, not @@ -2948,7 +2936,11 @@ fn canonicalise_v128_values<'a>( // Otherwise we'll have to cast, and push the resulting `Value`s into `canonicalised`. for v in values { tmp_canonicalised.push(if is_non_canonical_v128(builder.func.dfg.value_type(*v)) { - builder.ins().raw_bitcast(I8X16, *v) + builder.ins().bitcast( + I8X16, + MemFlags::new().with_endianness(ir::Endianness::Little), + *v, + ) } else { *v }); diff --git a/lib/compiler-cranelift/src/translator/func_environ.rs b/lib/compiler-cranelift/src/translator/func_environ.rs index 0ca674269..68b3a5c1d 100644 --- a/lib/compiler-cranelift/src/translator/func_environ.rs +++ b/lib/compiler-cranelift/src/translator/func_environ.rs @@ -46,8 +46,6 @@ pub enum GlobalVariable { pub enum ReturnMode { /// Use normal return instructions as needed. NormalReturns, - /// Use a single fallthrough return at the end of the function. - FallthroughReturn, } /// Environment affecting the translation of a WebAssembly. @@ -381,7 +379,7 @@ pub trait FuncEnvironment: TargetEnvironment { value: ir::Value, ) -> WasmResult { let is_null = pos.ins().is_null(value); - Ok(pos.ins().bint(ir::types::I64, is_null)) + Ok(pos.ins().uextend(ir::types::I64, is_null)) } /// Translate a `ref.func` WebAssembly instruction. diff --git a/lib/compiler-cranelift/src/translator/func_translator.rs b/lib/compiler-cranelift/src/translator/func_translator.rs index d8a4db96a..47972a45a 100644 --- a/lib/compiler-cranelift/src/translator/func_translator.rs +++ b/lib/compiler-cranelift/src/translator/func_translator.rs @@ -243,7 +243,7 @@ fn parse_function_body( // If the exit block is unreachable, it may not have the correct arguments, so we would // generate a return instruction that doesn't match the signature. if state.reachable { - debug_assert!(builder.is_pristine()); + //debug_assert!(builder.is_pristine()); if !builder.is_unreachable() { match environ.return_mode() { ReturnMode::NormalReturns => { @@ -253,7 +253,6 @@ fn parse_function_body( bitcast_arguments(&mut state.stack, &return_types, builder); builder.ins().return_(&state.stack) } - ReturnMode::FallthroughReturn => builder.ins().fallthrough_return(&state.stack), }; } } diff --git a/lib/compiler-cranelift/src/translator/unwind.rs b/lib/compiler-cranelift/src/translator/unwind.rs index 1aff474dd..4de700b2d 100644 --- a/lib/compiler-cranelift/src/translator/unwind.rs +++ b/lib/compiler-cranelift/src/translator/unwind.rs @@ -43,6 +43,8 @@ pub(crate) fn compiled_function_unwind_info( context: &Context, ) -> Result { let unwind_info = context + .compiled_code() + .unwrap() .create_unwind_info(isa) .map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?; From 9c764d0859e46648e14742e3534f9345218ebce9 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 2 Feb 2023 13:18:10 +0100 Subject: [PATCH 08/12] Fix non-rayon build of Cranelift compiler --- lib/compiler-cranelift/src/compiler.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/compiler-cranelift/src/compiler.rs b/lib/compiler-cranelift/src/compiler.rs index f638e278c..b2a880f69 100644 --- a/lib/compiler-cranelift/src/compiler.rs +++ b/lib/compiler-cranelift/src/compiler.rs @@ -132,7 +132,7 @@ impl Compiler for CraneliftCompiler { let name = &context.func.params.user_named_funcs()[nameref]; UserFuncName::User(name.clone()) } else { - ExternalName::default() + UserFuncName::default() } } ExternalName::TestCase(testcase) => UserFuncName::Testcase(testcase), @@ -161,9 +161,9 @@ impl Compiler for CraneliftCompiler { let mut code_buf: Vec = Vec::new(); context .compile_and_emit(&*isa, &mut code_buf) - .map_err(|error| CompileError::Codegen(pretty_error(&context.func, error)))?; + .map_err(|error| CompileError::Codegen(error.inner.to_string()))?; - let result = context.mach_compile_result.as_ref().unwrap(); + let result = context.compiled_code().unwrap(); let func_relocs = result .buffer .relocs() From d400ba3076e372a9a132ea7926fcdda76f07c109 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Wed, 1 Feb 2023 11:37:55 +0100 Subject: [PATCH 09/12] Improved handling of wasmer-headless generation and use on local run --- Makefile | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 5a2f6b8ed..f31360cf1 100644 --- a/Makefile +++ b/Makefile @@ -358,7 +358,7 @@ endif # Not really "all", just the default target that builds enough so make # install will go through. -all: build-wasmer build-capi +all: build-wasmer build-capi build-capi-headless check: check-wasmer check-wasmer-wasm check-capi @@ -561,7 +561,7 @@ test-wasi-unit: test-wasi: $(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --release --tests $(compiler_features) -- wasi::wasitests -test-integration-cli: build-wasmer build-capi package distribution +test-integration-cli: build-wasmer build-capi build-capi-headless package distribution cp ./dist/wasmer.tar.gz ./link.tar.gz rustup target add wasm32-wasi $(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --features webc_runner --no-fail-fast -p wasmer-integration-tests-cli -- --nocapture --test-threads=1 @@ -635,6 +635,10 @@ package-capi: cp target/headless/$(CARGO_TARGET)/release/wasmer.dll package/lib/wasmer-headless.dll ;\ fi + if [ -f target/headless/$(HOST_TARGET)/release/wasmer.dll ]; then \ + cp target/headless/$(HOST_TARGET)/release/wasmer.dll package/lib/wasmer-headless.dll ;\ + fi + if [ -f $(TARGET_DIR)/wasmer.dll.lib ]; then \ cp $(TARGET_DIR)/wasmer.dll.lib package/lib/wasmer.dll.lib ;\ fi @@ -643,6 +647,10 @@ package-capi: cp target/headless/$(CARGO_TARGET)/release/wasmer.dll.lib package/lib/wasmer-headless.dll.lib ;\ fi + if [ -f target/headless/$(HOST_TARGET)/release/wasmer.dll.lib ]; then \ + cp target/headless/$(HOST_TARGET)/release/wasmer.dll.lib package/lib/wasmer-headless.dll.lib ;\ + fi + if [ -f $(TARGET_DIR)/wasmer.lib ]; then \ cp $(TARGET_DIR)/wasmer.lib package/lib/wasmer.lib ;\ fi @@ -651,6 +659,10 @@ package-capi: cp target/headless/$(CARGO_TARGET)/release/wasmer.lib package/lib/wasmer-headless.lib ;\ fi + if [ -f target/headless/$(HOST_TARGET)/release/wasmer.lib ]; then \ + cp target/headless/$(HOST_TARGET)/release/wasmer.lib package/lib/wasmer-headless.lib ;\ + fi + if [ -f $(TARGET_DIR)/libwasmer.dylib ]; then \ cp $(TARGET_DIR)/libwasmer.dylib package/lib/libwasmer.dylib ;\ fi @@ -659,6 +671,10 @@ package-capi: cp target/headless/$(CARGO_TARGET)/release/libwasmer.dylib package/lib/libwasmer-headless.dylib ;\ fi + if [ -f target/headless/$(HOST_TARGET)/release/libwasmer.dylib ]; then \ + cp target/headless/$(HOST_TARGET)/release/libwasmer.dylib package/lib/libwasmer-headless.dylib ;\ + fi + if [ -f $(TARGET_DIR)/libwasmer.so ]; then \ cp $(TARGET_DIR)/libwasmer.so package/lib/libwasmer.so ;\ fi @@ -667,6 +683,10 @@ package-capi: cp target/headless/$(CARGO_TARGET)/release/libwasmer.so package/lib/libwasmer-headless.so ;\ fi + if [ -f target/headless/$(HOST_TARGET)/release/libwasmer.so ]; then \ + cp target/headless/$(HOST_TARGET)/release/libwasmer.so package/lib/libwasmer-headless.so ;\ + fi + if [ -f $(TARGET_DIR)/libwasmer.a ]; then \ cp $(TARGET_DIR)/libwasmer.a package/lib/libwasmer.a ;\ fi @@ -675,6 +695,10 @@ package-capi: cp target/headless/$(CARGO_TARGET)/release/libwasmer.a package/lib/libwasmer-headless.a ;\ fi + if [ -f target/headless/$(HOST_TARGET)/release/libwasmer.a ]; then \ + cp target/headless/$(HOST_TARGET)/release/libwasmer.a package/lib/libwasmer-headless.a ;\ + fi + if [ -f target/$(HOST_TARGET)/release/wasmer.dll ]; then \ cp target/$(HOST_TARGET)/release/wasmer.dll package/lib/wasmer.dll ;\ fi From 16ce7939871e3f409234ab4d8b6a55c3b967bd71 Mon Sep 17 00:00:00 2001 From: ptitSeb Date: Thu, 2 Feb 2023 10:18:13 +0100 Subject: [PATCH 10/12] Finetuning make test-integration-cli --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index f31360cf1..ec6365278 100644 --- a/Makefile +++ b/Makefile @@ -561,10 +561,10 @@ test-wasi-unit: test-wasi: $(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --release --tests $(compiler_features) -- wasi::wasitests -test-integration-cli: build-wasmer build-capi build-capi-headless package distribution +test-integration-cli: build-wasmer build-capi package-capi-headless package distribution cp ./dist/wasmer.tar.gz ./link.tar.gz rustup target add wasm32-wasi - $(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --features webc_runner --no-fail-fast -p wasmer-integration-tests-cli -- --nocapture --test-threads=1 + WASMER_DIR=`pwd`/package $(CARGO_BINARY) test $(CARGO_TARGET_FLAG) --features webc_runner --no-fail-fast -p wasmer-integration-tests-cli -- --nocapture --test-threads=1 # Before running this in the CI, we need to set up link.tar.gz and /cache/wasmer-[target].tar.gz test-integration-cli-ci: From d2bc1a6a602f4221bf31613f31f70c96127424aa Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 2 Feb 2023 15:57:57 +0100 Subject: [PATCH 11/12] Update login.rs --- lib/cli/src/commands/login.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/src/commands/login.rs b/lib/cli/src/commands/login.rs index e1d141db4..dd4239328 100644 --- a/lib/cli/src/commands/login.rs +++ b/lib/cli/src/commands/login.rs @@ -33,7 +33,7 @@ impl Login { registry_tld.suffix.as_deref(), ) { (Some(d), Some(s)) => { - format!("Please paste the login token for https://{d}.{s}/me") + format!("Please paste the login token from://{d}.{s}/settings/access-tokens") } _ => "Please paste the login token".to_string(), }; From 545a12ac93185f634844faa7e8e94049f475295b Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 2 Feb 2023 15:58:20 +0100 Subject: [PATCH 12/12] Update login.rs --- lib/cli/src/commands/login.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/cli/src/commands/login.rs b/lib/cli/src/commands/login.rs index dd4239328..fbfea96ad 100644 --- a/lib/cli/src/commands/login.rs +++ b/lib/cli/src/commands/login.rs @@ -33,7 +33,7 @@ impl Login { registry_tld.suffix.as_deref(), ) { (Some(d), Some(s)) => { - format!("Please paste the login token from://{d}.{s}/settings/access-tokens") + format!("Please paste the login token from https://{d}.{s}/settings/access-tokens") } _ => "Please paste the login token".to_string(), };