| ... | ... | @@ -97,7 +97,7 @@ pub fn symbolLoc(self: Atom) Wasm.SymbolLoc { |
| 97 | 97 | |
| 98 | 98 | /// Resolves the relocations within the atom, writing the new value |
| 99 | 99 | /// at the calculated offset. |
| 100 | | pub fn resolveRelocs(self: *Atom, wasm_bin: *const Wasm) !void { |
| 100 | pub fn resolveRelocs(self: *Atom, wasm_bin: *const Wasm) void { |
| 101 | 101 | if (self.relocs.items.len == 0) return; |
| 102 | 102 | const symbol_name = self.symbolLoc().getName(wasm_bin); |
| 103 | 103 | log.debug("Resolving relocs in atom '{s}' count({d})", .{ |
| ... | ... | @@ -106,7 +106,7 @@ pub fn resolveRelocs(self: *Atom, wasm_bin: *const Wasm) !void { |
| 106 | 106 | }); |
| 107 | 107 | |
| 108 | 108 | for (self.relocs.items) |reloc| { |
| 109 | | const value = try self.relocationValue(reloc, wasm_bin); |
| 109 | const value = self.relocationValue(reloc, wasm_bin); |
| 110 | 110 | log.debug("Relocating '{s}' referenced in '{s}' offset=0x{x:0>8} value={d}", .{ |
| 111 | 111 | (Wasm.SymbolLoc{ .file = self.file, .index = reloc.index }).getName(wasm_bin), |
| 112 | 112 | symbol_name, |
| ... | ... | @@ -144,9 +144,10 @@ pub fn resolveRelocs(self: *Atom, wasm_bin: *const Wasm) !void { |
| 144 | 144 | /// From a given `relocation` will return the new value to be written. |
| 145 | 145 | /// All values will be represented as a `u64` as all values can fit within it. |
| 146 | 146 | /// The final value must be casted to the correct size. |
| 147 | | fn relocationValue(self: Atom, relocation: types.Relocation, wasm_bin: *const Wasm) !u64 { |
| 147 | fn relocationValue(self: Atom, relocation: types.Relocation, wasm_bin: *const Wasm) u64 { |
| 148 | 148 | const target_loc: Wasm.SymbolLoc = .{ .file = self.file, .index = relocation.index }; |
| 149 | 149 | const symbol = target_loc.getSymbol(wasm_bin).*; |
| 150 | |
| 150 | 151 | switch (relocation.relocation_type) { |
| 151 | 152 | .R_WASM_FUNCTION_INDEX_LEB => return symbol.index, |
| 152 | 153 | .R_WASM_TABLE_NUMBER_LEB => return symbol.index, |
| ... | ... | @@ -155,7 +156,13 @@ fn relocationValue(self: Atom, relocation: types.Relocation, wasm_bin: *const Wa |
| 155 | 156 | .R_WASM_TABLE_INDEX_SLEB, |
| 156 | 157 | .R_WASM_TABLE_INDEX_SLEB64, |
| 157 | 158 | => return wasm_bin.function_table.get(target_loc) orelse 0, |
| 158 | | .R_WASM_TYPE_INDEX_LEB => return wasm_bin.functions.values()[symbol.index - wasm_bin.imported_functions_count].type_index, |
| 159 | .R_WASM_TYPE_INDEX_LEB => return blk: { |
| 160 | if (symbol.isUndefined()) { |
| 161 | const imp = wasm_bin.imports.get(target_loc).?; |
| 162 | break :blk imp.kind.function; |
| 163 | } |
| 164 | break :blk wasm_bin.functions.values()[symbol.index - wasm_bin.imported_functions_count].type_index; |
| 165 | }, |
| 159 | 166 | .R_WASM_GLOBAL_INDEX_I32, |
| 160 | 167 | .R_WASM_GLOBAL_INDEX_LEB, |
| 161 | 168 | => return symbol.index, |