From adf6d298b67d85832dcb60edb0bf48fe27bfa6e1 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Wed, 14 Nov 2018 23:10:35 -0800 Subject: [PATCH 1/3] Trying to upgrade Cranelift to 0.23 --- Cargo.lock | 129 ++++++++++++------------- Cargo.toml | 10 +- src/webassembly/instance.rs | 14 ++- src/webassembly/mod.rs | 11 ++- src/webassembly/module.rs | 187 +++++++++++++++++++++--------------- 5 files changed, 189 insertions(+), 162 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 0b0d6a774d8..cbce41116f4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -84,67 +84,71 @@ dependencies = [ [[package]] name = "cranelift-bforest" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-entity 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-entity 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cranelift-codegen" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-bforest 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-codegen-meta 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-entity 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", + "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)", - "target-lexicon 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cranelift-codegen-meta" -version = "0.22.0" +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)", +] [[package]] name = "cranelift-entity" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cranelift-frontend" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-codegen 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-codegen 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", ] [[package]] name = "cranelift-native" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-codegen 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "raw-cpuid 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "target-lexicon 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "cranelift-codegen 0.23.0 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", ] [[package]] name = "cranelift-wasm" -version = "0.22.0" +version = "0.23.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cranelift-codegen 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-entity 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-frontend 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", + "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)", - "target-lexicon 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmparser 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmparser 0.21.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -188,22 +192,22 @@ dependencies = [ [[package]] name = "failure" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "failure_derive" -version = "0.1.2" +version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -318,7 +322,7 @@ dependencies = [ [[package]] name = "raw-cpuid" -version = "5.0.0" +version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -366,7 +370,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", "errno 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", "mach 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -465,16 +469,6 @@ dependencies = [ "syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "syn" -version = "0.14.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "syn" version = "0.15.9" @@ -487,22 +481,22 @@ dependencies = [ [[package]] name = "synstructure" -version = "0.9.0" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "target-lexicon" -version = "0.0.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", "serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -600,10 +594,10 @@ dependencies = [ name = "wasmer" version = "0.1.0" dependencies = [ - "cranelift-codegen 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-entity 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-native 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", - "cranelift-wasm 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)", + "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)", "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)", "libc 0.2.43 (registry+https://github.com/rust-lang/crates.io-index)", @@ -615,7 +609,7 @@ dependencies = [ "serde_derive 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "target-lexicon 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "wasmparser 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -623,12 +617,12 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.17.3" +version = "0.20.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasmparser" -version = "0.20.0" +version = "0.21.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -661,19 +655,19 @@ 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.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "edd9d4c68e251628d0a224720034280ed3fe1bff90853e6199c7e3c07e7569fc" -"checksum cranelift-codegen 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6b56502b1ad2a1dc52455687309d80ca7e9a6ceb9b219935a50146dbd850c27b" -"checksum cranelift-codegen-meta 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b7baf504162041c394fe8a31f55e01138298c19cf3808ce9454e1315cb1e2dcd" -"checksum cranelift-entity 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "75c34e9d94525517f1e13957e8402de2b92a1db9ac90def5fec969999e7160ae" -"checksum cranelift-frontend 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "68c77d95a0e374f72d73d39530f2fbf9214854f49ffa21a04229429c814f030c" -"checksum cranelift-native 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "764e004b73b6aaa20ff2a0127094950b67f25552c9b87662b35272f670a6c17f" -"checksum cranelift-wasm 0.22.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97dba85d4788c520458e5d75eecccca39df43747dbcfbd8d45ac0d4e8aba475e" +"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" "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" -"checksum failure 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7efb22686e4a466b1ec1a15c2898f91fa9cb340452496dca654032de20ff95b9" -"checksum failure_derive 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "946d0e98a50d9831f5d589038d2ca7f8f455b1c21028c0db0e84116a12696426" +"checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7" +"checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "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" @@ -688,7 +682,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum proc-macro2 0.4.20 (registry+https://github.com/rust-lang/crates.io-index)" = "3d7b7eaaa90b4a90a932a9ea6666c95a389e424eff347f0f793979289429feee" "checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5" "checksum rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8356f47b32624fef5b3301c1be97e5944ecdd595409cc5da11d05f211db6cfbd" -"checksum raw-cpuid 5.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe3c460bd35fdb75644e94ab498372bdf29a4849367ce7ba74cf358edce590c4" +"checksum raw-cpuid 6.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "30a9d219c32c9132f7be513c18be77c9881c7107d2ab5569d205a6a0f0e6dc7d" "checksum redox_syscall 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "c214e91d3ecf43e9a4e41e578973adeb14b474f2bee858742d127af75a0112b1" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum regex 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "2069749032ea3ec200ca51e4a31df41759190a88edca0d2d86ee8bedf7073341" @@ -707,10 +701,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum structopt 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "ca85f2c9a5a1e2d5ac686fc0be48e40f8ad803f5bbe31f692ff71eb2dd8aad45" "checksum structopt-derive 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "1383e5db585da799a5c4acc496c5c868e18bf82e658c00c75cc91038fa26b55f" -"checksum syn 0.14.9 (registry+https://github.com/rust-lang/crates.io-index)" = "261ae9ecaa397c42b960649561949d69311f08eeaea86a65696e6e46517cf741" "checksum syn 0.15.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b10ee269228fb723234fce98e9aac0eaed2bd5f1ad2f6930e8d5b93f04445a1a" -"checksum synstructure 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "85bb9b7550d063ea184027c9b8c20ac167cd36d3e06b3a40bceb9d746dc1a7b7" -"checksum target-lexicon 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a34226bd63b5a26fc909f5f0d7ef4dc55d5851077035e49437e4e14bf567247f" +"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" +"checksum target-lexicon 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4af5e2227f0b887d591d3724b796a96eff04226104d872f5b3883fcd427d64b9" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" @@ -724,8 +717,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum wabt 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0768faf932f2898c0a7545edee648fefa716906a2e143009addf4959d2335a75" "checksum wabt-sys 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4aaa9a8fa0d698315da5611f3e113a1e688fbb8d6fa0dd9510dfa023f665e9dc" -"checksum wasmparser 0.17.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc6511bad33610d7798f80d48e10495a6eb4f1e39306b0bb340b2de0816c4ca" "checksum wasmparser 0.20.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2a75e0c3fe9a4d4fd91901348a5be05ba4791e29dda89e8596bfe87900ba7edc" +"checksum wasmparser 0.21.10 (registry+https://github.com/rust-lang/crates.io-index)" = "48b8ebfeb364ff50e0ff043f491c270f58a7563aa3dc97402a0e813bfeb6df6f" "checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 4a673b8689b..8d09a7b0d1b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,13 +20,13 @@ include = [ ] [dependencies] -cranelift-native = "0.22.0" +cranelift-native = "0.23.0" # cranelift-native = { path = "cranelift/lib/native" } -cranelift-codegen = "0.22.0" +cranelift-codegen = "0.23.0" # cranelift-codegen = { path = "cranelift/lib/codegen" } -cranelift-entity = "0.22.0" +cranelift-entity = "0.23.0" # cranelift-entity = { path = "cranelift/lib/entity" } -cranelift-wasm = "0.22.0" +cranelift-wasm = "0.23.0" # cranelift-wasm = { path = "cranelift/lib/wasm" } docopt = "1.0.0" serde = "1.0.55" @@ -40,7 +40,7 @@ region = "0.3.0" memmap = "0.6.2" spin = "0.4.10" log = "0.4.5" -target-lexicon = { version = "0.0.3", default-features = false } +target-lexicon = "0.2.0" libc = "0.2" nix = "0.11" diff --git a/src/webassembly/instance.rs b/src/webassembly/instance.rs index c22fec45ff8..801f6381b2a 100644 --- a/src/webassembly/instance.rs +++ b/src/webassembly/instance.rs @@ -7,9 +7,10 @@ //! primary way to get an Instance is through the asynchronous //! webassembly::instantiate_streaming() function. use cranelift_codegen::ir::LibCall; -use cranelift_codegen::{binemit, isa, Context}; +use cranelift_codegen::{binemit, Context}; use cranelift_entity::EntityRef; use cranelift_wasm::{FuncIndex, GlobalInit}; +use cranelift_codegen::isa::TargetIsa; use region; use std::iter::Iterator; use std::ptr::write_unaligned; @@ -125,10 +126,10 @@ pub struct DataPointers { pub globals: UncheckedSlice, } -#[derive(Debug, Clone)] pub struct InstanceOptions { // Shall we mock automatically the imported functions if they don't exist? pub mock_missing_imports: bool, + pub isa: Box, } extern fn mock_fn() -> i32 { @@ -153,9 +154,6 @@ impl Instance { // Instantiate functions { functions.reserve_exact(module.info.functions.len()); - let isa = isa::lookup(module.info.triple.clone()) - .unwrap() - .finish(module.info.flags.clone()); let mut relocations = Vec::new(); // let imported_functions: Vec = module.info.imported_funcs.iter().map(|(module, field)| { @@ -210,7 +208,7 @@ impl Instance { // 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(&*isa, &mut code_buf, &mut reloc_sink, &mut trap_sink) + .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()) @@ -352,7 +350,7 @@ impl Instance { ); let base = 0; - let table = &mut tables[table_element.table_index]; + let table = &mut tables[table_element.table_index.index()]; for (i, func_index) in table_element.elements.iter().enumerate() { // since the table just contains functions in the MVP // we get the address of the specified function indexes @@ -388,7 +386,7 @@ impl Instance { for init in &module.info.data_initializers { debug_assert!(init.base.is_none(), "globalvar base not supported yet"); let offset = init.offset; - let mem_mut = memories[init.memory_index].as_mut(); + let mem_mut = memories[init.memory_index.index()].as_mut(); let to_init = &mut mem_mut[offset..offset + init.data.len()]; to_init.copy_from_slice(&init.data); } diff --git a/src/webassembly/mod.rs b/src/webassembly/mod.rs index 1508f751663..21f3cd3ebdc 100644 --- a/src/webassembly/mod.rs +++ b/src/webassembly/mod.rs @@ -10,6 +10,8 @@ use std::panic; use std::str::FromStr; use target_lexicon; use wasmparser; +use cranelift_codegen::{isa, settings}; +use cranelift_codegen::isa::TargetIsa; pub use self::errors::{Error, ErrorKind}; pub use self::import_object::ImportObject; @@ -44,9 +46,12 @@ pub fn instantiate( buffer_source: Vec, import_object: ImportObject<&str, &str>, ) -> Result { + let flags = settings::Flags::new(settings::builder()); + let isa = isa::lookup(triple!("x86_64")).unwrap().finish(flags); + let module = compile(buffer_source)?; debug!("webassembly - creating instance"); - let instance = Instance::new(&module, &import_object, InstanceOptions { mock_missing_imports: true })?; + let instance = Instance::new(&module, &import_object, InstanceOptions { mock_missing_imports: true, isa: isa })?; debug!("webassembly - instance created"); Ok(ResultObject { module, instance }) } @@ -78,9 +83,11 @@ pub fn compile(buffer_source: Vec) -> Result { if !valid { return Err(ErrorKind::CompileError("Module not valid".to_string())); } + let flags = settings::Flags::new(settings::builder()); + let isa = isa::lookup(triple!("x86_64")).unwrap().finish(flags); debug!("webassembly - creating module"); - let module = Module::from_bytes(buffer_source, triple!("x86_64"), None)?; + let module = Module::from_bytes(buffer_source, isa.frontend_config())?; debug!("webassembly - module created"); Ok(module) diff --git a/src/webassembly/module.rs b/src/webassembly/module.rs index b74c9dbc61b..7aa8b1dcdd3 100644 --- a/src/webassembly/module.rs +++ b/src/webassembly/module.rs @@ -4,7 +4,6 @@ use std::collections::HashMap; use std::string::String; use std::vec::Vec; -use target_lexicon::{PointerWidth, Triple}; use cranelift_codegen::cursor::FuncCursor; use cranelift_codegen::ir::immediates::{Imm64, Offset32}; @@ -12,13 +11,12 @@ use cranelift_codegen::ir::types::*; use cranelift_codegen::ir::{ self, AbiParam, ArgumentPurpose, ExtFuncData, ExternalName, FuncRef, InstBuilder, Signature, }; -use cranelift_codegen::print_errors::pretty_verifier_error; -use cranelift_codegen::settings::CallConv; -use cranelift_codegen::{isa, settings, verifier}; +use cranelift_codegen::isa::{CallConv, TargetFrontendConfig}; use cranelift_entity::{EntityRef, PrimaryMap}; use cranelift_wasm::{ - translate_module, // ReturnMode, + translate_module, + ReturnMode, DefinedFuncIndex, FuncEnvironment as FuncEnvironmentTrait, FuncIndex, @@ -78,11 +76,8 @@ pub enum Export { /// `Module` to allow it to be borrowed separately from the /// `FuncTranslator` field. pub struct ModuleInfo { - /// Target description. - pub triple: Triple, - - /// Compilation setting flags. - pub flags: settings::Flags, + /// Target description relevant to frontends producing Cranelift IR. + config: TargetFrontendConfig, pub main_memory_base: Option, @@ -138,10 +133,9 @@ pub struct ModuleInfo { impl ModuleInfo { /// Allocates the data structures with the given flags. - pub fn with_triple_flags(triple: Triple, flags: settings::Flags) -> Self { + pub fn new(config: TargetFrontendConfig) -> Self { Self { - triple, - flags, + config, signatures: Vec::new(), imported_funcs: Vec::new(), functions: PrimaryMap::new(), @@ -214,17 +208,42 @@ pub struct Module { // return_mode: ReturnMode, } + fn native_pointer_type() -> ir::Type { + if cfg!(target_pointer_width = "64") { + ir::types::I64 + } else { + ir::types::I32 + } + } + + /// Number of bytes in a native pointer. + pub fn native_pointer_size() -> i32 { + if cfg!(target_pointer_width = "64") { + 8 + } else { + 4 + } + } + + + fn offset32(offset: usize) -> Offset32 { + assert!(offset <= i32::max_value() as usize); + (offset as i32).into() +} + /// Convert a usize offset into a `Imm64` for an iadd_imm. +fn imm64(offset: usize) -> Imm64 { + (offset as i64).into() +} + impl Module { /// Instantiate a Module given WASM bytecode pub fn from_bytes( buffer_source: Vec, - triple: Triple, - flags: Option, + config: TargetFrontendConfig, ) -> Result { // let return_mode = ReturnMode::NormalReturns; - let flags = flags.unwrap_or_else(|| settings::Flags::new(settings::builder())); let mut module = Self { - info: ModuleInfo::with_triple_flags(triple, flags), + info: ModuleInfo::new(config), trans: FuncTranslator::new(), func_bytecode_sizes: Vec::new(), // return_mode, @@ -265,15 +284,16 @@ impl Module { } pub fn verify(&self) { - let isa = isa::lookup(self.info.triple.clone()) - .unwrap() - .finish(self.info.flags.clone()); - - for func in self.info.function_bodies.values() { - verifier::verify_function(func, &*isa) - .map_err(|errors| panic!(pretty_verifier_error(func, Some(&*isa), None, errors))) - .unwrap(); - } + unimplemented!(); + // let isa = isa::lookup(self.info.triple.clone()) + // .unwrap() + // .finish(self.info.flags.clone()); + + // for func in self.info.function_bodies.values() { + // verifier::verify_function(func, &*isa) + // .map_err(|errors| panic!(pretty_verifier_error(func, Some(&*isa), None, errors))) + // .unwrap(); + // } } } @@ -302,96 +322,104 @@ impl<'environment> FuncEnvironment<'environment> { // Create a signature for `sigidx` amended with a `vmctx` argument after the standard wasm // arguments. fn vmctx_sig(&self, sigidx: SignatureIndex) -> ir::Signature { - let mut sig = self.mod_info.signatures[sigidx].clone(); + let mut sig = self.mod_info.signatures[sigidx.index()].clone(); sig.params.push(ir::AbiParam::special( self.pointer_type(), ir::ArgumentPurpose::VMContext, )); sig } - - fn ptr_size(&self) -> usize { - if self.triple().pointer_width().unwrap() == PointerWidth::U64 { - 8 - } else { - 4 - } - } } impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { - fn triple(&self) -> &Triple { - &self.mod_info.triple + /// Get the information needed to produce Cranelift IR for the given target. + fn target_config(&self) -> TargetFrontendConfig { + self.mod_info.config + } + + /// Get the Cranelift integer type to use for native pointers. + /// + /// This returns `I64` for 64-bit architectures and `I32` for 32-bit architectures. + fn pointer_type(&self) -> ir::Type { + ir::Type::int(u16::from(self.target_config().pointer_bits())).unwrap() } - fn flags(&self) -> &settings::Flags { - &self.mod_info.flags + /// Get the size of a native pointer, in bytes. + fn pointer_bytes(&self) -> u8 { + self.target_config().pointer_bytes() } fn make_table(&mut self, func: &mut ir::Function, table_index: TableIndex) -> ir::Table { + assert_eq!(table_index.index(), 0, "Only one WebAssembly memory supported"); let vmctx = func.create_global_value(ir::GlobalValueData::VMContext); - let ptr_size = self.ptr_size(); + let ptr_size = native_pointer_size(); // Given a instance, we want to retrieve instance.tables // Create a table whose base address is stored at `instance+0`. // 0 is the offset of the vmctx.tables pointer respect to vmctx pointer let base = func.create_global_value(ir::GlobalValueData::Load { base: vmctx, - offset: Offset32::new(0), + offset: offset32(0), global_type: self.pointer_type(), + readonly: true, }); // This will be 0 when the index is 0, not sure if the offset will work regardless - let table_data_offset = (table_index as usize * ptr_size * 2) as i32; + // let table_data_offset = table_index.index() * (ptr_size as usize) * 2 + ptr_size; // We get the pointer for our table index - let base_gv = func.create_global_value(ir::GlobalValueData::Load { + let bound_gv = func.create_global_value(ir::GlobalValueData::Load { base: base, - offset: Offset32::new(table_data_offset), - global_type: self.pointer_type(), + offset: offset32(0), + global_type: I64, + readonly: false, }); - let bound_gv = func.create_global_value(ir::GlobalValueData::Load { + let base_gv = func.create_global_value(ir::GlobalValueData::Load { base: base, - offset: Offset32::new(table_data_offset), - global_type: I64, + offset: offset32(ptr_size as usize), + global_type: self.pointer_type(), + readonly: false }); let table = func.create_table(ir::TableData { base_gv: base_gv, min_size: Imm64::new(0), bound_gv, - element_size: Imm64::new(i64::from(self.pointer_bytes())), - index_type: self.pointer_type(), + element_size: Imm64::new(i64::from(self.pointer_bytes()) * 2), + index_type: I64, }); // println!("FUNC {:?}", func); table } - fn make_heap(&mut self, func: &mut ir::Function, index: MemoryIndex) -> ir::Heap { + fn make_heap(&mut self, func: &mut ir::Function, memory_index: MemoryIndex) -> ir::Heap { // Create a static heap whose base address is stored at `instance+8`. let vmctx = func.create_global_value(ir::GlobalValueData::VMContext); let heap_base_addr = func.create_global_value(ir::GlobalValueData::Load { base: vmctx, - offset: Offset32::new(8), + offset: offset32(8), global_type: self.pointer_type(), + readonly: true, }); - let pointer_bytes = self.pointer_bytes(); - let memories_offset = (index * pointer_bytes as usize) as i32; + let pointer_bytes = self.pointer_bytes() as usize; + let memories_offset = memory_index.index() * pointer_bytes; // We de-reference the vm_context.memories addr let heap_base = func.create_global_value(ir::GlobalValueData::Load { base: heap_base_addr, - offset: Offset32::new(memories_offset), + offset: offset32(memories_offset), global_type: self.pointer_type(), + readonly: true, }); let bound_gv = func.create_global_value(ir::GlobalValueData::Load { base: vmctx, - offset: Offset32::new(120), + offset: offset32(120), global_type: I32, + readonly: false, }); func.create_heap(ir::HeapData { @@ -448,17 +476,18 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { // } } - fn make_global(&mut self, func: &mut ir::Function, index: GlobalIndex) -> GlobalVariable { + fn make_global(&mut self, func: &mut ir::Function, global_index: GlobalIndex) -> GlobalVariable { // Just create a dummy `vmctx` global. let vmctx = func.create_global_value(ir::GlobalValueData::VMContext); let globals_base_addr = func.create_global_value(ir::GlobalValueData::Load { base: vmctx, - offset: Offset32::new(16), + offset: offset32(16), global_type: self.pointer_type(), + readonly: false, }); - let offset = (index * 8) as i64; + let offset = (global_index.index() * 8) as i64; let iadd = func.create_global_value(ir::GlobalValueData::IAddImm { base: globals_base_addr, offset: Imm64::new(offset), @@ -466,7 +495,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { }); GlobalVariable::Memory { gv: iadd, - ty: self.mod_info.globals[index].entity.ty, + ty: self.mod_info.globals[global_index.index()].entity.ty, } } @@ -572,11 +601,11 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { fn translate_memory_grow( &mut self, mut pos: FuncCursor, - index: MemoryIndex, + memory_index: MemoryIndex, _heap: ir::Heap, val: ir::Value, ) -> WasmResult { - debug_assert_eq!(index, 0, "non-default memories not supported yet"); + debug_assert_eq!(memory_index.index(), 0, "non-default memories not supported yet"); let grow_mem_func = self.mod_info.grow_memory_extfunc.unwrap_or_else(|| { let sig_ref = pos.func.import_signature(Signature { call_conv: CallConv::SystemV, @@ -600,20 +629,20 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { }); // self.mod_info.grow_memory_extfunc = Some(grow_mem_func); - let memory_index = pos.ins().iconst(I32, index as i64); + let memory_index_value = pos.ins().iconst(I32, imm64(memory_index.index())); let vmctx = pos.func.special_param(ArgumentPurpose::VMContext).unwrap(); - let call_inst = pos.ins().call(grow_mem_func, &[val, memory_index, vmctx]); + let call_inst = pos.ins().call(grow_mem_func, &[val, memory_index_value, vmctx]); Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap()) } fn translate_memory_size( &mut self, mut pos: FuncCursor, - index: MemoryIndex, + memory_index: MemoryIndex, _heap: ir::Heap, ) -> WasmResult { - debug_assert_eq!(index, 0, "non-default memories not supported yet"); + debug_assert_eq!(memory_index.index(), 0, "non-default memories not supported yet"); let cur_mem_func = self.mod_info.current_memory_extfunc.unwrap_or_else(|| { let sig_ref = pos.func.import_signature(Signature { call_conv: CallConv::SystemV, @@ -637,22 +666,22 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { // self.mod_info.current_memory_extfunc = cur_mem_func; - let memory_index = pos.ins().iconst(I32, index as i64); + let memory_index_value = pos.ins().iconst(I32, imm64(memory_index.index())); let vmctx = pos.func.special_param(ArgumentPurpose::VMContext).unwrap(); - let call_inst = pos.ins().call(cur_mem_func, &[memory_index, vmctx]); + let call_inst = pos.ins().call(cur_mem_func, &[memory_index_value, vmctx]); Ok(*pos.func.dfg.inst_results(call_inst).first().unwrap()) // Ok(pos.ins().iconst(I32, -1)) } - // fn return_mode(&self) -> ReturnMode { - // self.return_mode - // } + fn return_mode(&self) -> ReturnMode { + ReturnMode::FallthroughReturn + } } impl<'data> ModuleEnvironment<'data> for Module { - fn flags(&self) -> &settings::Flags { - &self.info.flags + fn target_config(&self) -> &TargetFrontendConfig { + &self.info.config } fn get_func_name(&self, func_index: FuncIndex) -> ir::ExternalName { @@ -676,7 +705,7 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn get_signature(&self, sig_index: SignatureIndex) -> &ir::Signature { - &self.info.signatures[sig_index] + &self.info.signatures[sig_index.index()] } fn declare_func_import( @@ -713,7 +742,7 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn get_global(&self, global_index: GlobalIndex) -> &Global { - &self.info.globals[global_index].entity + &self.info.globals[global_index.index()].entity } fn declare_table(&mut self, table: Table) { @@ -728,7 +757,7 @@ impl<'data> ModuleEnvironment<'data> for Module { elements: Vec, ) { // NEW - debug_assert!(base.is_none(), "global-value offsets not supported yet"); + // debug_assert!(base.is_none(), "global-value offsets not supported yet"); self.info.table_elements.push(TableElements { table_index, base, @@ -767,7 +796,7 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_table_export(&mut self, table_index: TableIndex, name: &'data str) { - self.info.tables[table_index] + self.info.tables[table_index.index()] .export_names .push(String::from(name)); // We add to the exports to have O(1) retrieval @@ -777,7 +806,7 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_memory_export(&mut self, memory_index: MemoryIndex, name: &'data str) { - self.info.memories[memory_index] + self.info.memories[memory_index.index()] .export_names .push(String::from(name)); // We add to the exports to have O(1) retrieval @@ -787,7 +816,7 @@ impl<'data> ModuleEnvironment<'data> for Module { } fn declare_global_export(&mut self, global_index: GlobalIndex, name: &'data str) { - self.info.globals[global_index] + self.info.globals[global_index.index()] .export_names .push(String::from(name)); // We add to the exports to have O(1) retrieval From f3cbfc0e09d11446dbbc43eb8315c89635a933a0 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 18 Nov 2018 15:23:38 -0800 Subject: [PATCH 2/3] Fixed return_mode --- src/webassembly/module.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/webassembly/module.rs b/src/webassembly/module.rs index 3974b90de10..fa54d754983 100644 --- a/src/webassembly/module.rs +++ b/src/webassembly/module.rs @@ -364,7 +364,6 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { assert_eq!(table_index.index(), 0, "Only one WebAssembly memory supported"); let instance = func.create_global_value(ir::GlobalValueData::VMContext); let ptr_size = native_pointer_size(); - // Load value at (instance + TABLES_OFFSET) // which is the address of data_pointer.tables let base = func.create_global_value(ir::GlobalValueData::Load { @@ -660,7 +659,8 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { } fn return_mode(&self) -> ReturnMode { - ReturnMode::FallthroughReturn + ReturnMode::NormalReturns + // ReturnMode::FallthroughReturn } } From 998d7294f0d2808f7ac7b29268fadc6f51dd85fa Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Sun, 18 Nov 2018 15:41:31 -0800 Subject: [PATCH 3/3] Fix table element size --- src/webassembly/module.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/webassembly/module.rs b/src/webassembly/module.rs index fa54d754983..1b8a76c6620 100644 --- a/src/webassembly/module.rs +++ b/src/webassembly/module.rs @@ -391,7 +391,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { base, offset: Offset32::new(table_data_offset + ptr_size as i32), global_type: self.pointer_type(), - readonly: true, + readonly: false, }); // Create table based on the data above @@ -399,7 +399,7 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { base_gv, min_size: Imm64::new(0), bound_gv, - element_size: Imm64::new(i64::from(self.pointer_bytes()) * 2), + element_size: Imm64::new(i64::from(self.pointer_bytes())), index_type: I64, }); @@ -525,18 +525,22 @@ impl<'environment> FuncEnvironmentTrait for FuncEnvironment<'environment> { // The `callee` value is an index into a table of function pointers. // Apparently, that table is stored at absolute address 0 in this dummy environment. // TODO: Generate bounds checking code. - let ptr = self.pointer_type(); + let ptr = native_pointer_type(); let callee_offset = if ptr == I32 { // pos.ins().imul_imm(callee, 4) callee } else { - let ext = pos.ins().uextend(I64, callee); + let ext = pos.ins().uextend(ptr, callee); ext // pos.ins().imul_imm(ext, 4) }; + // let entry_size = native_pointer_size() as i64 * 2; + // let callee_scaled = pos.ins().imul_imm(callee_offset, entry_size); + let entry_addr = pos .ins() - .table_addr(self.pointer_type(), table, callee_offset, 0); + .table_addr(ptr, table, callee_offset, 0); + let mut mflags = ir::MemFlags::new(); mflags.set_notrap(); mflags.set_aligned();