diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-12-18 20:34:58 -0800 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-01-15 15:11:36 -0800 |
| commit | 5fac6f380ef77a7650047c65450aec0d3215da2d (patch) | |
| tree | c8d24c03a454954c5e9f526df7b16bcfa1f10fbc /src | |
| parent | 568d9936ab4401e53a96bb2b51d31d10861c5545 (diff) | |
| download | zig-5fac6f380ef77a7650047c65450aec0d3215da2d.tar.gz zig-5fac6f380ef77a7650047c65450aec0d3215da2d.zip | |
wasm linker: fix eliding empty data segments
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Wasm.zig | 8 | ||||
| -rw-r--r-- | src/link/Wasm/Flush.zig | 2 |
2 files changed, 9 insertions, 1 deletions
diff --git a/src/link/Wasm.zig b/src/link/Wasm.zig index 36849cda18..e45555432d 100644 --- a/src/link/Wasm.zig +++ b/src/link/Wasm.zig @@ -1410,6 +1410,14 @@ pub const DataSegment = extern struct { }; } + pub fn isEmpty(id: Id, wasm: *const Wasm) bool { + return switch (unpack(id, wasm)) { + .__zig_error_name_table => false, + .object => |i| i.ptr(wasm).payload.off == .none, + inline .uav_exe, .uav_obj, .nav_exe, .nav_obj => |i| i.value(wasm).code.off == .none, + }; + } + pub fn size(id: Id, wasm: *const Wasm) u32 { return switch (unpack(id, wasm)) { .__zig_error_name_table => { diff --git a/src/link/Wasm/Flush.zig b/src/link/Wasm/Flush.zig index 41f866178d..8da9d78a59 100644 --- a/src/link/Wasm/Flush.zig +++ b/src/link/Wasm/Flush.zig @@ -657,7 +657,7 @@ pub fn finish(f: *Flush, wasm: *Wasm) !void { var group_index: u32 = 0; var offset: u32 = undefined; for (segment_ids, segment_offsets) |segment_id, segment_offset| { - if (!import_memory and segment_id.isBss(wasm)) { + if (segment_id.isEmpty(wasm)) { // It counted for virtual memory but it does not go into the binary. continue; } |
