WebAssembly / tool-conventions

Conventions supporting interoperatibility between tools working with WebAssembly.
Artistic License 2.0
298 stars 65 forks source link

Relocation offsets are relative to what? #143

Closed kripken closed 4 years ago

kripken commented 4 years ago

Maybe this is obvious but I can't find it. Linking.md says

offset | varuint32 | offset of the value to rewrite

But is the offset relative to the entire wasm module, or relative to the relevant section? (and if the section, does it include the section ID + LEB size, or is 0 right after that?)

I see

Note that for all relocation types, the bytes being relocated (from offset to offset + 5 for LEB/SLEB relocations or offset + 4 for I32) must lie within the section to which the relocation applies.

If the offset is relative to the whole module, then this sentence makes sense to me. If it's relative to the section, then "must lie within" can only mean they must not be too big as to be past the end of the section, which might be clearer?

aardappel commented 4 years ago

It's relative to the section, after the section size (but before the section element count, if any).

kripken commented 4 years ago

Thanks! I'll open a PR.