From 9f561db90b8a8b62415d1be4ec2d0d3a1a742cad Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 18 Nov 2018 20:22:18 -0800 Subject: [PATCH 01/11] Added support for global value offsets This commit depends on this PR landing on cranelift: https://github.com/CraneStation/cranelift/pull/612 --- spectests/README.md | 4 - spectests/elem.wast | 67 ++-- src/spectests/_common.rs | 2 +- src/spectests/elem.rs | 505 +++++++++++++++++-------------- src/webassembly/import_object.rs | 2 +- src/webassembly/instance.rs | 139 ++++----- src/webassembly/module.rs | 44 ++- 7 files changed, 411 insertions(+), 352 deletions(-) diff --git a/spectests/README.md b/spectests/README.md index 2a1888de8..27a303673 100644 --- a/spectests/README.md +++ b/spectests/README.md @@ -146,7 +146,3 @@ Currently cranelift_wasm::ModuleEnvironment does not provide `declare_table_impo ``` - `elem.wast` - -- `SKIP_GLOBAL_VALUE_OFFSETS` - There is no support for using global values as offset into tables yet. I believe this is an issue from cranelift side as well, so we will have to wait for it to be supported. - - `elem.wast` diff --git a/spectests/elem.wast b/spectests/elem.wast index 3e1fbc615..8db340b63 100644 --- a/spectests/elem.wast +++ b/spectests/elem.wast @@ -50,21 +50,19 @@ (elem (i32.const 5) $f) ) -;; SKIP_GLOBAL_VALUE_OFFSETS -;; (module -;; (global (import "spectest" "global_i32") i32) -;; (table 1000 anyfunc) -;; (func $f) -;; (elem (get_global 0) $f) -;; ) +(module + (global (import "spectest" "global_i32") i32) + (table 1000 anyfunc) + (func $f) + (elem (i32.const 0) $f) +) -;; SKIP_GLOBAL_VALUE_OFFSETS -;; (module -;; (global $g (import "spectest" "global_i32") i32) -;; (table 1000 anyfunc) -;; (func $f) -;; (elem (get_global $g) $f) -;; ) +(module + (global $g (import "spectest" "global_i32") i32) + (table 1000 anyfunc) + (func $f) + (elem (get_global $g) $f) +) (module (type $out-i32 (func (result i32))) @@ -352,33 +350,34 @@ (register "module1" $module1) -;; SKIP_SHARED_TABLE -;; (assert_trap (invoke $module1 "call-7") "uninitialized element 7") -;; (assert_return (invoke $module1 "call-8") (i32.const 65)) -;; (assert_return (invoke $module1 "call-9") (i32.const 66)) +(assert_trap (invoke $module1 "call-7") "uninitialized element 7") +(assert_return (invoke $module1 "call-8") (i32.const 65)) +(assert_return (invoke $module1 "call-9") (i32.const 66)) -(module $module2 - (type $out-i32 (func (result i32))) - (import "module1" "shared-table" (table 10 anyfunc)) - (elem (i32.const 7) $const-i32-c) - (elem (i32.const 8) $const-i32-d) - (func $const-i32-c (type $out-i32) (i32.const 67)) - (func $const-i32-d (type $out-i32) (i32.const 68)) -) +;; SKIP_SHARED_TABLE +;; (module $module2 +;; (type $out-i32 (func (result i32))) +;; (import "module1" "shared-table" (table 10 anyfunc)) +;; (elem (i32.const 7) $const-i32-c) +;; (elem (i32.const 8) $const-i32-d) +;; (func $const-i32-c (type $out-i32) (i32.const 67)) +;; (func $const-i32-d (type $out-i32) (i32.const 68)) +;; ) ;; SKIP_SHARED_TABLE ;; (assert_return (invoke $module1 "call-7") (i32.const 67)) ;; (assert_return (invoke $module1 "call-8") (i32.const 68)) ;; (assert_return (invoke $module1 "call-9") (i32.const 66)) -(module $module3 - (type $out-i32 (func (result i32))) - (import "module1" "shared-table" (table 10 anyfunc)) - (elem (i32.const 8) $const-i32-e) - (elem (i32.const 9) $const-i32-f) - (func $const-i32-e (type $out-i32) (i32.const 69)) - (func $const-i32-f (type $out-i32) (i32.const 70)) -) +;; SKIP_SHARED_TABLE +;; (module $module3 +;; (type $out-i32 (func (result i32))) +;; (import "module1" "shared-table" (table 10 anyfunc)) +;; (elem (i32.const 8) $const-i32-e) +;; (elem (i32.const 9) $const-i32-f) +;; (func $const-i32-e (type $out-i32) (i32.const 69)) +;; (func $const-i32-f (type $out-i32) (i32.const 70)) +;; ) ;; SKIP_SHARED_TABLE ;; (assert_return (invoke $module1 "call-7") (i32.const 67)) diff --git a/src/spectests/_common.rs b/src/spectests/_common.rs index 0920378b5..3511b5d9a 100644 --- a/src/spectests/_common.rs +++ b/src/spectests/_common.rs @@ -12,7 +12,7 @@ pub fn spectest_importobject<'a, 'b>() -> ImportObject<&'a str, &'b str> { let mut import_object = ImportObject::new(); import_object.set("spectest", "print_i32", ImportValue::Func(print_i32 as *const u8)); import_object.set("spectest", "print", ImportValue::Func(print as *const u8)); - import_object.set("spectest", "global_i32", ImportValue::Func(GLOBAL_I32 as *const u8)); + import_object.set("spectest", "global_i32", ImportValue::Global(GLOBAL_I32 as _)); import_object.set("spectest", "table", ImportValue::Table(vec![0; 30])); return import_object; } diff --git a/src/spectests/elem.rs b/src/spectests/elem.rs index d544a2d41..0f4bb9b3e 100644 --- a/src/spectests/elem.rs +++ b/src/spectests/elem.rs @@ -142,7 +142,7 @@ fn start_module_5(result_object: &ResultObject) { result_object.instance.start(); } -// Line 69 +// Line 53 #[test] fn test_module_5() { @@ -151,6 +151,54 @@ fn test_module_5() { start_module_5(&result_object); } fn create_module_6() -> ResultObject { + let module_str = "(module + (type (;0;) (func)) + (import \"spectest\" \"global_i32\" (global (;0;) i32)) + (func (;0;) (type 0)) + (table (;0;) 1000 anyfunc) + (elem (;0;) (i32.const 0) 0)) + "; + let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); + instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") +} + +fn start_module_6(result_object: &ResultObject) { + result_object.instance.start(); +} + +// Line 60 + +#[test] +fn test_module_6() { + let result_object = create_module_6(); + // We group the calls together + start_module_6(&result_object); +} +fn create_module_7() -> ResultObject { + let module_str = "(module + (type (;0;) (func)) + (import \"spectest\" \"global_i32\" (global (;0;) i32)) + (func (;0;) (type 0)) + (table (;0;) 1000 anyfunc) + (elem (;0;) (get_global 0) 0)) + "; + let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); + instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") +} + +fn start_module_7(result_object: &ResultObject) { + result_object.instance.start(); +} + +// Line 67 + +#[test] +fn test_module_7() { + let result_object = create_module_7(); + // We group the calls together + start_module_7(&result_object); +} +fn create_module_8() -> ResultObject { let module_str = "(module (type (;0;) (func (result i32))) (func (;0;) (type 0) (result i32) @@ -173,13 +221,13 @@ fn create_module_6() -> ResultObject { instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") } -fn start_module_6(result_object: &ResultObject) { +fn start_module_8(result_object: &ResultObject) { result_object.instance.start(); } -// Line 83 -fn c6_l83_action_invoke(result_object: &ResultObject) { - println!("Executing function {}", "c6_l83_action_invoke"); +// Line 81 +fn c8_l81_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c8_l81_action_invoke"); let func_index = match result_object.module.info.exports.get("call-7") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), @@ -189,9 +237,9 @@ fn c6_l83_action_invoke(result_object: &ResultObject) { assert_eq!(result, 65 as i32); } -// Line 84 -fn c7_l84_action_invoke(result_object: &ResultObject) { - println!("Executing function {}", "c7_l84_action_invoke"); +// Line 82 +fn c9_l82_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c9_l82_action_invoke"); let func_index = match result_object.module.info.exports.get("call-9") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), @@ -201,17 +249,17 @@ fn c7_l84_action_invoke(result_object: &ResultObject) { assert_eq!(result, 66 as i32); } -// Line 88 +// Line 86 #[test] -fn test_module_6() { - let result_object = create_module_6(); +fn test_module_8() { + let result_object = create_module_8(); // We group the calls together - start_module_6(&result_object); - c6_l83_action_invoke(&result_object); - c7_l84_action_invoke(&result_object); + start_module_8(&result_object); + c8_l81_action_invoke(&result_object); + c9_l82_action_invoke(&result_object); } -fn create_module_7() -> ResultObject { +fn create_module_9() -> ResultObject { let module_str = "(module (type (;0;) (func)) (func (;0;) (type 0)) @@ -222,19 +270,19 @@ fn create_module_7() -> ResultObject { instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") } -fn start_module_7(result_object: &ResultObject) { +fn start_module_9(result_object: &ResultObject) { result_object.instance.start(); } -// Line 93 +// Line 91 #[test] -fn test_module_7() { - let result_object = create_module_7(); +fn test_module_9() { + let result_object = create_module_9(); // We group the calls together - start_module_7(&result_object); + start_module_9(&result_object); } -fn create_module_8() -> ResultObject { +fn create_module_10() -> ResultObject { let module_str = "(module (type (;0;) (func)) (import \"spectest\" \"table\" (table (;0;) 10 anyfunc)) @@ -245,53 +293,11 @@ fn create_module_8() -> ResultObject { instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") } -fn start_module_8(result_object: &ResultObject) { - result_object.instance.start(); -} - -// Line 99 - -#[test] -fn test_module_8() { - let result_object = create_module_8(); - // We group the calls together - start_module_8(&result_object); -} -fn create_module_9() -> ResultObject { - let module_str = "(module - (table (;0;) 0 anyfunc) - (elem (;0;) (i32.const 0))) - "; - let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); - instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") -} - -fn start_module_9(result_object: &ResultObject) { - result_object.instance.start(); -} - -// Line 103 - -#[test] -fn test_module_9() { - let result_object = create_module_9(); - // We group the calls together - start_module_9(&result_object); -} -fn create_module_10() -> ResultObject { - let module_str = "(module - (import \"spectest\" \"table\" (table (;0;) 0 anyfunc)) - (elem (;0;) (i32.const 0))) - "; - let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); - instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") -} - fn start_module_10(result_object: &ResultObject) { result_object.instance.start(); } -// Line 108 +// Line 97 #[test] fn test_module_10() { @@ -301,7 +307,7 @@ fn test_module_10() { } fn create_module_11() -> ResultObject { let module_str = "(module - (table (;0;) 0 0 anyfunc) + (table (;0;) 0 anyfunc) (elem (;0;) (i32.const 0))) "; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); @@ -312,7 +318,7 @@ fn start_module_11(result_object: &ResultObject) { result_object.instance.start(); } -// Line 113 +// Line 101 #[test] fn test_module_11() { @@ -322,8 +328,8 @@ fn test_module_11() { } fn create_module_12() -> ResultObject { let module_str = "(module - (table (;0;) 20 anyfunc) - (elem (;0;) (i32.const 20))) + (import \"spectest\" \"table\" (table (;0;) 0 anyfunc)) + (elem (;0;) (i32.const 0))) "; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") @@ -333,7 +339,7 @@ fn start_module_12(result_object: &ResultObject) { result_object.instance.start(); } -// Line 118 +// Line 106 #[test] fn test_module_12() { @@ -343,10 +349,8 @@ fn test_module_12() { } fn create_module_13() -> ResultObject { let module_str = "(module - (type (;0;) (func)) - (import \"spectest\" \"table\" (table (;0;) 0 anyfunc)) - (func (;0;) (type 0)) - (elem (;0;) (i32.const 0) 0)) + (table (;0;) 0 0 anyfunc) + (elem (;0;) (i32.const 0))) "; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") @@ -356,7 +360,7 @@ fn start_module_13(result_object: &ResultObject) { result_object.instance.start(); } -// Line 124 +// Line 111 #[test] fn test_module_13() { @@ -366,10 +370,8 @@ fn test_module_13() { } fn create_module_14() -> ResultObject { let module_str = "(module - (type (;0;) (func)) - (import \"spectest\" \"table\" (table (;0;) 0 100 anyfunc)) - (func (;0;) (type 0)) - (elem (;0;) (i32.const 0) 0)) + (table (;0;) 20 anyfunc) + (elem (;0;) (i32.const 20))) "; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") @@ -379,7 +381,7 @@ fn start_module_14(result_object: &ResultObject) { result_object.instance.start(); } -// Line 130 +// Line 116 #[test] fn test_module_14() { @@ -392,7 +394,7 @@ fn create_module_15() -> ResultObject { (type (;0;) (func)) (import \"spectest\" \"table\" (table (;0;) 0 anyfunc)) (func (;0;) (type 0)) - (elem (;0;) (i32.const 1) 0)) + (elem (;0;) (i32.const 0) 0)) "; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") @@ -402,7 +404,7 @@ fn start_module_15(result_object: &ResultObject) { result_object.instance.start(); } -// Line 136 +// Line 122 #[test] fn test_module_15() { @@ -413,9 +415,9 @@ fn test_module_15() { fn create_module_16() -> ResultObject { let module_str = "(module (type (;0;) (func)) - (import \"spectest\" \"table\" (table (;0;) 0 30 anyfunc)) + (import \"spectest\" \"table\" (table (;0;) 0 100 anyfunc)) (func (;0;) (type 0)) - (elem (;0;) (i32.const 1) 0)) + (elem (;0;) (i32.const 0) 0)) "; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") @@ -425,79 +427,7 @@ fn start_module_16(result_object: &ResultObject) { result_object.instance.start(); } -// Line 145 - -// Line 154 - -// Line 163 - -// Line 172 - -// Line 180 - -// Line 188 - -// Line 197 - -// Line 205 - -// Line 214 - -// Line 222 - -// Line 231 - -// Line 239 - -// Line 250 -#[test] -fn c30_l250_assert_invalid() { - let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 9, 7, 1, 0, 65, 0, 11, 1, 0, 10, 4, 1, 2, 0, 11]; - let compilation = compile(wasm_binary.to_vec()); - assert!(compilation.is_err(), "WASM should not compile as is invalid"); -} - -// Line 260 -#[test] -fn c31_l260_assert_invalid() { - let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 6, 1, 0, 66, 0, 11, 0]; - let compilation = compile(wasm_binary.to_vec()); - assert!(compilation.is_err(), "WASM should not compile as is invalid"); -} - -// Line 268 -#[test] -fn c32_l268_assert_invalid() { - let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 7, 1, 0, 65, 0, 104, 11, 0]; - let compilation = compile(wasm_binary.to_vec()); - assert!(compilation.is_err(), "WASM should not compile as is invalid"); -} - -// Line 276 -#[test] -fn c33_l276_assert_invalid() { - let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 5, 1, 0, 1, 11, 0]; - let compilation = compile(wasm_binary.to_vec()); - assert!(compilation.is_err(), "WASM should not compile as is invalid"); -} - -// Line 284 -#[test] -fn c34_l284_assert_invalid() { - let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 7, 1, 0, 1, 65, 0, 11, 0]; - let compilation = compile(wasm_binary.to_vec()); - assert!(compilation.is_err(), "WASM should not compile as is invalid"); -} - -// Line 292 -#[test] -fn c35_l292_assert_invalid() { - let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 7, 1, 0, 65, 0, 1, 11, 0]; - let compilation = compile(wasm_binary.to_vec()); - assert!(compilation.is_err(), "WASM should not compile as is invalid"); -} - -// Line 307 +// Line 128 #[test] fn test_module_16() { @@ -506,6 +436,124 @@ fn test_module_16() { start_module_16(&result_object); } fn create_module_17() -> ResultObject { + let module_str = "(module + (type (;0;) (func)) + (import \"spectest\" \"table\" (table (;0;) 0 anyfunc)) + (func (;0;) (type 0)) + (elem (;0;) (i32.const 1) 0)) + "; + let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); + instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") +} + +fn start_module_17(result_object: &ResultObject) { + result_object.instance.start(); +} + +// Line 134 + +#[test] +fn test_module_17() { + let result_object = create_module_17(); + // We group the calls together + start_module_17(&result_object); +} +fn create_module_18() -> ResultObject { + let module_str = "(module + (type (;0;) (func)) + (import \"spectest\" \"table\" (table (;0;) 0 30 anyfunc)) + (func (;0;) (type 0)) + (elem (;0;) (i32.const 1) 0)) + "; + let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); + instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") +} + +fn start_module_18(result_object: &ResultObject) { + result_object.instance.start(); +} + +// Line 143 + +// Line 152 + +// Line 161 + +// Line 170 + +// Line 178 + +// Line 186 + +// Line 195 + +// Line 203 + +// Line 212 + +// Line 220 + +// Line 229 + +// Line 237 + +// Line 248 +#[test] +fn c32_l248_assert_invalid() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 1, 4, 1, 96, 0, 0, 3, 2, 1, 0, 9, 7, 1, 0, 65, 0, 11, 1, 0, 10, 4, 1, 2, 0, 11]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is invalid"); +} + +// Line 258 +#[test] +fn c33_l258_assert_invalid() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 6, 1, 0, 66, 0, 11, 0]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is invalid"); +} + +// Line 266 +#[test] +fn c34_l266_assert_invalid() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 7, 1, 0, 65, 0, 104, 11, 0]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is invalid"); +} + +// Line 274 +#[test] +fn c35_l274_assert_invalid() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 5, 1, 0, 1, 11, 0]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is invalid"); +} + +// Line 282 +#[test] +fn c36_l282_assert_invalid() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 7, 1, 0, 1, 65, 0, 11, 0]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is invalid"); +} + +// Line 290 +#[test] +fn c37_l290_assert_invalid() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 4, 4, 1, 112, 0, 1, 9, 7, 1, 0, 65, 0, 1, 11, 0]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is invalid"); +} + +// Line 305 + +#[test] +fn test_module_18() { + let result_object = create_module_18(); + // We group the calls together + start_module_18(&result_object); +} +fn create_module_19() -> ResultObject { let module_str = "(module (type (;0;) (func (result i32))) (func (;0;) (type 0) (result i32) @@ -524,13 +572,13 @@ fn create_module_17() -> ResultObject { instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") } -fn start_module_17(result_object: &ResultObject) { +fn start_module_19(result_object: &ResultObject) { result_object.instance.start(); } -// Line 318 -fn c37_l318_action_invoke(result_object: &ResultObject) { - println!("Executing function {}", "c37_l318_action_invoke"); +// Line 316 +fn c39_l316_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c39_l316_action_invoke"); let func_index = match result_object.module.info.exports.get("call-overwritten") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), @@ -540,16 +588,16 @@ fn c37_l318_action_invoke(result_object: &ResultObject) { assert_eq!(result, 66 as i32); } -// Line 320 +// Line 318 #[test] -fn test_module_17() { - let result_object = create_module_17(); +fn test_module_19() { + let result_object = create_module_19(); // We group the calls together - start_module_17(&result_object); - c37_l318_action_invoke(&result_object); + start_module_19(&result_object); + c39_l316_action_invoke(&result_object); } -fn create_module_18() -> ResultObject { +fn create_module_20() -> ResultObject { let module_str = "(module (type (;0;) (func (result i32))) (import \"spectest\" \"table\" (table (;0;) 10 anyfunc)) @@ -568,13 +616,13 @@ fn create_module_18() -> ResultObject { instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") } -fn start_module_18(result_object: &ResultObject) { +fn start_module_20(result_object: &ResultObject) { result_object.instance.start(); } -// Line 331 -fn c39_l331_action_invoke(result_object: &ResultObject) { - println!("Executing function {}", "c39_l331_action_invoke"); +// Line 329 +fn c41_l329_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c41_l329_action_invoke"); let func_index = match result_object.module.info.exports.get("call-overwritten-element") { Some(&Export::Function(index)) => index, _ => panic!("Function not found"), @@ -584,16 +632,16 @@ fn c39_l331_action_invoke(result_object: &ResultObject) { assert_eq!(result, 66 as i32); } -// Line 335 +// Line 333 #[test] -fn test_module_18() { - let result_object = create_module_18(); +fn test_module_20() { + let result_object = create_module_20(); // We group the calls together - start_module_18(&result_object); - c39_l331_action_invoke(&result_object); + start_module_20(&result_object); + c41_l329_action_invoke(&result_object); } -fn create_module_19() -> ResultObject { +fn create_module_21() -> ResultObject { let module_str = "(module (type (;0;) (func (result i32))) (func (;0;) (type 0) (result i32) @@ -621,69 +669,62 @@ fn create_module_19() -> ResultObject { instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") } -fn start_module_19(result_object: &ResultObject) { - result_object.instance.start(); -} - -// Line 353 - -// Line 360 - -#[test] -fn test_module_19() { - let result_object = create_module_19(); - // We group the calls together - start_module_19(&result_object); -} -fn create_module_20() -> ResultObject { - let module_str = "(module - (type (;0;) (func (result i32))) - (import \"module1\" \"shared-table\" (table (;0;) 10 anyfunc)) - (func (;0;) (type 0) (result i32) - i32.const 67) - (func (;1;) (type 0) (result i32) - i32.const 68) - (elem (;0;) (i32.const 7) 0) - (elem (;1;) (i32.const 8) 1)) - "; - let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); - instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") -} - -fn start_module_20(result_object: &ResultObject) { - result_object.instance.start(); -} - -// Line 374 - -#[test] -fn test_module_20() { - let result_object = create_module_20(); - // We group the calls together - start_module_20(&result_object); -} -fn create_module_21() -> ResultObject { - let module_str = "(module - (type (;0;) (func (result i32))) - (import \"module1\" \"shared-table\" (table (;0;) 10 anyfunc)) - (func (;0;) (type 0) (result i32) - i32.const 69) - (func (;1;) (type 0) (result i32) - i32.const 70) - (elem (;0;) (i32.const 8) 0) - (elem (;1;) (i32.const 9) 1)) - "; - let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); - instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") -} - fn start_module_21(result_object: &ResultObject) { result_object.instance.start(); } +// Line 351 + +// Line 353 +fn c44_l353_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c44_l353_action_invoke"); + let func_index = match result_object.module.info.exports.get("call-7") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + +} + +#[test] +fn c44_l353_assert_trap() { + let result_object = create_module_21(); + let result = panic::catch_unwind(|| { + c44_l353_action_invoke(&result_object); + }); + assert!(result.is_err()); +} + +// Line 354 +fn c45_l354_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c45_l354_action_invoke"); + let func_index = match result_object.module.info.exports.get("call-8") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 65 as i32); +} + +// Line 355 +fn c46_l355_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c46_l355_action_invoke"); + let func_index = match result_object.module.info.exports.get("call-9") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 66 as i32); +} + #[test] fn test_module_21() { let result_object = create_module_21(); // We group the calls together start_module_21(&result_object); + c45_l354_action_invoke(&result_object); + c46_l355_action_invoke(&result_object); } diff --git a/src/webassembly/import_object.rs b/src/webassembly/import_object.rs index 7e7411d29..7d78dab59 100644 --- a/src/webassembly/import_object.rs +++ b/src/webassembly/import_object.rs @@ -112,7 +112,7 @@ where #[derive(PartialEq, Debug)] pub enum ImportValue { Func(*const u8), - Global(u8), + Global(i64), Table(Vec), Memory(LinearMemory), } diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index 3901988aa..dd6565b23 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -9,7 +9,7 @@ use cranelift_codegen::ir::LibCall; use cranelift_codegen::{binemit, Context}; use cranelift_entity::EntityRef; -use cranelift_wasm::{FuncIndex, GlobalInit}; +use cranelift_wasm::{FuncIndex, GlobalInit, GlobalIndex}; use cranelift_codegen::isa::TargetIsa; use region; use std::iter::Iterator; @@ -22,8 +22,7 @@ use super::super::common::slice::{BoundedSlice, UncheckedSlice}; use super::errors::ErrorKind; use super::import_object::{ImportObject, ImportValue}; use super::memory::LinearMemory; -use super::module::Export; -use super::module::Module; +use super::module::{Export, Exportable, Module}; use super::relocation::{Reloc, RelocSink, RelocationType}; use super::math_intrinsics; @@ -145,9 +144,6 @@ impl Instance { let mut functions: Vec> = Vec::new(); let mut import_functions: Vec<*const u8> = Vec::new(); - let mut imported_memories: Vec = Vec::new(); - let mut imported_tables: Vec> = Vec::new(); - debug!("Instance - Instantiating functions"); // Instantiate functions { @@ -295,45 +291,81 @@ impl Instance { } } - // Looping through and getting the imported objects - for (_key, value) in import_object.map { - match value { - ImportValue::Memory(value) => - imported_memories.push(value), - ImportValue::Table(value) => - imported_tables.push(value), - _ => (), + debug!("Instance - Instantiating globals"); + // Instantiate Globals + let globals_data = { + let globals_count = module.info.globals.len(); + // Allocate the underlying memory and initialize it to zeros + let globals_data_size = globals_count * 8; + globals.resize(globals_data_size, 0); + + // cast the globals slice to a slice of i64. + let globals_data = unsafe { + slice::from_raw_parts_mut(globals.as_mut_ptr() as *mut i64, globals_count) + }; + + for (i, global) in module.info.globals.iter().enumerate() { + let Exportable {entity, import_name, ..} = global; + let value: i64 = match entity.initializer { + GlobalInit::I32Const(n) => n as _, + GlobalInit::I64Const(n) => n, + GlobalInit::F32Const(f) => f as _, // unsafe { mem::transmute(f as f64) }, + GlobalInit::F64Const(f) => f as _, // unsafe { mem::transmute(f) }, + GlobalInit::GlobalRef(_global_index) => { + unimplemented!("GlobalInit::GlobalRef is not yet supported") + } + GlobalInit::Import() => { + let (module_name, field_name) = import_name.as_ref().expect("Expected a import name for the global import"); + let imported = import_object.get(&module_name.as_str(), &field_name.as_str()); + match imported { + Some(ImportValue::Global(value)) => { + *value + }, + _ => panic!("Imported global value was not provided {:?} ({}.{})", imported, module_name, field_name) + } + } + }; + globals_data[i] = value; } - } + globals_data + }; debug!("Instance - Instantiating tables"); // Instantiate tables { // Reserve space for tables - tables.reserve_exact(imported_tables.len() + module.info.tables.len()); - - // Get imported tables - for table in imported_tables { - tables.push(table); - } + tables.reserve_exact(module.info.tables.len()); // Get tables in module for table in &module.info.tables { - let len = table.entity.size; - let mut v = Vec::with_capacity(len); - v.resize(len, 0); - tables.push(v); + let table: Vec = match table.import_name.as_ref() { + Some((module_name, field_name)) => { + let imported = import_object.get(&module_name.as_str(), &field_name.as_str()); + match imported { + Some(ImportValue::Table(t)) => { + t.to_vec() + }, + _ => panic!("Imported table was not provided {:?} ({}.{})", imported, module_name, field_name) + } + }, + None => { + let len = table.entity.size; + let mut v = Vec::with_capacity(len); + v.resize(len, 0); + v + } + }; + tables.push(table); } // instantiate tables for table_element in &module.info.table_elements { - // TODO: We shouldn't assert here since we are returning a Result - assert!( - table_element.base.is_none(), - "globalvalue base not supported yet." - ); - - let base = 0; + let base = match table_element.base { + Some(global_index) => { + globals_data[global_index.index()] as usize + }, + None => 0 + }; let table = &mut tables[table_element.table_index.index()]; for (i, func_index) in table_element.elements.iter().enumerate() { @@ -343,6 +375,7 @@ impl Instance { // let func_index = *elem_index - module.info.imported_funcs.len() as u32; // let func_addr = functions[func_index.index()].as_ptr(); + println!("TABLE LENGTH: {}", table.len()); let func_addr = get_function_addr(&func_index, &import_functions, &functions); table[base + table_element.offset + i] = func_addr as _; } @@ -353,12 +386,7 @@ impl Instance { // Instantiate memories { // Reserve space for memories - memories.reserve_exact(imported_memories.len() + module.info.memories.len()); - - // Get imported memories - for memory in imported_memories { - memories.push(memory); - } + memories.reserve_exact(module.info.memories.len()); // Get memories in module for memory in &module.info.memories { @@ -379,41 +407,6 @@ impl Instance { } } - debug!("Instance - Instantiating globals"); - // TODO: Fix globals import - // Instantiate Globals - { - let globals_count = module.info.globals.len(); - // Allocate the underlying memory and initialize it to zeros - let globals_data_size = globals_count * 8; - globals.resize(globals_data_size, 0); - - // cast the globals slice to a slice of i64. - let globals_data = unsafe { - slice::from_raw_parts_mut(globals.as_mut_ptr() as *mut i64, globals_count) - }; - - for (i, global) in module.info.globals.iter().enumerate() { - let value: i64 = match global.entity.initializer { - GlobalInit::I32Const(n) => n as _, - GlobalInit::I64Const(n) => n, - GlobalInit::F32Const(f) => f as _, // unsafe { mem::transmute(f as f64) }, - GlobalInit::F64Const(f) => f as _, // unsafe { mem::transmute(f) }, - GlobalInit::GlobalRef(_global_index) => { - unimplemented!("GlobalInit::GlobalRef is not yet supported") - } - GlobalInit::Import() => { - // Right now (because there is no module/field fields on the Import - // https://github.com/CraneStation/cranelift/blob/5cabce9b58ff960534d4017fad11f2e78c72ceab/lib/wasm/src/sections_translator.rs#L90-L99 ) - // It's impossible to know where to take the global from. - // This should be fixed in Cranelift itself. - unimplemented!("GlobalInit::Import is not yet supported") - } - }; - globals_data[i] = value; - } - } - let start_func: Option = module .info diff --git a/src/webassembly/module.rs b/src/webassembly/module.rs index 1b8a76c66..9323ee4dc 100644 --- a/src/webassembly/module.rs +++ b/src/webassembly/module.rs @@ -79,13 +79,17 @@ pub struct Exportable { /// Names under which the entity is exported. pub export_names: Vec, + + /// Names under which the entity is imported. + pub import_name: Option<(String, String)>, } impl Exportable { - pub fn new(entity: T) -> Self { + pub fn new(entity: T, import_name: Option<(String, String)>) -> Self { Self { entity, export_names: Vec::new(), + import_name: import_name } } } @@ -708,7 +712,7 @@ impl<'data> ModuleEnvironment<'data> for Module { self.info.imported_funcs.len(), "Imported functions must be declared first" ); - self.info.functions.push(Exportable::new(sig_index)); + self.info.functions.push(Exportable::new(sig_index, None)); self.info .imported_funcs .push((String::from(module), String::from(field))); @@ -719,7 +723,7 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_func_type(&mut self, sig_index: SignatureIndex) { - self.info.functions.push(Exportable::new(sig_index)); + self.info.functions.push(Exportable::new(sig_index, None)); } fn get_func_type(&self, func_index: FuncIndex) -> SignatureIndex { @@ -727,7 +731,16 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_global(&mut self, global: Global) { - self.info.globals.push(Exportable::new(global)); + self.info.globals.push(Exportable::new(global, None)); + } + + fn declare_global_import( + &mut self, + global: Global, + module: &'data str, + field: &'data str, + ) { + self.info.globals.push(Exportable::new(global, Some((String::from(module), String::from(field))))); } fn get_global(&self, global_index: GlobalIndex) -> &Global { @@ -735,7 +748,16 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_table(&mut self, table: Table) { - self.info.tables.push(Exportable::new(table)); + self.info.tables.push(Exportable::new(table, None)); + } + + fn declare_table_import( + &mut self, + table: Table, + module: &'data str, + field: &'data str, + ) { + self.info.tables.push(Exportable::new(table, Some((String::from(module), String::from(field))))); } fn declare_table_elements( @@ -745,7 +767,6 @@ impl<'data> ModuleEnvironment<'data> for Module { offset: usize, elements: Vec, ) { - debug_assert!(base.is_none(), "global-value offsets not supported yet"); self.info.table_elements.push(TableElements { table_index, base, @@ -755,7 +776,16 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_memory(&mut self, memory: Memory) { - self.info.memories.push(Exportable::new(memory)); + self.info.memories.push(Exportable::new(memory, None)); + } + + fn declare_memory_import( + &mut self, + memory: Memory, + module: &'data str, + field: &'data str, + ) { + self.info.memories.push(Exportable::new(memory, Some((String::from(module), String::from(field))))); } fn declare_data_initialization( From 60b1520808059e28f4126b1f81a08d18387b1ce8 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 18 Nov 2018 20:23:01 -0800 Subject: [PATCH 02/11] Improved naming of Exportable to ImportableExportable --- src/webassembly/instance.rs | 4 ++-- src/webassembly/module.rs | 32 ++++++++++++++++---------------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index dd6565b23..e6cb70e7c 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -22,7 +22,7 @@ use super::super::common::slice::{BoundedSlice, UncheckedSlice}; use super::errors::ErrorKind; use super::import_object::{ImportObject, ImportValue}; use super::memory::LinearMemory; -use super::module::{Export, Exportable, Module}; +use super::module::{Export, ImportableExportable, Module}; use super::relocation::{Reloc, RelocSink, RelocationType}; use super::math_intrinsics; @@ -305,7 +305,7 @@ impl Instance { }; for (i, global) in module.info.globals.iter().enumerate() { - let Exportable {entity, import_name, ..} = global; + let ImportableExportable {entity, import_name, ..} = global; let value: i64 = match entity.initializer { GlobalInit::I32Const(n) => n as _, GlobalInit::I64Const(n) => n, diff --git a/src/webassembly/module.rs b/src/webassembly/module.rs index 9323ee4dc..bd31b060b 100644 --- a/src/webassembly/module.rs +++ b/src/webassembly/module.rs @@ -71,9 +71,9 @@ fn get_func_name(func_index: FuncIndex) -> ir::ExternalName { ir::ExternalName::user(0, func_index.index() as u32) } -/// A collection of names under which a given entity is exported. +/// A collection of names under which a given entity is imported/exported. #[derive(Debug)] -pub struct Exportable { +pub struct ImportableExportable { /// An entity. pub entity: T, @@ -84,7 +84,7 @@ pub struct Exportable { pub import_name: Option<(String, String)>, } -impl Exportable { +impl ImportableExportable { pub fn new(entity: T, import_name: Option<(String, String)>) -> Self { Self { entity, @@ -124,7 +124,7 @@ pub struct ModuleInfo { pub signatures: Vec, /// Functions, imported and local. - pub functions: PrimaryMap>, + pub functions: PrimaryMap>, /// Function bodies. pub function_bodies: PrimaryMap, @@ -133,7 +133,7 @@ pub struct ModuleInfo { pub imported_funcs: Vec<(String, String)>, /// Tables as provided by `declare_table`. - pub tables: Vec>, + pub tables: Vec>, /// WebAssembly table initializers. pub table_elements: Vec, @@ -142,13 +142,13 @@ pub struct ModuleInfo { pub tables_base: Option, /// Memories as provided by `declare_memory`. - pub memories: Vec>, + pub memories: Vec>, /// The Cranelift global holding the base address of the globals vector. pub globals_base: Option, /// Globals as provided by `declare_global`. - pub globals: Vec>, + pub globals: Vec>, /// The start function. pub start_func: Option, @@ -158,7 +158,7 @@ pub struct ModuleInfo { /// Exported entities /// We use this in order to have a O(1) allocation of the exports - /// rather than iterating through the Exportable elements. + /// rather than iterating through the ImportableExportable elements. pub exports: HashMap, /// The external function declaration for implementing wasm's `current_memory`. @@ -712,7 +712,7 @@ impl<'data> ModuleEnvironment<'data> for Module { self.info.imported_funcs.len(), "Imported functions must be declared first" ); - self.info.functions.push(Exportable::new(sig_index, None)); + self.info.functions.push(ImportableExportable::new(sig_index, None)); self.info .imported_funcs .push((String::from(module), String::from(field))); @@ -723,7 +723,7 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_func_type(&mut self, sig_index: SignatureIndex) { - self.info.functions.push(Exportable::new(sig_index, None)); + self.info.functions.push(ImportableExportable::new(sig_index, None)); } fn get_func_type(&self, func_index: FuncIndex) -> SignatureIndex { @@ -731,7 +731,7 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_global(&mut self, global: Global) { - self.info.globals.push(Exportable::new(global, None)); + self.info.globals.push(ImportableExportable::new(global, None)); } fn declare_global_import( @@ -740,7 +740,7 @@ impl<'data> ModuleEnvironment<'data> for Module { module: &'data str, field: &'data str, ) { - self.info.globals.push(Exportable::new(global, Some((String::from(module), String::from(field))))); + self.info.globals.push(ImportableExportable::new(global, Some((String::from(module), String::from(field))))); } fn get_global(&self, global_index: GlobalIndex) -> &Global { @@ -748,7 +748,7 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_table(&mut self, table: Table) { - self.info.tables.push(Exportable::new(table, None)); + self.info.tables.push(ImportableExportable::new(table, None)); } fn declare_table_import( @@ -757,7 +757,7 @@ impl<'data> ModuleEnvironment<'data> for Module { module: &'data str, field: &'data str, ) { - self.info.tables.push(Exportable::new(table, Some((String::from(module), String::from(field))))); + self.info.tables.push(ImportableExportable::new(table, Some((String::from(module), String::from(field))))); } fn declare_table_elements( @@ -776,7 +776,7 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_memory(&mut self, memory: Memory) { - self.info.memories.push(Exportable::new(memory, None)); + self.info.memories.push(ImportableExportable::new(memory, None)); } fn declare_memory_import( @@ -785,7 +785,7 @@ impl<'data> ModuleEnvironment<'data> for Module { module: &'data str, field: &'data str, ) { - self.info.memories.push(Exportable::new(memory, Some((String::from(module), String::from(field))))); + self.info.memories.push(ImportableExportable::new(memory, Some((String::from(module), String::from(field))))); } fn declare_data_initialization( From a7e1775255d43100a95590e28ca07cf1104d8228 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 18 Nov 2018 21:05:26 -0800 Subject: [PATCH 03/11] Added mocking back into instance --- src/webassembly/instance.rs | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index 3901988aa..243037f4b 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -121,9 +121,9 @@ pub struct InstanceOptions { pub isa: Box, } -// extern fn mock_fn() -> i32 { -// return 0; -// } +extern fn mock_fn() -> i32 { + return 0; +} impl Instance { pub const TABLES_OFFSET: usize = 0; // 0 on 64-bit | 0 on 32-bit @@ -165,19 +165,19 @@ impl Instance { for (module, field) in module.info.imported_funcs.iter() { let imported = import_object .get(&module.as_str(), &field.as_str()); - let function = match imported { + let function: &*const u8 = match imported { Some(ImportValue::Func(f)) => f, None => { - // if options.mock_missing_imports { - // debug!("The import {}.{} is not provided, therefore will be mocked.", module, field); - // mock_fn as *const u8 - // } - // else { - return Err(ErrorKind::LinkError(format!( - "Imported function {}.{} was not provided in the import_functions", - module, field - ))); - // } + if options.mock_missing_imports { + debug!("The import {}.{} is not provided, therefore will be mocked.", module, field); + &(mock_fn as *const u8) + } + else { + return Err(ErrorKind::LinkError(format!( + "Imported function {}.{} was not provided in the import_functions", + module, field + ))); + } }, other => panic!("Expected function import, received {:?}", other) }; From 9680d586c379c505dbf29d8a8309c82823c5ae2b Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 18 Nov 2018 22:12:22 -0800 Subject: [PATCH 04/11] Use iterator map for compilation --- src/webassembly/instance.rs | 66 ++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 30 deletions(-) diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index 243037f4b..b44bd140c 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -6,7 +6,7 @@ //! synchronously instantiate a given webassembly::Module object. However, the //! primary way to get an Instance is through the asynchronous //! webassembly::instantiate_streaming() function. -use cranelift_codegen::ir::LibCall; +use cranelift_codegen::ir::{LibCall, Function}; use cranelift_codegen::{binemit, Context}; use cranelift_entity::EntityRef; use cranelift_wasm::{FuncIndex, GlobalInit}; @@ -125,6 +125,33 @@ extern fn mock_fn() -> i32 { return 0; } +struct CompiledFunction { + code_buf: Vec, + reloc_sink: RelocSink, + trap_sink: binemit::NullTrapSink, +} + +fn compile_function(isa: &TargetIsa, function_body: &Function) -> Result { + let mut func_context = Context::for_function(function_body.to_owned()); + + let mut code_buf: Vec = Vec::new(); + let mut reloc_sink = RelocSink::new(); + let mut trap_sink = binemit::NullTrapSink {}; + + func_context + .compile_and_emit(isa, &mut code_buf, &mut reloc_sink, &mut trap_sink) + .map_err(|e| { + debug!("CompileError: {}", e.to_string()); + ErrorKind::CompileError(e.to_string()) + })?; + + Ok(CompiledFunction { + code_buf, + reloc_sink, + trap_sink + }) +} + impl Instance { pub const TABLES_OFFSET: usize = 0; // 0 on 64-bit | 0 on 32-bit pub const MEMORIES_OFFSET: usize = size_of::(); // 8 on 64-bit | 4 on 32-bit @@ -188,32 +215,10 @@ impl Instance { debug!("Instance - Compiling functions"); // Compile the functions (from cranelift IR to machine code) - for function_body in module.info.function_bodies.values() { - let mut func_context = Context::for_function(function_body.to_owned()); - // func_context - // .verify(&*isa) - // .map_err(|e| ErrorKind::CompileError(e.to_string()))?; - // func_context - // .verify_locations(&*isa) - // .map_err(|e| ErrorKind::CompileError(e.to_string()))?; - // let code_size_offset = func_context - // .compile(&*isa) - // .map_err(|e| ErrorKind::CompileError(e.to_string()))?; - // as usize; - - let mut code_buf: Vec = Vec::new(); - let mut reloc_sink = RelocSink::new(); - let mut trap_sink = binemit::NullTrapSink {}; - // This will compile a cranelift ir::Func into a code buffer (stored in memory) - // and will push any inner function calls to the reloc sync. - // In case traps need to be triggered, they will go to trap_sink - func_context - .compile_and_emit(&*options.isa, &mut code_buf, &mut reloc_sink, &mut trap_sink) - .map_err(|e| { - debug!("CompileError: {}", e.to_string()); - ErrorKind::CompileError(e.to_string()) - })?; - // We set this code_buf to be readable & executable + module.info.function_bodies.values().map(|function_body| -> CompiledFunction { + compile_function(&*options.isa, function_body).unwrap() + }).for_each(|compiled_func| -> () { + let CompiledFunction {code_buf, reloc_sink, ..} = compiled_func; protect_codebuf(&code_buf).unwrap(); let func_offset = code_buf; @@ -221,9 +226,10 @@ impl Instance { // context_and_offsets.push(func_context); relocations.push(reloc_sink.func_relocs); - // println!("FUNCTION RELOCATIONS {:?}", reloc_sink.func_relocs) - // total_size += code_size_offset; - } + () + }); + + // compiled_funcs?; debug!("Instance - Relocating functions"); // For each of the functions used, we see what are the calls inside this functions From f2d2c9b9f8d25bd9a57bf55b6b86416d1c44ddbc Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 18 Nov 2018 23:51:56 -0800 Subject: [PATCH 05/11] Use rayon for easy parallel compilation --- src/main.rs | 1 + src/webassembly/instance.rs | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index bb181aecf..c9d915fad 100644 --- a/src/main.rs +++ b/src/main.rs @@ -13,6 +13,7 @@ extern crate wasmparser; #[macro_use] extern crate target_lexicon; extern crate nix; +extern crate rayon; use std::fs::File; use std::io; diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index b44bd140c..dbd047c89 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -8,14 +8,17 @@ //! webassembly::instantiate_streaming() function. use cranelift_codegen::ir::{LibCall, Function}; use cranelift_codegen::{binemit, Context}; +use cranelift_codegen::isa::TargetIsa; use cranelift_entity::EntityRef; use cranelift_wasm::{FuncIndex, GlobalInit}; -use cranelift_codegen::isa::TargetIsa; +use rayon::prelude::*; + use region; use std::iter::Iterator; use std::ptr::write_unaligned; use std::slice; use std::sync::Arc; +use std::iter::FromIterator; use std::mem::size_of; use super::super::common::slice::{BoundedSlice, UncheckedSlice}; @@ -215,20 +218,26 @@ impl Instance { debug!("Instance - Compiling functions"); // Compile the functions (from cranelift IR to machine code) - module.info.function_bodies.values().map(|function_body| -> CompiledFunction { + let values: Vec<&Function> = Vec::from_iter(module.info.function_bodies.values()); + // let isa: &TargetIsa = &*options.isa; + let compiled_funcs: Vec = values.par_iter().map(|function_body| -> CompiledFunction { + // let r = *Arc::from_raw(isa_ptr); compile_function(&*options.isa, function_body).unwrap() - }).for_each(|compiled_func| -> () { - let CompiledFunction {code_buf, reloc_sink, ..} = compiled_func; - protect_codebuf(&code_buf).unwrap(); + // unimplemented!() + }).collect(); - let func_offset = code_buf; - functions.push(func_offset); + for compiled_func in compiled_funcs.into_iter() { + let CompiledFunction {code_buf, reloc_sink, ..} = compiled_func; + + + // let func_offset = code_buf; + protect_codebuf(&code_buf).unwrap(); + functions.push(code_buf); // context_and_offsets.push(func_context); relocations.push(reloc_sink.func_relocs); - () - }); - + } + // compiled_funcs?; debug!("Instance - Relocating functions"); From 12dc70d4976c8dd4e37668e2c4659bce0d28a225 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 19 Nov 2018 10:27:55 -0800 Subject: [PATCH 06/11] Added support for global references --- spectests/globals.wast | 19 ++++-- src/spectests/globals.rs | 116 +++++++++++++++++++++++++++--------- src/webassembly/instance.rs | 4 +- 3 files changed, 106 insertions(+), 33 deletions(-) diff --git a/spectests/globals.wast b/spectests/globals.wast index f9ea90e80..1fbe72217 100644 --- a/spectests/globals.wast +++ b/spectests/globals.wast @@ -287,6 +287,12 @@ "type mismatch" ) +(assert_invalid + (module (global i32 (i32.const 0)) (global i64 (get_global 1))) + "unknown global" +) + + (assert_invalid (module (global i32 (;empty instruction sequence;))) "type mismatch" @@ -302,10 +308,15 @@ "unknown global" ) -;; SKIP_MUTABLE_GLOBALS -;; (module -;; (import "spectest" "global_i32" (global i32)) -;; ) +(module + (import "spectest" "global_i32" (global i32)) + (global i32 (get_global 0)) + (func (export "get-0") (result i32) (get_global 0)) + (func (export "get-0-ref") (result i32) (get_global 1)) +) + +(assert_return (invoke "get-0") (i32.const 666)) +(assert_return (invoke "get-0-ref") (i32.const 666)) (assert_malformed (module binary diff --git a/src/spectests/globals.rs b/src/spectests/globals.rs index 53a35ded6..31cbf47d9 100644 --- a/src/spectests/globals.rs +++ b/src/spectests/globals.rs @@ -907,44 +907,36 @@ fn c54_l286_assert_invalid() { // Line 291 #[test] fn c55_l291_assert_invalid() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 6, 11, 2, 127, 0, 65, 0, 11, 126, 0, 35, 1, 11]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is invalid"); +} + +// Line 297 +#[test] +fn c56_l297_assert_invalid() { let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 6, 4, 1, 127, 0, 11]; let compilation = compile(wasm_binary.to_vec()); assert!(compilation.is_err(), "WASM should not compile as is invalid"); } -// Line 296 +// Line 302 #[test] -fn c56_l296_assert_invalid() { +fn c57_l302_assert_invalid() { let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 6, 6, 1, 127, 0, 35, 0, 11]; let compilation = compile(wasm_binary.to_vec()); assert!(compilation.is_err(), "WASM should not compile as is invalid"); } -// Line 301 +// Line 307 #[test] -fn c57_l301_assert_invalid() { +fn c58_l307_assert_invalid() { let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 6, 11, 2, 127, 0, 35, 1, 11, 127, 0, 65, 0, 11]; let compilation = compile(wasm_binary.to_vec()); assert!(compilation.is_err(), "WASM should not compile as is invalid"); } // Line 311 -#[test] -fn c58_l311_assert_malformed() { - let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 2, 148, 128, 128, 128, 0, 1, 8, 115, 112, 101, 99, 116, 101, 115, 116, 10, 103, 108, 111, 98, 97, 108, 95, 105, 51, 50, 3, 127, 2]; - let compilation = compile(wasm_binary.to_vec()); - assert!(compilation.is_err(), "WASM should not compile as is malformed"); -} - -// Line 324 -#[test] -fn c59_l324_assert_malformed() { - let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 2, 148, 128, 128, 128, 0, 1, 8, 115, 112, 101, 99, 116, 101, 115, 116, 10, 103, 108, 111, 98, 97, 108, 95, 105, 51, 50, 3, 127, 255]; - let compilation = compile(wasm_binary.to_vec()); - assert!(compilation.is_err(), "WASM should not compile as is malformed"); -} - -// Line 337 #[test] fn test_module_1() { @@ -999,7 +991,15 @@ fn test_module_1() { } fn create_module_2() -> ResultObject { let module_str = "(module - (global (;0;) i32 (i32.const 0))) + (type (;0;) (func (result i32))) + (import \"spectest\" \"global_i32\" (global (;0;) i32)) + (func (;0;) (type 0) (result i32) + get_global 0) + (func (;1;) (type 0) (result i32) + get_global 1) + (global (;1;) i32 (get_global 0)) + (export \"get-0\" (func 0)) + (export \"get-0-ref\" (func 1))) "; let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") @@ -1009,25 +1009,87 @@ fn start_module_2(result_object: &ResultObject) { result_object.instance.start(); } -// Line 341 +// Line 318 +fn c60_l318_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c60_l318_action_invoke"); + let func_index = match result_object.module.info.exports.get("get-0") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 666 as i32); +} + +// Line 319 +fn c61_l319_action_invoke(result_object: &ResultObject) { + println!("Executing function {}", "c61_l319_action_invoke"); + let func_index = match result_object.module.info.exports.get("get-0-ref") { + Some(&Export::Function(index)) => index, + _ => panic!("Function not found"), + }; + let invoke_fn: fn(&Instance) -> i32 = get_instance_function!(result_object.instance, func_index); + let result = invoke_fn(&result_object.instance); + assert_eq!(result, 666 as i32); +} + +// Line 322 #[test] -fn c61_l341_assert_malformed() { - let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 6, 134, 128, 128, 128, 0, 1, 127, 2, 65, 0, 11]; +fn c62_l322_assert_malformed() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 2, 148, 128, 128, 128, 0, 1, 8, 115, 112, 101, 99, 116, 101, 115, 116, 10, 103, 108, 111, 98, 97, 108, 95, 105, 51, 50, 3, 127, 2]; let compilation = compile(wasm_binary.to_vec()); assert!(compilation.is_err(), "WASM should not compile as is malformed"); } -// Line 353 +// Line 335 #[test] -fn c62_l353_assert_malformed() { - let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 6, 134, 128, 128, 128, 0, 1, 127, 255, 65, 0, 11]; +fn c63_l335_assert_malformed() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 2, 148, 128, 128, 128, 0, 1, 8, 115, 112, 101, 99, 116, 101, 115, 116, 10, 103, 108, 111, 98, 97, 108, 95, 105, 51, 50, 3, 127, 255]; let compilation = compile(wasm_binary.to_vec()); assert!(compilation.is_err(), "WASM should not compile as is malformed"); } +// Line 348 + #[test] fn test_module_2() { let result_object = create_module_2(); // We group the calls together start_module_2(&result_object); + c60_l318_action_invoke(&result_object); + c61_l319_action_invoke(&result_object); +} +fn create_module_3() -> ResultObject { + let module_str = "(module + (global (;0;) i32 (i32.const 0))) + "; + let wasm_binary = wat2wasm(module_str.as_bytes()).expect("WAST not valid or malformed"); + instantiate(wasm_binary, spectest_importobject()).expect("WASM can't be instantiated") +} + +fn start_module_3(result_object: &ResultObject) { + result_object.instance.start(); +} + +// Line 352 +#[test] +fn c65_l352_assert_malformed() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 6, 134, 128, 128, 128, 0, 1, 127, 2, 65, 0, 11]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is malformed"); +} + +// Line 364 +#[test] +fn c66_l364_assert_malformed() { + let wasm_binary = [0, 97, 115, 109, 1, 0, 0, 0, 6, 134, 128, 128, 128, 0, 1, 127, 255, 65, 0, 11]; + let compilation = compile(wasm_binary.to_vec()); + assert!(compilation.is_err(), "WASM should not compile as is malformed"); +} + +#[test] +fn test_module_3() { + let result_object = create_module_3(); + // We group the calls together + start_module_3(&result_object); } diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index 884d7a71d..5588e29c9 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -311,8 +311,8 @@ impl Instance { GlobalInit::I64Const(n) => n, GlobalInit::F32Const(f) => f as _, // unsafe { mem::transmute(f as f64) }, GlobalInit::F64Const(f) => f as _, // unsafe { mem::transmute(f) }, - GlobalInit::GlobalRef(_global_index) => { - unimplemented!("GlobalInit::GlobalRef is not yet supported") + GlobalInit::GlobalRef(global_index) => { + globals_data[global_index.index()] } GlobalInit::Import() => { let (module_name, field_name) = import_name.as_ref().expect("Expected a import name for the global import"); From 3b878620ccb6a7e1e1582bb9037fe7db6c7c8107 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 19 Nov 2018 13:09:16 -0800 Subject: [PATCH 07/11] Added support for mocking globals and tables by default --- src/webassembly/instance.rs | 29 +++++++++++++++++++++++++++-- src/webassembly/mod.rs | 2 ++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index 5588e29c9..554985ffe 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -117,6 +117,8 @@ pub struct DataPointers { pub struct InstanceOptions { // Shall we mock automatically the imported functions if they don't exist? pub mock_missing_imports: bool, + pub mock_missing_globals: bool, + pub mock_missing_tables: bool, pub isa: Box, } @@ -321,7 +323,17 @@ impl Instance { Some(ImportValue::Global(value)) => { *value }, - _ => panic!("Imported global value was not provided {:?} ({}.{})", imported, module_name, field_name) + None => { + if options.mock_missing_globals { + 0 + } + else { + panic!("Imported global value was not provided ({}.{})", module_name, field_name) + } + }, + _ => { + panic!("Expected global import, but received {:?} ({}.{})", imported, module_name, field_name) + } } } }; @@ -345,7 +357,20 @@ impl Instance { Some(ImportValue::Table(t)) => { t.to_vec() }, - _ => panic!("Imported table was not provided {:?} ({}.{})", imported, module_name, field_name) + None => { + if options.mock_missing_tables { + let len = table.entity.size; + let mut v = Vec::with_capacity(len); + v.resize(len, 0); + v + } + else { + panic!("Imported table value was not provided ({}.{})", module_name, field_name) + } + }, + _ => { + panic!("Expected global table, but received {:?} ({}.{})", imported, module_name, field_name) + } } }, None => { diff --git a/src/webassembly/mod.rs b/src/webassembly/mod.rs index 9e2a2ed01..f60d67861 100644 --- a/src/webassembly/mod.rs +++ b/src/webassembly/mod.rs @@ -58,6 +58,8 @@ pub fn instantiate( import_object, InstanceOptions { mock_missing_imports: true, + mock_missing_globals: true, + mock_missing_tables: true, isa: isa }, )?; From 3fa01be0bb4e42bbab20fe0191d84ee0633c86e9 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 19 Nov 2018 13:21:11 -0800 Subject: [PATCH 08/11] Remove offsets print --- src/main.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main.rs b/src/main.rs index bb181aecf..fd75ee802 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,11 +76,11 @@ fn execute_wasm(wasm_path: PathBuf) -> Result<(), String> { webassembly::instantiate(wasm_binary, import_object) .map_err(|err| format!("Can't instantiate the WebAssembly module: {}", err))?; - webassembly::utils::print_instance_offsets(&instance); + // webassembly::utils::print_instance_offsets(&instance); let func_index = instance .start_func - .unwrap_or_else(|| match module.info.exports.get("main") { + .unwrap_or_else(|| match module.info.exports.get("main").or(module.info.exports.get("_main")) { Some(&webassembly::Export::Function(index)) => index, _ => panic!("Main function not found"), }); From 3070667edd546aea3206868f530d73082f01c2d9 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Mon, 19 Nov 2018 13:21:35 -0800 Subject: [PATCH 09/11] Remove offsets print --- src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index bb181aecf..6bd1e3919 100644 --- a/src/main.rs +++ b/src/main.rs @@ -76,7 +76,7 @@ fn execute_wasm(wasm_path: PathBuf) -> Result<(), String> { webassembly::instantiate(wasm_binary, import_object) .map_err(|err| format!("Can't instantiate the WebAssembly module: {}", err))?; - webassembly::utils::print_instance_offsets(&instance); + // webassembly::utils::print_instance_offsets(&instance); let func_index = instance .start_func From c141f8b64c9a3d0f657d7ee9064073fd469f7b6a Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 20 Nov 2018 16:02:33 -0800 Subject: [PATCH 10/11] Use local cranelift --- .circleci/config.yml | 6 +++++ .gitmodules | 3 +++ Cargo.lock | 55 ++++++++++++++++---------------------------- Cargo.toml | 18 ++++++++------- README.md | 2 +- cranelift | 1 + 6 files changed, 41 insertions(+), 44 deletions(-) create mode 100644 .gitmodules create mode 160000 cranelift diff --git a/.circleci/config.yml b/.circleci/config.yml index 01a7ff499..d617670be 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -7,6 +7,12 @@ jobs: steps: - checkout + - run: + name: Pull submodules + command: | + # git pull --recurse-submodules + git submodule sync --recursive + git submodule update --recursive --init - restore_cache: keys: - v4-test-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }} diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..56796d767 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "cranelift"] + path = cranelift + url = git@github.com:WAFoundation/cranelift.git diff --git a/Cargo.lock b/Cargo.lock index 8e6da6342..d38e55216 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -85,19 +85,17 @@ dependencies = [ [[package]] name = "cranelift-bforest" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-entity 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-entity 0.23.0", ] [[package]] name = "cranelift-codegen" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-bforest 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-codegen-meta 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-entity 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-bforest 0.23.0", + "cranelift-codegen-meta 0.23.0", + "cranelift-entity 0.23.0", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -107,22 +105,19 @@ dependencies = [ [[package]] name = "cranelift-codegen-meta" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-entity 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-entity 0.23.0", ] [[package]] name = "cranelift-entity" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cranelift-frontend" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-codegen 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-codegen 0.23.0", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -130,9 +125,8 @@ dependencies = [ [[package]] name = "cranelift-native" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-codegen 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-codegen 0.23.0", "raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -140,11 +134,10 @@ dependencies = [ [[package]] name = "cranelift-wasm" version = "0.23.0" -source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-codegen 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-entity 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-frontend 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-codegen 0.23.0", + "cranelift-entity 0.23.0", + "cranelift-frontend 0.23.0", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -156,7 +149,7 @@ name = "docopt" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", @@ -236,11 +229,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "lazy_static" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "libc" @@ -532,7 +522,7 @@ name = "thread_local" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -594,12 +584,14 @@ dependencies = [ name = "wasmer" version = "0.1.0" dependencies = [ - "cranelift-codegen 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-entity 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-native 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-wasm 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-codegen 0.23.0", + "cranelift-entity 0.23.0", + "cranelift-native 0.23.0", + "cranelift-wasm 0.23.0", "docopt 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (git+https://github.com/rust-lang/libc)", "log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -654,13 +646,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum cfg-if 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0c4e7bb64a8ebb0d856483e1e682ea3422f883c5f5615a90d51a2c82fe87fdd3" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec65ee4f9c9d16f335091d23693457ed4928657ba4982289d7fafee03bc614a" -"checksum cranelift-bforest 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8c5f8e1ab4f73b59a98531a8013d8ed3ca7edb4e36984cb301d9c06f6892787b" -"checksum cranelift-codegen 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4437ec8212686e6cdacfea75aaedb4ab8b013869be1e8693a4cb97a60f135035" -"checksum cranelift-codegen-meta 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4eac16097b96e9f609df735555f2d1658531750fbc3805bca1daca7671aef9eb" -"checksum cranelift-entity 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9be3f82369346201c2e0cff720522e6eb55459e51c916b2199f25cff2058ca96" -"checksum cranelift-frontend 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d5d18ab2bc89a09b4275442a9559dc0f947b9a8ad9ae9ee89452a057df54ced" -"checksum cranelift-native 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d8d3b5951eefd89778dc59b0e33b556573a870538bc21982019bd4c4003b0a2d" -"checksum cranelift-wasm 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e5906a111814d43d84002ef974eb0c023804fd4d1866b34f43c1bb588a759ad8" "checksum docopt 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d60c92df70dfaaabecc14b409fd79f55ba0f247780529db1d73bfa601e1d3ac0" "checksum errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "c2a071601ed01b988f896ab14b95e67335d1eeb50190932a1320f7fe3cadc84e" "checksum errno-dragonfly 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "14ca354e36190500e1e1fb267c647932382b54053c50b14970856c0b00a35067" @@ -671,7 +656,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum lazy_static 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ca488b89a5657b0a2ecd45b95609b3e848cf1755da332a0da46e2b2b1cb371a7" +"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" "checksum libc 0.2.43 (git+https://github.com/rust-lang/libc)" = "" "checksum libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)" = "76e3a3ef172f1a0b9a9ff0dd1491ae5e6c948b94479a3021819ba7d860c8645d" "checksum log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4fcce5fa49cc693c312001daf1d13411c4a5283796bac1084299ea3e567113f" diff --git a/Cargo.toml b/Cargo.toml index 3c795b0aa..e34c02a7e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,14 +20,14 @@ include = [ ] [dependencies] -cranelift-native = "0.23.0" -# cranelift-native = { path = "cranelift/lib/native" } -cranelift-codegen = "0.23.0" -# cranelift-codegen = { path = "cranelift/lib/codegen" } -cranelift-entity = "0.23.0" -# cranelift-entity = { path = "cranelift/lib/entity" } -cranelift-wasm = "0.23.0" -# cranelift-wasm = { path = "cranelift/lib/wasm" } +# cranelift-native = "0.23.0" +cranelift-native = { path = "cranelift/lib/native" } +# cranelift-codegen = "0.23.0" +cranelift-codegen = { path = "cranelift/lib/codegen" } +# cranelift-entity = "0.23.0" +cranelift-entity = { path = "cranelift/lib/entity" } +# cranelift-wasm = "0.23.0" +cranelift-wasm = { path = "cranelift/lib/wasm" } docopt = "1.0.0" serde = "1.0.55" serde_derive = "1.0.55" @@ -44,6 +44,8 @@ target-lexicon = "0.2.0" # libc = "0.2" libc = { git = "https://github.com/rust-lang/libc" } nix = "0.11" +backtrace = "0.3.9" +lazy_static = "1.2.0" [build-dependencies] wabt = "0.7.1" diff --git a/README.md b/README.md index b80140ad7..237efd94c 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ To build this project you will need Rust and Cargo. ```sh # checkout code and associated submodules -git clone https://github.com/wafoundation/wasmer.git +git clone --recursive https://github.com/wafoundation/wasmer.git cd wasmer # install tools diff --git a/cranelift b/cranelift new file mode 160000 index 000000000..cb62a1ead --- /dev/null +++ b/cranelift @@ -0,0 +1 @@ +Subproject commit cb62a1ead2c5346ccb0f1224ecae5939ac064f87 From b75a9c3acd56d418c1f0dbfcd59c5a9c528d2965 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Tue, 20 Nov 2018 16:33:47 -0800 Subject: [PATCH 11/11] Fix build release pulling the submodules --- .circleci/config.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index d617670be..f6b1af785 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -32,6 +32,12 @@ jobs: steps: - checkout + - run: + name: Pull submodules + command: | + # git pull --recurse-submodules + git submodule sync --recursive + git submodule update --recursive --init - restore_cache: keys: - v4-cargo-cache-linux-{{ arch }}-{{ checksum "Cargo.lock" }} @@ -65,6 +71,12 @@ jobs: steps: - checkout + - run: + name: Pull submodules + command: | + # git pull --recurse-submodules + git submodule sync --recursive + git submodule update --recursive --init - restore_cache: keys: - v4-cargo-cache-darwin-{{ arch }}-{{ checksum "Cargo.lock" }}