aboutsummaryrefslogtreecommitdiff
path: root/src/link/Wasm/Atom.zig
diff options
context:
space:
mode:
authorLuuk de Gram <luuk@degram.dev>2022-12-15 20:28:30 +0100
committerLuuk de Gram <luuk@degram.dev>2022-12-15 20:28:30 +0100
commitae106db8897ce3afd38dbfc1c2c811cd2f2de357 (patch)
treed0aec126cfe1569b2899bbf3fc173c4ee7258244 /src/link/Wasm/Atom.zig
parentf95549ddc71f75f3bf15f54f8d03a1a367d0db37 (diff)
downloadzig-ae106db8897ce3afd38dbfc1c2c811cd2f2de357.tar.gz
zig-ae106db8897ce3afd38dbfc1c2c811cd2f2de357.zip
wasm-linker: Fix debug info relocations
Diffstat (limited to 'src/link/Wasm/Atom.zig')
-rw-r--r--src/link/Wasm/Atom.zig16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/link/Wasm/Atom.zig b/src/link/Wasm/Atom.zig
index 4c1da180bd..4f16a1c2fb 100644
--- a/src/link/Wasm/Atom.zig
+++ b/src/link/Wasm/Atom.zig
@@ -204,18 +204,10 @@ fn relocationValue(atom: Atom, relocation: types.Relocation, wasm_bin: *const Wa
return @intCast(u32, rel_value);
},
.R_WASM_FUNCTION_OFFSET_I32 => {
- const target_atom = wasm_bin.symbol_atom.get(target_loc).?;
- var current_atom = target_atom.getFirst();
- var offset: u32 = 0;
- // TODO: Calculate this during atom allocation, rather than
- // this linear calculation. For now it's done here as atoms
- // are being sorted after atom allocation, as functions aren't
- // merged until later.
- while (true) {
- offset += 5; // each atom uses 5 bytes to store its body's size
- if (current_atom == target_atom) break;
- current_atom = current_atom.next.?;
- }
+ const target_atom = wasm_bin.symbol_atom.get(target_loc) orelse {
+ return @bitCast(u32, @as(i32, -1));
+ };
+ const offset: u32 = 11 + Wasm.getULEB128Size(target_atom.size); // Header (11 bytes fixed-size) + body size (leb-encoded)
const rel_value = @intCast(i32, target_atom.offset + offset) + relocation.addend;
return @intCast(u32, rel_value);
},