From 4d3715d89f97f3f9b6e366bbabe01f9d64ed56cf Mon Sep 17 00:00:00 2001 From: Luuk de Gram Date: Sun, 22 May 2022 19:07:16 +0200 Subject: wasm-linker: de-duplicate functions+atom sorting Multiple symbols can point to the same function, this means that when we loop over the symbol list, we must deduplicate those functions being added twice. Additionaly, we must also ensure that when we append a new type and set the type index on a function, we must not do this again for the same function. This commit also implements sorting of code atoms to ensure their order matches the order of the function section to ensure the function signature matches that of the function body. --- src/link/Wasm/Atom.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/link/Wasm') diff --git a/src/link/Wasm/Atom.zig b/src/link/Wasm/Atom.zig index 03b6fc6cf4..40b7f64804 100644 --- a/src/link/Wasm/Atom.zig +++ b/src/link/Wasm/Atom.zig @@ -155,7 +155,7 @@ fn relocationValue(self: Atom, relocation: types.Relocation, wasm_bin: *const Wa .R_WASM_TABLE_INDEX_SLEB, .R_WASM_TABLE_INDEX_SLEB64, => return wasm_bin.function_table.get(target_loc) orelse 0, - .R_WASM_TYPE_INDEX_LEB => return wasm_bin.functions.items[symbol.index].type_index, + .R_WASM_TYPE_INDEX_LEB => return wasm_bin.functions.values()[symbol.index - wasm_bin.imported_functions_count].type_index, .R_WASM_GLOBAL_INDEX_I32, .R_WASM_GLOBAL_INDEX_LEB, => return symbol.index, -- cgit v1.2.3