Skip to content

Module Naming Resolution

Erik McClure edited this page May 27, 2019 · 1 revision

WebAssembly does not provide a standard way of naming modules. The closest it has is the optional custom name section, which may or may not be present, and doesn't necessarily include a module name. This custom name section roughly translates to the optional name you can give to modules in the .wat textual representation, but it's still optional.

Despite the fact that a module is not required to provide it's own name, module names are required to resolve WebAssembly imports. As a result, inNative must guarantee the uniqueness of module names, while also respecting the name section if it exists. Once inNative has resolved a module's name, it is always stored in the module->name byte array, which is the definitive name of the module as far as inNative is concerned, and should be what you query to figure out what name ended up being used.

The steps inNative follows to resolve the module name are as follows:

  1. If a module name is included in the custom name section, use it.
  2. Otherwise, if a suggested name has been passed into AddModule(), use the suggested name.
  3. If there is no suggested name, use the name m##, where ## is the index number of the module (e.g. m0).

Tooling Names

Various tools and compilation situations rely on generating unique suggested names. This is usually to preserve as much information as possible.

innative-cmd

The command line will always use the suggested name that is the file name without an extension.

.wast files

When compiling a .wast file, each module is compiled with the suggested name of wast_m##, where ## is the index number of the module.