diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-12-18 22:11:20 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-01-15 15:11:36 -0800 |
| commit | 4f8a6b0888c8d1df87d254b68344bb99edcfe57c (patch) | |
| tree | 2685575e3ef8de7a9134e8a35a9067a67d8d365c /src/link/Wasm.zig | |
| parent | 5fac6f380ef77a7650047c65450aec0d3215da2d (diff) | |
| download | zig-4f8a6b0888c8d1df87d254b68344bb99edcfe57c.tar.gz zig-4f8a6b0888c8d1df87d254b68344bb99edcfe57c.zip | |
wasm linker: implement data fixups
one hash table lookup per fixup
Diffstat (limited to 'src/link/Wasm.zig')
| -rw-r--r-- | src/link/Wasm.zig | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index e45555432d..acfb694cf2 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -259,13 +259,13 @@ params_scratch: std.ArrayListUnmanaged(std.wasm.Valtype) = .empty, returns_scratch: std.ArrayListUnmanaged(std.wasm.Valtype) = .empty, pub const UavFixup = extern struct { - ip_index: InternPool.Index, + uavs_exe_index: UavsExeIndex, /// Index into `string_bytes`. offset: u32, }; pub const NavFixup = extern struct { - nav_index: InternPool.Nav.Index, + navs_exe_index: NavsExeIndex, /// Index into `string_bytes`. offset: u32, }; @@ -2379,7 +2379,7 @@ pub fn updateNav(wasm: *Wasm, pt: Zcu.PerThread, nav_index: InternPool.Nav.Index const gop = try wasm.navs_exe.getOrPut(gpa, nav_index); gop.value_ptr.* = .{ .code = zcu_data.code, - .count = 0, + .count = if (gop.found_existing) gop.value_ptr.count else 0, }; wasm.data_segments.putAssumeCapacity(.pack(wasm, .{ .nav_exe = @enumFromInt(gop.index) }), {}); } @@ -3376,6 +3376,24 @@ pub fn refUavExe(wasm: *Wasm, pt: Zcu.PerThread, ip_index: InternPool.Index) !Ua return uav_index; } +pub fn refNavExe(wasm: *Wasm, nav_index: InternPool.Nav.Index) !NavsExeIndex { + const comp = wasm.base.comp; + const gpa = comp.gpa; + assert(comp.config.output_mode != .Obj); + const gop = try wasm.navs_exe.getOrPut(gpa, nav_index); + if (gop.found_existing) { + gop.value_ptr.count += 1; + } else { + gop.value_ptr.* = .{ + .code = undefined, + .count = 1, + }; + } + const navs_exe_index: NavsExeIndex = @enumFromInt(gop.index); + try wasm.data_segments.put(gpa, .pack(wasm, .{ .nav_exe = navs_exe_index }), {}); + return navs_exe_index; +} + /// Asserts it is called after `Flush.data_segments` is fully populated and sorted. pub fn uavAddr(wasm: *Wasm, uav_index: UavsExeIndex) u32 { assert(wasm.flush_buffer.memory_layout_finished); |
