authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-12-15 20:35:07-08:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2025-01-15 15:11:35-08:00
log0555fe8d5b026c8544c62acde83e9d3b1f6c01b8
tree14d16d7d4c640ffe66aefaed4a288939fe59e957
parentd6b42e585be2bfb17d959908731b02e9e97f5fd9

fix replaceVecSectionHeader


1 files changed, 4 insertions(+), 9 deletions(-)

src/link/Wasm/Flush.zig+4-9
...@@ -1038,7 +1038,7 @@ fn replaceVecSectionHeader(...@@ -1038,7 +1038,7 @@ fn replaceVecSectionHeader(
1038 section: std.wasm.Section,1038 section: std.wasm.Section,
1039 n_items: u32,1039 n_items: u32,
1040) void {1040) void {
1041 const size: u32 = @intCast(bytes.items.len - offset - section_header_size);1041 const size: u32 = @intCast(bytes.items.len - offset - section_header_reserve_size + uleb128size(n_items));
1042 var buf: [section_header_reserve_size]u8 = undefined;1042 var buf: [section_header_reserve_size]u8 = undefined;
1043 var fbw = std.io.fixedBufferStream(&buf);1043 var fbw = std.io.fixedBufferStream(&buf);
1044 const w = fbw.writer();1044 const w = fbw.writer();
...@@ -1395,14 +1395,9 @@ fn emitSegmentInfo(wasm: *Wasm, binary_bytes: *std.ArrayList(u8)) !void {...@@ -1395,14 +1395,9 @@ fn emitSegmentInfo(wasm: *Wasm, binary_bytes: *std.ArrayList(u8)) !void {
1395// }1395// }
1396//}1396//}
13971397
1398fn getUleb128Size(uint_value: anytype) u32 {1398fn uleb128size(x: u32) u32 {
1399 const T = @TypeOf(uint_value);1399 var value = x;
1400 const U = if (@typeInfo(T).int.bits < 8) u8 else T;
1401 var value = @as(U, @intCast(uint_value));
1402
1403 var size: u32 = 0;1400 var size: u32 = 0;
1404 while (value != 0) : (size += 1) {1401 while (value != 0) : (size += 1) value >>= 7;
1405 value >>= 7;
1406 }
1407 return size;1402 return size;
1408}1403}