| author | |
| committer | |
| log | 85b53730fe248cf02468a213903ddac4bffe8234 |
| tree | 22f04c8edeed5562a6dce6383fdf55c846f69317 |
| parent | 2d899e9a9f0864385939955902e0ba5f322176fc |
3 files changed, 20 insertions(+), 8 deletions(-)
src/arch/wasm/Emit.zig+6-5| ... | ... | @@ -108,7 +108,7 @@ pub fn lowerToCode(emit: *Emit) Error!void { |
| 108 | 108 | inst += 1; |
| 109 | 109 | continue :loop tags[inst]; |
| 110 | 110 | } else { |
| 111 | const addr = try wasm.errorNameTableAddr(); | |
| 111 | const addr: u32 = wasm.errorNameTableAddr(); | |
| 112 | 112 | leb.writeIleb128(code.fixedWriter(), addr) catch unreachable; |
| 113 | 113 | |
| 114 | 114 | inst += 1; |
| ... | ... | @@ -931,7 +931,7 @@ fn uavRefOffExe(wasm: *Wasm, code: *std.ArrayListUnmanaged(u8), data: Mir.UavRef |
| 931 | 931 | try code.ensureUnusedCapacity(gpa, 11); |
| 932 | 932 | code.appendAssumeCapacity(@intFromEnum(opcode)); |
| 933 | 933 | |
| 934 | const addr = try wasm.uavAddr(data.uav_exe); | |
| 934 | const addr = wasm.uavAddr(data.uav_exe); | |
| 935 | 935 | leb.writeUleb128(code.fixedWriter(), @as(u32, @intCast(@as(i64, addr) + data.offset))) catch unreachable; |
| 936 | 936 | } |
| 937 | 937 | |
| ... | ... | @@ -957,8 +957,9 @@ fn navRefOff(wasm: *Wasm, code: *std.ArrayListUnmanaged(u8), data: Mir.NavRefOff |
| 957 | 957 | }); |
| 958 | 958 | code.appendNTimesAssumeCapacity(0, 5); |
| 959 | 959 | } else { |
| 960 | const addr = try wasm.navAddr(data.nav_index); | |
| 961 | leb.writeUleb128(code.fixedWriter(), @as(u32, @intCast(@as(i64, addr) + data.offset))) catch unreachable; | |
| 960 | const function_imports_len: u32 = @intCast(wasm.function_imports.entries.len); | |
| 961 | const func_index = Wasm.FunctionIndex.fromIpNav(wasm, data.nav_index).?; | |
| 962 | leb.writeUleb128(code.fixedWriter(), function_imports_len + @intFromEnum(func_index)) catch unreachable; | |
| 962 | 963 | } |
| 963 | 964 | } else { |
| 964 | 965 | const opcode: std.wasm.Opcode = if (is_wasm32) .i32_const else .i64_const; |
| ... | ... | @@ -972,7 +973,7 @@ fn navRefOff(wasm: *Wasm, code: *std.ArrayListUnmanaged(u8), data: Mir.NavRefOff |
| 972 | 973 | }); |
| 973 | 974 | code.appendNTimesAssumeCapacity(0, if (is_wasm32) 5 else 10); |
| 974 | 975 | } else { |
| 975 | const addr = try wasm.navAddr(data.nav_index); | |
| 976 | const addr = wasm.navAddr(data.nav_index); | |
| 976 | 977 | leb.writeUleb128(code.fixedWriter(), @as(u32, @intCast(@as(i64, addr) + data.offset))) catch unreachable; |
| 977 | 978 | } |
| 978 | 979 | } |
src/link/Wasm.zig+9-3| ... | ... | @@ -3331,21 +3331,27 @@ pub fn refUavExe(wasm: *Wasm, pt: Zcu.PerThread, ip_index: InternPool.Index) !Ua |
| 3331 | 3331 | return uav_index; |
| 3332 | 3332 | } |
| 3333 | 3333 | |
| 3334 | pub fn uavAddr(wasm: *Wasm, uav_index: UavsExeIndex) Allocator.Error!u32 { | |
| 3334 | /// Asserts it is called after `Wasm.data_segments` is fully populated and sorted. | |
| 3335 | pub fn uavAddr(wasm: *Wasm, uav_index: UavsExeIndex) u32 { | |
| 3336 | assert(wasm.flush_buffer.memory_layout_finished); | |
| 3335 | 3337 | const comp = wasm.base.comp; |
| 3336 | 3338 | assert(comp.config.output_mode != .Obj); |
| 3337 | 3339 | const ds_id: DataSegment.Id = .pack(wasm, .{ .uav_exe = uav_index }); |
| 3338 | 3340 | return wasm.data_segments.get(ds_id).?; |
| 3339 | 3341 | } |
| 3340 | 3342 | |
| 3341 | pub fn navAddr(wasm: *Wasm, nav_index: InternPool.Nav.Index) Allocator.Error!u32 { | |
| 3343 | /// Asserts it is called after `Wasm.data_segments` is fully populated and sorted. | |
| 3344 | pub fn navAddr(wasm: *Wasm, nav_index: InternPool.Nav.Index) u32 { | |
| 3345 | assert(wasm.flush_buffer.memory_layout_finished); | |
| 3342 | 3346 | const comp = wasm.base.comp; |
| 3343 | 3347 | assert(comp.config.output_mode != .Obj); |
| 3344 | 3348 | const ds_id: DataSegment.Id = .pack(wasm, .{ .nav_exe = @enumFromInt(wasm.navs_exe.getIndex(nav_index).?) }); |
| 3345 | 3349 | return wasm.data_segments.get(ds_id).?; |
| 3346 | 3350 | } |
| 3347 | 3351 | |
| 3348 | pub fn errorNameTableAddr(wasm: *Wasm) Allocator.Error!u32 { | |
| 3352 | /// Asserts it is called after `Wasm.data_segments` is fully populated and sorted. | |
| 3353 | pub fn errorNameTableAddr(wasm: *Wasm) u32 { | |
| 3354 | assert(wasm.flush_buffer.memory_layout_finished); | |
| 3349 | 3355 | const comp = wasm.base.comp; |
| 3350 | 3356 | assert(comp.config.output_mode != .Obj); |
| 3351 | 3357 | return wasm.data_segments.get(.__zig_error_name_table).?; |
src/link/Wasm/Flush.zig+5| ... | ... | @@ -28,10 +28,14 @@ missing_exports: std.AutoArrayHashMapUnmanaged(String, void) = .empty, |
| 28 | 28 | |
| 29 | 29 | indirect_function_table: std.AutoArrayHashMapUnmanaged(Wasm.OutputFunctionIndex, u32) = .empty, |
| 30 | 30 | |
| 31 | /// For debug purposes only. | |
| 32 | memory_layout_finished: bool = false, | |
| 33 | ||
| 31 | 34 | pub fn clear(f: *Flush) void { |
| 32 | 35 | f.binary_bytes.clearRetainingCapacity(); |
| 33 | 36 | f.data_segment_groups.clearRetainingCapacity(); |
| 34 | 37 | f.indirect_function_table.clearRetainingCapacity(); |
| 38 | f.memory_layout_finished = false; | |
| 35 | 39 | } |
| 36 | 40 | |
| 37 | 41 | pub fn deinit(f: *Flush, gpa: Allocator) void { |
| ... | ... | @@ -348,6 +352,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { |
| 348 | 352 | if (shared_memory) wasm.memories.limits.flags.is_shared = true; |
| 349 | 353 | log.debug("maximum memory pages: {?d}", .{wasm.memories.limits.max}); |
| 350 | 354 | } |
| 355 | f.memory_layout_finished = true; | |
| 351 | 356 | |
| 352 | 357 | var section_index: u32 = 0; |
| 353 | 358 | // Index of the code section. Used to tell relocation table where the section lives. |