Skip to content

spirv: fix null file handle crash & improve flush err handling #24296

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/link.zig
Original file line number Diff line number Diff line change
Expand Up @@ -608,8 +608,15 @@ pub const File = struct {
.mode = determineMode(output_mode, link_mode),
});
},
.c, .spirv => dev.checkAny(&.{ .c_linker, .spirv_linker }),
}
.spirv => {
if (base.file != null) return;
dev.check(.spirv_linker);
const emit = base.emit;
base.file = try emit.root_dir.handle.createFile(emit.sub_path, .{
.truncate = true,
});
},
.c => dev.check(.c_linker),
}

/// Some linkers create a separate file for debug info, which we might need to temporarily close
Expand Down
5 changes: 5 additions & 0 deletions src/link/SpirV.zig
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ pub fn flush(
else => |other| return diags.fail("error while linking: {s}", .{@errorName(other)}),
};

self.base.makeWritable() catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
else => return error.LinkFailure,
};

self.base.file.?.writeAll(std.mem.sliceAsBytes(linked_module)) catch |err|
return diags.fail("failed to write: {s}", .{@errorName(err)});
}
Expand Down
Loading