-
Notifications
You must be signed in to change notification settings - Fork 695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Should module byte offsets be used for specifying wasm code locations? #1071
Comments
Previous discussion can be found at https://github.com/WebAssembly/design/pull/1064/files#r116468692 and #1053 (comment) (and the replies to those) |
One sort of fundamental question that hasn't been discussed yet is whether we care about having locations be specific to a function or not; i.e. the byte offset is global in the module whereas the so-far-discussed instruction-numbering schemes are all local to a function. So in that case a full reference would be a tuple of a function index and instruction index. I don't imagine browsers or encoding/decoding tools would care much; it's more interesting for debugging tools. For source maps and other JS-centric tools we currently have a mismatch between the line:column tuple used there, so using another field would probably be no big deal. DWARF and other systems that assume a single global address might be more interesting. |
Purpose of numbering scheme will be to identify an instruction, and most of proposed here things will work fine for this, e.g. module byte code offset, instruction number and function number pair, etc. We need to choose the simplest that will reduce overhead on operations performed with it, e.g. to quickly locate and display disassembly of the trapped instruction, without building/storing any additional indices in memory. I don't think the display format of the reference will matter much to the human. Based on the use cases we already perform with instructions, any of the schemes suggested above will work just fine: global byte offset, function index and local byte offset pair, function index and instruction index pair. I identified the following use cases related to the subject so far:
Are there more?
Knowing what schemes our tools are using at the moment, and if there are any (performance?) problems with what is used, might help us to see if what we have is the acceptable solution. |
To get debug info without reinventing too many wheels I suspect the easiest path would be to use DWARF. If that's the case, then doing something that fits into existing DWARF conventions would make it easier to use existing tools. For attributes used to define machine code addresses (2.17 Code Addresses, Ranges and Base Addresses) like I think using a single bytecode offset to reference instructions (equivalent to a program counter in other architectures) is likely to make for fewer headaches. It ought to be fairly straightforward to adapt DWARF for WebAssembly with that. All the DWARF standard section references above are from the latest version of the DWARF spec (DWARF 5). |
In #1053 (and in the first version of #1064) locations of wasm instructions are specified as byte offsets in the module. This is analogous to use of PC addresses in native code, and this style of location is usable in browsers (e.g. for error messages and stack traces), in a module's name section as proposed in #1064 (which could feed into those same browser use cases, as well as online debugging), and in offline tools such as WABT and LLVM.
However, wasm is unlike traditional native-code architectures in that the code is not actually exposed to the program itself, so any specifications of references to code locations are just conventions rather than having any semantic meaning. All of the semantics and (other than the aforementioned cases) all of the conventions about wasm locations are self-consistent without reference to the binary bytes of the instructions (e.g. branch depth, imports/exports and all the other index spaces, etc). So it might be worth considering alternative naming/numbering schemes for referring to specific instructions in a wasm program.
The text was updated successfully, but these errors were encountered: