| ... | @@ -842,10 +842,10 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { | ... | @@ -842,10 +842,10 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { |
| 842 | group_end_addr = f.data_segment_groups.items[group_index].end_addr; | 842 | group_end_addr = f.data_segment_groups.items[group_index].end_addr; |
| 843 | segment_offset = 0; | 843 | segment_offset = 0; |
| 844 | } | 844 | } |
| | 845 | const flags: Object.DataSegmentFlags = if (segment_id.isPassive(wasm)) .passive else .active; |
| 845 | if (segment_offset == 0) { | 846 | if (segment_offset == 0) { |
| 846 | const group_size = group_end_addr - group_start_addr; | 847 | const group_size = group_end_addr - group_start_addr; |
| 847 | log.debug("emit data section group, {d} bytes", .{group_size}); | 848 | log.debug("emit data section group, {d} bytes", .{group_size}); |
| 848 | const flags: Object.DataSegmentFlags = if (segment_id.isPassive(wasm)) .passive else .active; | | |
| 849 | try leb.writeUleb128(binary_writer, @intFromEnum(flags)); | 849 | try leb.writeUleb128(binary_writer, @intFromEnum(flags)); |
| 850 | // Passive segments are initialized at runtime. | 850 | // Passive segments are initialized at runtime. |
| 851 | if (flags != .passive) { | 851 | if (flags != .passive) { |
| ... | @@ -853,7 +853,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { | ... | @@ -853,7 +853,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { |
| 853 | } | 853 | } |
| 854 | try leb.writeUleb128(binary_writer, group_size); | 854 | try leb.writeUleb128(binary_writer, group_size); |
| 855 | } | 855 | } |
| 856 | if (segment_id.isEmpty(wasm)) { | 856 | if (flags == .passive or segment_id.isEmpty(wasm)) { |
| 857 | // It counted for virtual memory but it does not go into the binary. | 857 | // It counted for virtual memory but it does not go into the binary. |
| 858 | continue; | 858 | continue; |
| 859 | } | 859 | } |
| ... | @@ -933,7 +933,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { | ... | @@ -933,7 +933,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { |
| 933 | // try wasm.emitDataRelocations(binary_bytes, data_index, symbol_table); | 933 | // try wasm.emitDataRelocations(binary_bytes, data_index, symbol_table); |
| 934 | //} | 934 | //} |
| 935 | } else if (comp.config.debug_format != .strip) { | 935 | } else if (comp.config.debug_format != .strip) { |
| 936 | try emitNameSection(wasm, &f.data_segments, binary_bytes); | 936 | try emitNameSection(wasm, f.data_segment_groups.items, binary_bytes); |
| 937 | } | 937 | } |
| 938 | | 938 | |
| 939 | if (comp.config.debug_format != .strip) { | 939 | if (comp.config.debug_format != .strip) { |
| ... | @@ -992,7 +992,7 @@ const VirtualAddrs = struct { | ... | @@ -992,7 +992,7 @@ const VirtualAddrs = struct { |
| 992 | | 992 | |
| 993 | fn emitNameSection( | 993 | fn emitNameSection( |
| 994 | wasm: *Wasm, | 994 | wasm: *Wasm, |
| 995 | data_segments: *const std.AutoArrayHashMapUnmanaged(Wasm.DataSegmentId, u32), | 995 | data_segment_groups: []const DataSegmentGroup, |
| 996 | binary_bytes: *std.ArrayListUnmanaged(u8), | 996 | binary_bytes: *std.ArrayListUnmanaged(u8), |
| 997 | ) !void { | 997 | ) !void { |
| 998 | const f = &wasm.flush_buffer; | 998 | const f = &wasm.flush_buffer; |
| ... | @@ -1052,11 +1052,11 @@ fn emitNameSection( | ... | @@ -1052,11 +1052,11 @@ fn emitNameSection( |
| 1052 | const sub_offset = try reserveCustomSectionHeader(gpa, binary_bytes); | 1052 | const sub_offset = try reserveCustomSectionHeader(gpa, binary_bytes); |
| 1053 | defer replaceHeader(binary_bytes, sub_offset, @intFromEnum(std.wasm.NameSubsection.data_segment)); | 1053 | defer replaceHeader(binary_bytes, sub_offset, @intFromEnum(std.wasm.NameSubsection.data_segment)); |
| 1054 | | 1054 | |
| 1055 | const total_globals: u32 = @intCast(f.global_imports.entries.len + wasm.globals.entries.len); | 1055 | const total_data_segments: u32 = @intCast(data_segment_groups.len); |
| 1056 | try leb.writeUleb128(binary_bytes.writer(gpa), total_globals); | 1056 | try leb.writeUleb128(binary_bytes.writer(gpa), total_data_segments); |
| 1057 | | 1057 | |
| 1058 | for (data_segments.keys(), 0..) |ds, i| { | 1058 | for (data_segment_groups, 0..) |group, i| { |
| 1059 | const name = ds.name(wasm); | 1059 | const name = group.first_segment.name(wasm); |
| 1060 | try leb.writeUleb128(binary_bytes.writer(gpa), @as(u32, @intCast(i))); | 1060 | try leb.writeUleb128(binary_bytes.writer(gpa), @as(u32, @intCast(i))); |
| 1061 | try leb.writeUleb128(binary_bytes.writer(gpa), @as(u32, @intCast(name.len))); | 1061 | try leb.writeUleb128(binary_bytes.writer(gpa), @as(u32, @intCast(name.len))); |
| 1062 | try binary_bytes.appendSlice(gpa, name); | 1062 | try binary_bytes.appendSlice(gpa, name); |