WebAssembly / wabt

The WebAssembly Binary Toolkit
Apache License 2.0
6.73k stars 687 forks source link

[wasm2wat] Nicer error for known but disabled feature #1197

Open godmar opened 4 years ago

godmar commented 4 years ago

Hi, I'm new to WASM.

I've installed emscripten using the installation instructions and tried it out on a simple program:

#include <cstdlib>
#include <cstring>

char *
malloc_demo()
{
    char *p = (char *)malloc(20);
    strcpy(p, "Hello, World\n");
    return p;
}

this is with

$ emcc -v
emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 1.39.0
clang version 10.0.0 (/b/s/w/ir/cache/git/chromium.googlesource.com-external-github.com-llvm-llvm--project e44524736c4a97ae4fb37193e58647f838f6d36a)

when I run wabt on it (the current build), I see:

$ wasm2wat malloc.wasm 
000009d: error: invalid section code: 12

I googled the specification - indeed, section numbers don't extend past 11.

However, I also found an issue in the LLVM Phabricator that introduced a DataCount section, which tools such as binaryen apparently support.

The Phabricator issue notes that: Engines that don't support bulk memory operations will not recognize the DataCount section and will report validation errors, but that's ok because object files aren't supposed to be run directly anyway.

I suppose my confusion is why I tapped into something that's apparently in development. Does wabt tracked 'tagged releases' of emscripten? Should wabt be able to convert files containing such "linking sections" to the .wat format, and this particular feature just has not been implemented? Or am I mistaken in the idea to be able to convert files written by emscripten using wabt?

Thank you.

godmar commented 4 years ago

PS: running wasm2wat -v, I found:

$ wasm2wat --enable-bulk-memory malloc.wasm -o malloc.wat

or

$ wasm2wat --enable-all malloc.wasm -o malloc.wat

which make it parse this file.

I suppose this makes my issue a usability suggestion. How about instead of outputting invalid section code, output invalid section code - did you forget to enable a feature you want?

binji commented 4 years ago

Agreed, that would be a nice fix. It would be even nicer to look for these known but disabled features and mentions the flag explicitly.