-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
base: master
Are you sure you want to change the base?
spirv: fix null file handle crash & improve flush err handling #24296
Conversation
Add makeWritable() call before writeAll() in SPIR-V linker flush function. SPIR-V linker was trying to write to uninitialized file handle. - Add .spirv case to makeWritable() switch in link.zig - Call makeWritable() with proper error handling in SpirV.zig - OutOfMemory propagates up, other errors become LinkFailure Fixes ziglang#23883
cc @alichraghi |
Add makeWritable() call before file operations to ensure file handle is initialized. Implement ELF/COFF delegation pattern with flushInner() for consistent error handling and architectural parity with other major linkers. Prevents crash when SPIR-V linker attempts to write to uninitialized file.
@alichraghi if you got time, mind looking at this? |
return flushInner(self, arena, tid, sub_prog_node) catch |err| switch (err) { | ||
error.OutOfMemory => return error.OutOfMemory, | ||
error.LinkFailure => return error.LinkFailure, | ||
else => |e| return diags.fail("SPIR-V flush failed: {s}", .{@errorName(e)}), | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just return LinkFailure
for every other error:
return flushInner(self, arena, tid, sub_prog_node) catch |err| switch (err) {
error.OutOfMemory => return error.OutOfMemory,
- error.LinkFailure => return error.LinkFailure,
- else => |e| return diags.fail("SPIR-V flush failed: {s}", .{@errorName(e)}),
+ else => return error.LinkFailure,
};
try self.pwriteAll(std.mem.sliceAsBytes(linked_module), 0); | ||
try self.setEndPos(linked_module.len * @sizeOf(Word)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't abstract them into mini functions. just use try
:
- try self.pwriteAll(std.mem.sliceAsBytes(linked_module), 0);
- try self.setEndPos(linked_module.len * @sizeOf(Word));
+ try self.base.file.?.pwriteAll(std.mem.sliceAsBytes(linked_module), 0);
+ try self.base.file.?.setEndPos(linked_module.len * @sizeOf(Word));
Add makeWritable() call before writeAll() in SPIR-V linker flush function.
SPIR-V linker was trying to write to uninitialized file handle.
Changes:
Testing:
zig build-obj shader.zig -target spirv64-vulkan
Fixes #23883