Browsers Now Spit Out Compilation Error Messages

Compilation error messages steps into the browser world. The “failed to compile wasm module: CompileError: at offset 8: binary version 0xd does not match expected version 0x1” message was generated after trying to execute a simple “Hello World” application in the Firefox browser. The same message was shown by chrome. What does this message mean?

I rarely see a compilation error message that can be easily understood, and is useful, they look like medical doctor scribble…

webassembly-compilation-error-old-emsdk-version

Too Specific of an Error Message

This error message made me remember of a classical joke:

A man in a hot air balloon realized he was lost. He got lower and asked a woman for help: Do you know where I am?

She replies: You are in a hot air balloon 30 feet above ground.

You must be a consultant, said the lost man.

I am, how do you know?

Well, the information you gave me is right and useless, because I am still lost…

There is a second part to this joke, I will tell you after the conclusion, lets go back to Webassembly.

Wait a Minute, is The Browser Compiling Webassembly?

Isn’t EMSCRIPTEN the compiler? I thought the compilation would occur in my computer while I compile my C code? Yes, but the browser have to translate the Webassembly instructions into instructions for the processor where your code is going to run. I guess browsers are calling this translation step compilation. Which I guess is not semantically wrong.

Lets see the steps needed to run C source code when Webassembly is used:

Step Compiler Description
1 EMSCRIPTEN C –> Webassembly
2 Browser Webassembly –> Processor instructions

And here when Webassembly is not used:

Step Compiler Description
1 GCC (or other C compiler) C –> Processor instructions

 Another Reason to (Really) Verify if The customer Browser Supports Webassembly

In this post I show how to (really) verify if your user Browser supports Webassembly.

Deconstructing The Error Message

“CompileError: at offset 8: binary version 0xd does not match expected version 0x1”

The Binary Encoding Specification is the official document that allows us to understand Webassembly module sections. A Webassembly module always starts like this:

Field Type Description
magic number uint32 Magic number 0x6d736100 (i.e., asm)
version uint32 Version number, 0x1

Here is how a Webassembly module first words looks like:

webassembly-helloworld-module-version

Ha! We have found the version 0xd part of the error message.

Now lets look for the version 0x1 part of the error message.

According to EMSCRIPTEN change log, versions 1.37.3 and newer are considered stable. Version 1.37.3 generates Webassembly modules with version 0x01:


v1.37.3: 2/16/2017
------------------
 - **Updated Binaryen to version 0x01**. First official stable WebAssembly support version. (#4953)
 - Optimized memcpy and memset with unrolling and SIMD, when available.
 - Improved Emscripten toolchain profiler to track more hot code.
 - Added new linker flag -s WEBGL2_BACKWARDS_COMPATIBILITY_EMULATION=1 to allow simultaneously targeting WebGL 1 and WebGL 2.
 - Optimize Emscripten use of multiprocessing pools.
 - More WebGL 2 garbage free optimizations.
 - Full list of changes:
    - Emscripten: https://github.com/kripken/emscripten/compare/1.37.2...1.37.3
    - Emscripten-LLVM: https://github.com/kripken/emscripten-fastcomp/compare/1.37.2...1.37.3
    - Emscripten-Clang: no changes.

Ha again! It looks like the Webassembly crowd decided (or someone decided for them) when to consider Webassembly “stable”, and from that point on, Webassembly’s module version was assigned the version 0x1. Current browsers fail to deal with Webassembly modules with version different than 0x1.

I can understand part of this decision. But would this mean that Webassembly module version must be 0x1 forever? At least this is what the browsers are currently checking for. So no evolution on that front. Lets hope the module version won’t need changes!

The other conclusion we have is that using EMSCRIPTEN older than 1.37.3 generates code that does no run on current browsers.

How Did I Get There?

Not sure I got with EMSCRIPTEN version 1.37.1!

Perhaps because, when I first decided to look into Webassembly, I have not installed EMSCRIPTEN by following the Webassembly.org’ get started instructions, instead I have Installed EMSCRIPTEN by searching google for “emscripten download” and following the sdk installation instructions.

DON’T BYTE OFF MORE THAN YOU CAN CHEW

Going back to compilation error messages, it looks like Intercal is a language that puts some humor into error messages, look at this one from the Quora post:

Error : DON’T BYTE OFF MORE THAN YOU CAN CHEW Reason : I tried to store a 32 bit integer in a 16 bit variable. In case had I tried to store a 64 bit integer in a 32 bit variable, the error would have been YOU WANT MAYBE WE SHOULD IMPLEMENT 64-BIT VARIABLES?

At least it is clear, what message would GCC give for this error?

Conclusion

The error message happens because EMSCRIPTEN versions older than 1.37.3 generates Webassembly module versions that are not considered “stable” by current browsers. Browsers expects Webassembly module version 0x1. No other number for Webassembly module version is currently accepted! This error makes a point in having a more complete verification on the Browser as far as its Webassembly support.

Finally, Here is the Whole Joke

A man in a hot air balloon realized he was lost. He got lower and asked a woman for help: Do you know where I am?

She replies: You are in a hot air balloon 30 feet above ground

You must be a consultant, said the lost man

I am, how do you know?

Well, the information you gave me is right and useless, because I am still lost…

And then the woman replied:

You must be a manager.

I am, how do you know?

Well, you don’t know where you are, or where you are going, and you want people that stand lower than you to solve your problems!

Post MindMap


Leave a message below. Webassembly is evolving rapidly, please let me know if this post got outdated.

Enjoyed this post?

Don't miss new posts: Share it with your friends:

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *