How to preserve variable names when compiling with clang to wasm

Viewed 222

clang successfully emits a wasm custom name section containing the function names (when compiling with the -g option), however I found no way to also emit the parameter names and variable names of unoptimized code. Is there such an option, or an open ticket to preserve the progress of this feature?

1 Answers

;tldr; the name section is not rich enough to encode this information.

When clang compiles to WebAssembly, variables from the source language do not correspond directly to WebAssembly constructs such as locals and globals (at least not in a consistent way). The only current way to achieve that is via the DWARF information that clang emits (if you build with emscripten you can use -g3 to get DWARF output). The ecosystem of tools that understands this debug information is still growing but chrome recently announced support for using it: https://developers.google.com/web/updates/2019/12/webassembly

Related