From 55bb0c134ff5face3cf1b69b9f86c574558a6908 Mon Sep 17 00:00:00 2001 From: bxq2011hust Date: Sun, 9 Jun 2024 17:06:43 +0800 Subject: [PATCH] try to fix Unknown opcode 192 --- .github/workflows/workflow.yml | 4 ++- Cargo.lock | 8 ++--- Cargo.toml | 4 +-- rust-toolchain.toml | 2 +- src/main/cmd/build.rs | 55 ++++++++++++++++++++-------------- 5 files changed, 42 insertions(+), 31 deletions(-) diff --git a/.github/workflows/workflow.yml b/.github/workflows/workflow.yml index cfcd96d..94e7132 100644 --- a/.github/workflows/workflow.yml +++ b/.github/workflows/workflow.yml @@ -19,10 +19,12 @@ jobs: - name: install rust nightly uses: actions-rs/toolchain@v1 with: - toolchain: nightly-2021-06-23 + toolchain: nightly-2024-02-25 components: rustc-dev, rust-src, llvm-tools-preview - name: install cargo-liquid run: cargo install --path . --force + - name: install wasm-opt + run: cargo install wasm-opt --force - name: compile test contract run: cd .\tests\conflict_analysis_test\contract && cargo liquid build - name: setup python diff --git a/Cargo.lock b/Cargo.lock index 04d60e2..7b6c4c1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -592,9 +592,9 @@ checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" [[package]] name = "parity-wasm" -version = "0.41.0" +version = "0.42.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc878dac00da22f8f61e7af3157988424567ab01d9920b962ef7dcbd7cd865" +checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" [[package]] name = "petgraph" @@ -653,9 +653,9 @@ dependencies = [ [[package]] name = "pwasm-utils" -version = "0.14.0" +version = "0.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0f53bc2558e8376358ebdc28301546471d67336584f6438ed4b7c7457a055fd7" +checksum = "2ecdabd73c8beaf98c66e45aff3032b56260ee49eb5d0d1222ecce269bfafda7" dependencies = [ "byteorder", "log", diff --git a/Cargo.toml b/Cargo.toml index 797f6a1..a7dbf85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,8 +16,8 @@ rustc_version = "0.2.3" cargo-xbuild = "0.6.6" toml = "0.5.6" tempfile = "3.1.0" -parity-wasm = "0.41.0" -pwasm-utils = "0.14.0" +parity-wasm = "0.42.0" +pwasm-utils = "0.19.0" which = "4.0.2" indicatif = { version = "0.15.0", features = ["rayon", "improved_unicode"] } console = "0.13.0" diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 1b6fe42..cd4454a 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "nightly-2023-01-03" +channel = "nightly-2024-02-25" components = [ "rust-src", "rustc-dev", "llvm-tools-preview" ] diff --git a/src/main/cmd/build.rs b/src/main/cmd/build.rs index 2526103..34de419 100644 --- a/src/main/cmd/build.rs +++ b/src/main/cmd/build.rs @@ -192,7 +192,12 @@ fn build_cargo_project( if let Ok(ref old_flags) = old_flags { env::set_var( RUSTFLAGS_ENV_VAR, - [old_flags, "-C link-arg=-z -C link-arg=stack-size=65536"].join(" "), + [ + old_flags, + // add -C target-cpu=mvp try to fix https://github.com/rust-lang/rust/issues/109807 + "-C target-feature=-sign-ext -C target-cpu=mvp -C link-arg=-z -C link-arg=stack-size=65536", + ] + .join(" "), ); } @@ -284,28 +289,31 @@ fn strip_custom_sections(module: &mut Module) { /// succeed, and the user will be encouraged to install it for further optimizations. fn optimize_wasm(crate_metadata: &CrateMetadata) -> Result<()> { // Deserialize wasm module from a file. - let mut module = - parity_wasm::deserialize_file(&crate_metadata.original_wasm).context(format!( - "Loading original wasm file '{}'", - crate_metadata.original_wasm.display() - ))?; - - // Perform optimization. - // - // In practice only tree-shaking is performed, i.e transitively removing all symbols that are - // NOT used by the specified entry points. - if pwasm_utils::optimize( - &mut module, - ["main", "deploy", "memory", "hash_type"].to_vec(), - ) - .is_err() - { - anyhow::bail!("Optimizer failed"); - } - strip_custom_sections(&mut module); - - parity_wasm::serialize_to_file(&crate_metadata.dest_wasm, module)?; - + // print!("crate_metadata.original_wasm: {:?}", crate_metadata.original_wasm); + // print!("crate_metadata.dest_wasm: {:?}", crate_metadata.dest_wasm); + // let mut module = + // parity_wasm::deserialize_file(&crate_metadata.original_wasm).context(format!( + // "Loading original wasm file '{}'", + // crate_metadata.original_wasm.display() + // ))?; + + // // Perform optimization. + // // + // // In practice only tree-shaking is performed, i.e transitively removing all symbols that are + // // NOT used by the specified entry points. + // if pwasm_utils::optimize( + // &mut module, + // ["main", "deploy", "memory", "hash_type"].to_vec(), + // ) + // .is_err() + // { + // anyhow::bail!("Optimizer failed"); + // } + // strip_custom_sections(&mut module); + + // parity_wasm::serialize_to_file(&crate_metadata.dest_wasm, module)?; + + fs::copy(&crate_metadata.original_wasm, &crate_metadata.dest_wasm)?; // check `wasm-opt` installed if which::which("wasm-opt").is_err() { eprintln!( @@ -323,6 +331,7 @@ fn optimize_wasm(crate_metadata: &CrateMetadata) -> Result<()> { let output = Command::new("wasm-opt") .arg(crate_metadata.dest_wasm.as_os_str()) + .arg("--signext-lowering") .arg("-g") .arg("-O3") // execute -O3 optimization passes (spends potentially a lot of time optimizing) .arg("-o")