oracle / graal

GraalVM compiles Java applications into native executables that start instantly, scale fast, and use fewer compute resources 🚀
https://www.graalvm.org
Other
20.41k stars 1.64k forks source link

[wasm] not compiling example #2292

Closed aitorhh closed 4 years ago

aitorhh commented 4 years ago

Describe the issue wasm not compiling while testing example provided at https://www.graalvm.org/docs/reference-manual/languages/wasm/

Steps to reproduce the issue Please include both build steps as well as run steps

  1. sdk install java 20.0.0.r11-grl
  2. sdk use java 20.0.0.r11-grl
  3. Download the latest wasm: wget https://github.com/graalvm/graalvm-ce-dev-builds/releases/download/20.1.0-dev-20200325_0537/wasm-installable-svm-java11-linux-amd64-20.1.0-dev.jar
  4. gu install --force -L wasm-installable-svm-java11-linux-amd64-20.1.0-dev.jar
  5. Create example floyd.wasm from https://www.graalvm.org/docs/reference-manual/languages/wasm/
  6. wasm --Builtins=memory,env:emscripten loyd.wasm

Describe GraalVM and your environment:

More details After running wasm --Builtins=memory,env:emscripten loyd.wasm:

ERROR: Invalid MAGIC number: 1668180259 should = 1836278016.

When using wasm v20.0.0 from stable release, I get a more detailed stacktrace:

wasm --Builtins=memory,env:emscripten polyglot-hello-world-scala/src/wasm/floyd.wasm                                                                     127   master 
ERROR: org.graalvm.wasm.exception.BinaryParserException: Invalid MAGIC number: should be equal: 1668180259 != 1836278016                                                                                          
org.graalvm.polyglot.PolyglotException: org.graalvm.wasm.exception.BinaryParserException: Invalid MAGIC number: should be equal: 1668180259 != 1836278016                                                         
        at org.graalvm.wasm.Assert.fail(Assert.java:115)                                  
        at org.graalvm.wasm.Assert.assertIntEqual(Assert.java:56)                                                                                                                                                 
        at org.graalvm.wasm.BinaryParser.validateMagicNumberAndVersion(BinaryParser.java:108)
        at org.graalvm.wasm.BinaryParser.readModule(BinaryParser.java:102)                                                              
        at org.graalvm.wasm.WasmLanguage.parse(WasmLanguage.java:71)                                                                                                                                              
        at com.oracle.truffle.api.TruffleLanguage$ParsingRequest.parse(TruffleLanguage.java:833)                               
        at com.oracle.truffle.api.TruffleLanguage.parse(TruffleLanguage.java:1245)                                                                                                                                
        at com.oracle.truffle.api.LanguageAccessor$LanguageImpl.parse(LanguageAccessor.java:213)                                                                                                                  
        at com.oracle.truffle.polyglot.PolyglotSourceCache.parseImpl(PolyglotSourceCache.java:92)                                                                                                                 
        at com.oracle.truffle.polyglot.PolyglotSourceCache.parseCached(PolyglotSourceCache.java:73)                                                                                                               
        at com.oracle.truffle.polyglot.PolyglotLanguageContext.parseCached(PolyglotLanguageContext.java:321)                                                                                                      
        at com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:821)                                                                                                                     
        at org.graalvm.polyglot.Context.eval(Context.java:345)          
        at org.graalvm.wasm.launcher.WasmLauncher.execute(WasmLauncher.java:95)
        at org.graalvm.wasm.launcher.WasmLauncher.launch(WasmLauncher.java:90)
        at org.graalvm.launcher.AbstractLanguageLauncher.launch(AbstractLanguageLauncher.java:121)
        at org.graalvm.launcher.AbstractLanguageLauncher.launch(AbstractLanguageLauncher.java:70)
        at org.graalvm.wasm.launcher.WasmLauncher.main(WasmLauncher.java:61)                                                                                                                                      
Original Internal Error:                                                                                        
org.graalvm.wasm.exception.BinaryParserException: Invalid MAGIC number: should be equal: 1668180259 != 1836278016                                                                                                 
        at org.graalvm.wasm.Assert.fail(Assert.java:115)                                                                                                                                                          
        at org.graalvm.wasm.Assert.assertIntEqual(Assert.java:56)                                 
        at org.graalvm.wasm.BinaryParser.validateMagicNumberAndVersion(BinaryParser.java:108)                                                                                                                     
        at org.graalvm.wasm.BinaryParser.readModule(BinaryParser.java:102)                                                                                                                                        
        at org.graalvm.wasm.WasmLanguage.parse(WasmLanguage.java:71)                                                                       
        at com.oracle.truffle.api.TruffleLanguage$ParsingRequest.parse(TruffleLanguage.java:833)                                                                                                                  
        at com.oracle.truffle.api.TruffleLanguage.parse(TruffleLanguage.java:1245)                                                                                                                                
        at com.oracle.truffle.api.LanguageAccessor$LanguageImpl.parse(LanguageAccessor.java:213)                                                                                                                  
        at com.oracle.truffle.polyglot.PolyglotSourceCache.parseImpl(PolyglotSourceCache.java:92)
        at com.oracle.truffle.polyglot.PolyglotSourceCache.parseCached(PolyglotSourceCache.java:73)                                                                                                               
        at com.oracle.truffle.polyglot.PolyglotLanguageContext.parseCached(PolyglotLanguageContext.java:321)                                                                                                      
        at com.oracle.truffle.polyglot.PolyglotContextImpl.eval(PolyglotContextImpl.java:821)                                                                              
        at org.graalvm.polyglot.Context.eval(Context.java:345)
        at org.graalvm.wasm.launcher.WasmLauncher.execute(WasmLauncher.java:95)                                                                                                                                   
        at org.graalvm.wasm.launcher.WasmLauncher.launch(WasmLauncher.java:90)
        at org.graalvm.launcher.AbstractLanguageLauncher.launch(AbstractLanguageLauncher.java:121)                                                                                                                 
        at org.graalvm.launcher.AbstractLanguageLauncher.launch(AbstractLanguageLauncher.java:70)                                                                                                                  
        at org.graalvm.wasm.launcher.WasmLauncher.main(WasmLauncher.java:61)                                                                       
Caused by: Attached Guest Language Frames (0)                                  
olyagpl commented 4 years ago

@aitorhh, thank you for the report. The error is reproducible.

olyagpl commented 4 years ago

@aitorhh, there was a change introduced to WASM support in GraalVM. We updated the doc https://www.graalvm.org/reference-manual/wasm/#running-webassembly-programs. It is recommended to built WASM binary must be built using a recent Emscripten version. The Builtins option should point to wasi_snapshot_preview1: wasm --Builtins=wasi_snapshot_preview1 example.wasm. Thanks for reporting the problem!