| ... | ... | @@ -8,6 +8,7 @@ |
| 8 | 8 | const Module = @This(); |
| 9 | 9 | |
| 10 | 10 | const std = @import("std"); |
| 11 | const builtin = @import("builtin"); |
| 11 | 12 | const Allocator = std.mem.Allocator; |
| 12 | 13 | const assert = std.debug.assert; |
| 13 | 14 | |
| ... | ... | @@ -471,19 +472,26 @@ pub fn flush(self: *Module, file: std.fs.File, target: std.Target) !void { |
| 471 | 472 | self.sections.functions.toWords(), |
| 472 | 473 | }; |
| 473 | 474 | |
| 474 | | var iovc_buffers: [buffers.len]std.os.iovec_const = undefined; |
| 475 | | var file_size: u64 = 0; |
| 476 | | for (&iovc_buffers, 0..) |*iovc, i| { |
| 477 | | // Note, since spir-v supports both little and big endian we can ignore byte order here and |
| 478 | | // just treat the words as a sequence of bytes. |
| 479 | | const bytes = std.mem.sliceAsBytes(buffers[i]); |
| 480 | | iovc.* = .{ .iov_base = bytes.ptr, .iov_len = bytes.len }; |
| 481 | | file_size += bytes.len; |
| 482 | | } |
| 475 | if (builtin.zig_backend == .stage2_x86_64) { |
| 476 | for (buffers) |buf| { |
| 477 | try file.writeAll(std.mem.sliceAsBytes(buf)); |
| 478 | } |
| 479 | } else { |
| 480 | // miscompiles with x86_64 backend |
| 481 | var iovc_buffers: [buffers.len]std.os.iovec_const = undefined; |
| 482 | var file_size: u64 = 0; |
| 483 | for (&iovc_buffers, 0..) |*iovc, i| { |
| 484 | // Note, since spir-v supports both little and big endian we can ignore byte order here and |
| 485 | // just treat the words as a sequence of bytes. |
| 486 | const bytes = std.mem.sliceAsBytes(buffers[i]); |
| 487 | iovc.* = .{ .iov_base = bytes.ptr, .iov_len = bytes.len }; |
| 488 | file_size += bytes.len; |
| 489 | } |
| 483 | 490 | |
| 484 | | try file.seekTo(0); |
| 485 | | try file.setEndPos(file_size); |
| 486 | | try file.pwritevAll(&iovc_buffers, 0); |
| 491 | try file.seekTo(0); |
| 492 | try file.setEndPos(file_size); |
| 493 | try file.pwritevAll(&iovc_buffers, 0); |
| 494 | } |
| 487 | 495 | } |
| 488 | 496 | |
| 489 | 497 | /// Merge the sections making up a function declaration into this module. |