| ... | @@ -204,18 +204,10 @@ fn relocationValue(atom: Atom, relocation: types.Relocation, wasm_bin: *const Wa | ... | @@ -204,18 +204,10 @@ fn relocationValue(atom: Atom, relocation: types.Relocation, wasm_bin: *const Wa |
| 204 | return @intCast(u32, rel_value); | 204 | return @intCast(u32, rel_value); |
| 205 | }, | 205 | }, |
| 206 | .R_WASM_FUNCTION_OFFSET_I32 => { | 206 | .R_WASM_FUNCTION_OFFSET_I32 => { |
| 207 | const target_atom = wasm_bin.symbol_atom.get(target_loc).?; | 207 | const target_atom = wasm_bin.symbol_atom.get(target_loc) orelse { |
| 208 | var current_atom = target_atom.getFirst(); | 208 | return @bitCast(u32, @as(i32, -1)); |
| 209 | var offset: u32 = 0; | 209 | }; |
| 210 | // TODO: Calculate this during atom allocation, rather than | 210 | const offset: u32 = 11 + Wasm.getULEB128Size(target_atom.size); // Header (11 bytes fixed-size) + body size (leb-encoded) |
| 211 | // this linear calculation. For now it's done here as atoms | | |
| 212 | // are being sorted after atom allocation, as functions aren't | | |
| 213 | // merged until later. | | |
| 214 | while (true) { | | |
| 215 | offset += 5; // each atom uses 5 bytes to store its body's size | | |
| 216 | if (current_atom == target_atom) break; | | |
| 217 | current_atom = current_atom.next.?; | | |
| 218 | } | | |
| 219 | const rel_value = @intCast(i32, target_atom.offset + offset) + relocation.addend; | 211 | const rel_value = @intCast(i32, target_atom.offset + offset) + relocation.addend; |
| 220 | return @intCast(u32, rel_value); | 212 | return @intCast(u32, rel_value); |
| 221 | }, | 213 | }, |