wasm linker: fix eliding empty data segments

This commit is contained in:
Andrew Kelley 2024-12-18 20:34:58 -08:00
parent 568d9936ab
commit 5fac6f380e
2 changed files with 9 additions and 1 deletions

View File

@ -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 => {

View File

@ -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;
}