Repository navigation
port(wasm): Apply code section index relocations - #2058
Conversation
|
With more practical testing cases becoming available, I plan to begin establishing a basic testing infrastructure once this gets merged. |
There was a problem hiding this comment.
Nice! Looking forward to seeing some tests in a later PR :)
da0b940 to
da6cefe
Compare
| pub(crate) bytes: &'data [u8], | ||
| /// Byte offset of this body (starting at its size prefix) within the code section payload. | ||
| pub(crate) code_offset: u32, | ||
| pub(crate) relocations: Vec<ResolvedCodeReloc>, |
There was a problem hiding this comment.
It looks to me like it might be possible to avoid this Vec and store just enough information to find the relocations later on. e.g. a &'data [WasmRelocation] or even just a u32 that represents the index of the first relocation for this function. But it's perfectly reasonable to leave this optimisation until later.
There was a problem hiding this comment.
If we do that, we'll have to propagate relocation value resolution to the writer side, which would require each object to access its own index map and symbols reference, so the current implementation should be kept I think. But of course we can revisit this if allocation overhead becomes a concern.
This patch enables the application of code index relocations (
R_WASM_TYPE_INDEX_LEB,R_WASM_FUNCTION_INDEX_LEB,R_WASM_FUNCTION_INDEX_I32,R_WASM_GLOBAL_INDEX_LEB,R_WASM_GLOBAL_INDEX_I32). The byte-level encoding primitives (apply_relocation()) were already implemented in a prior patch and this patch adds the symbol-to-output-index resolution, per-body relocation grouping, and replaces thewasm_encoder::CodeSectionbuilder with direct emission into the output buffer.Part of #1431