emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.36k stars 3.25k forks source link

Wasm validator error #22090

Open n0thhhing opened 2 weeks ago

n0thhhing commented 2 weeks ago

I recently upgraded emsdk to latest and I am given a wasm validator error, before upgrading the build worked as expected and didn't have any errors, but now after updating and attempting to rebuild, I'm getting the following error

[wasm-validator error in function 581] call param types must match, on
(call $fimport$0
 (i32.add
  (local.get $7)
  (i32.const 8)
 )
 (local.get $5)
 (select
  (i32.const 0)
  (select
   (i32.const 1)
   (i32.const 2)
   (i32.and
    (local.tee $2
     (i32.load offset=4
      (local.get $0)
     )
    )
    (i32.const 4)
   )
  )
  (i32.and
   (local.get $2)
   (i32.const 2)
  )
 )
)
(on argument 1)
[wasm-validator error in function 581] call param types must match, on
(call $fimport$0
 (i32.add
  (local.get $7)
  (i32.const 8)
 )
 (local.get $5)
 (select
  (i32.const 0)
  (select
   (i32.const 1)
   (i32.const 2)
   (i32.and
    (local.tee $2
     (i32.load offset=4
      (local.get $0)
     )
    )
    (i32.const 4)
   )
  )
  (i32.and
   (local.get $2)
   (i32.const 2)
  )
 )
)
(on argument 2)
Fatal: error validating input
emcc: error: '/root/emsdk/upstream/bin/wasm-opt --strip-target-features --post-emscripten -O3 --low-memory-unused --zero-filled-memory --pass-arg=directize-initial-contents-immutable /tmp/emscripten_temp_49nmu78j/libcapstone.wasm -o /tmp/emscripten_temp_49nmu78j/libcapstone.wasm --mvp-features --enable-multivalue --enable-mutable-globals --enable-sign-ext' failed (returned 1)
make: *** [Makefile:10: build] Error 1

NOTES:

n0thhhing commented 2 weeks ago

I was previously using emsdk version 3.1.47(downgrading back to it fixed the issue, but I can't use the latest)

kripken commented 2 weeks ago

If you can save the temp files emitted by EMCC_DEBUG=1 in the env, then there should be some wasm files in /tmp/emscripten_temp/ that you can attach here, which should reproduce the issue so we can investigate.

n0thhhing commented 2 weeks ago

Here's everything that was outputed debug.zip

kripken commented 2 weeks ago

Thanks @n0thhhing , looks like even emcc-00-*.wasm has errors (the same call param types must match as you reported), so this must be a clang or wasm-ld issue. Two ways to look into that:

  1. Provide all the linker inputs + linker command so we can reproduce in full. That may lead to discovering a particular object file is broken.
  2. Bisecting to find where this regressed: https://emscripten.org/docs/contributing/developers_guide.html#bisecting

@sbc100 I wonder if we can make 1 easier somehow, as this situation happens now and then. Could wasm-ld validate the input object files it reads? And/or could it validate its output?

n0thhhing commented 2 weeks ago

Here I have provided a zip file containing the full directory structure, linker commands, and necessary inputs to reproduce the issue. You can find the details in README.md.

emscripten_bug.zip

Please let me know if any additional information is required.

My repo which contains everything is ts-capstone

n0thhhing commented 2 weeks ago

It may be because the libcapstone.a file was compiled with an older version and is now being used with emcc in a newer version