authorgravatar for timonkruiper@gmail.comTimon Kruiper <timonkruiper@gmail.com> 2020-10-06 12:08:12+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-10-06 23:39:58-07:00
logbd7eab573a5e5f1366cd5dc3639fef28c4acb32a
treef1f6a4363781197db451e072ea7650595032bc6c
parentfb63a2cfaecb981010e0b9d656fd372dbb331888

Fix building the zig compiler for 32-bit targets


5 files changed, 17 insertions(+), 16 deletions(-)

lib/std/fs/file.zig+11-10
...@@ -615,7 +615,7 @@ pub const File = struct {...@@ -615,7 +615,7 @@ pub const File = struct {
615 }615 }
616 }616 }
617617
618 pub fn pwritev(self: File, iovecs: []os.iovec_const, offset: usize) PWriteError!usize {618 pub fn pwritev(self: File, iovecs: []os.iovec_const, offset: u64) PWriteError!usize {
619 if (is_windows) {619 if (is_windows) {
620 // TODO improve this to use WriteFileScatter620 // TODO improve this to use WriteFileScatter
621 if (iovecs.len == 0) return @as(usize, 0);621 if (iovecs.len == 0) return @as(usize, 0);
...@@ -632,11 +632,11 @@ pub const File = struct {...@@ -632,11 +632,11 @@ pub const File = struct {
632632
633 /// The `iovecs` parameter is mutable because this function needs to mutate the fields in633 /// The `iovecs` parameter is mutable because this function needs to mutate the fields in
634 /// order to handle partial writes from the underlying OS layer.634 /// order to handle partial writes from the underlying OS layer.
635 pub fn pwritevAll(self: File, iovecs: []os.iovec_const, offset: usize) PWriteError!void {635 pub fn pwritevAll(self: File, iovecs: []os.iovec_const, offset: u64) PWriteError!void {
636 if (iovecs.len == 0) return;636 if (iovecs.len == 0) return;
637637
638 var i: usize = 0;638 var i: usize = 0;
639 var off: usize = 0;639 var off: u64 = 0;
640 while (true) {640 while (true) {
641 var amt = try self.pwritev(iovecs[i..], offset + off);641 var amt = try self.pwritev(iovecs[i..], offset + off);
642 off += amt;642 off += amt;
...@@ -652,24 +652,25 @@ pub const File = struct {...@@ -652,24 +652,25 @@ pub const File = struct {
652652
653 pub const CopyRangeError = os.CopyFileRangeError;653 pub const CopyRangeError = os.CopyFileRangeError;
654654
655 pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: usize) CopyRangeError!usize {655 pub fn copyRange(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!usize {
656 return os.copy_file_range(in.handle, in_offset, out.handle, out_offset, len, 0);656 const adjusted_len = math.cast(usize, len) catch math.maxInt(usize);
657 return os.copy_file_range(in.handle, in_offset, out.handle, out_offset, adjusted_len, 0);
657 }658 }
658659
659 /// Returns the number of bytes copied. If the number read is smaller than `buffer.len`, it660 /// Returns the number of bytes copied. If the number read is smaller than `buffer.len`, it
660 /// means the in file reached the end. Reaching the end of a file is not an error condition.661 /// means the in file reached the end. Reaching the end of a file is not an error condition.
661 pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: usize) CopyRangeError!usize {662 pub fn copyRangeAll(in: File, in_offset: u64, out: File, out_offset: u64, len: u64) CopyRangeError!usize {
662 var total_bytes_copied: usize = 0;663 var total_bytes_copied: u64 = 0;
663 var in_off = in_offset;664 var in_off = in_offset;
664 var out_off = out_offset;665 var out_off = out_offset;
665 while (total_bytes_copied < len) {666 while (total_bytes_copied < len) {
666 const amt_copied = try copyRange(in, in_off, out, out_off, len - total_bytes_copied);667 const amt_copied = try copyRange(in, in_off, out, out_off, len);
667 if (amt_copied == 0) return total_bytes_copied;668 if (amt_copied == 0) return @intCast(usize, total_bytes_copied);
668 total_bytes_copied += amt_copied;669 total_bytes_copied += amt_copied;
669 in_off += amt_copied;670 in_off += amt_copied;
670 out_off += amt_copied;671 out_off += amt_copied;
671 }672 }
672 return total_bytes_copied;673 return @intCast(usize, total_bytes_copied);
673 }674 }
674675
675 pub const WriteFileOptions = struct {676 pub const WriteFileOptions = struct {
src/link/Elf.zig+2-2
...@@ -2757,7 +2757,7 @@ fn writeSymbol(self: *Elf, index: usize) !void {...@@ -2757,7 +2757,7 @@ fn writeSymbol(self: *Elf, index: usize) !void {
2757 if (needed_size > self.allocatedSize(syms_sect.sh_offset)) {2757 if (needed_size > self.allocatedSize(syms_sect.sh_offset)) {
2758 // Move all the symbols to a new file location.2758 // Move all the symbols to a new file location.
2759 const new_offset = self.findFreeSpace(needed_size, sym_align);2759 const new_offset = self.findFreeSpace(needed_size, sym_align);
2760 const existing_size = @as(u64, syms_sect.sh_info) * sym_size;2760 const existing_size = syms_sect.sh_info * sym_size;
2761 const amt = try self.base.file.?.copyRangeAll(syms_sect.sh_offset, self.base.file.?, new_offset, existing_size);2761 const amt = try self.base.file.?.copyRangeAll(syms_sect.sh_offset, self.base.file.?, new_offset, existing_size);
2762 if (amt != existing_size) return error.InputOutput;2762 if (amt != existing_size) return error.InputOutput;
2763 syms_sect.sh_offset = new_offset;2763 syms_sect.sh_offset = new_offset;
...@@ -2911,7 +2911,7 @@ fn pwriteDbgLineNops(...@@ -2911,7 +2911,7 @@ fn pwriteDbgLineNops(
2911 prev_padding_size: usize,2911 prev_padding_size: usize,
2912 buf: []const u8,2912 buf: []const u8,
2913 next_padding_size: usize,2913 next_padding_size: usize,
2914 offset: usize,2914 offset: u64,
2915) !void {2915) !void {
2916 const tracy = trace(@src());2916 const tracy = trace(@src());
2917 defer tracy.end();2917 defer tracy.end();
src/link/MachO.zig+1-1
...@@ -1267,7 +1267,7 @@ fn updateString(self: *MachO, old_str_off: u32, new_name: []const u8) !u32 {...@@ -1267,7 +1267,7 @@ fn updateString(self: *MachO, old_str_off: u32, new_name: []const u8) !u32 {
1267fn addPadding(self: *MachO, size: u64, file_offset: u64) !void {1267fn addPadding(self: *MachO, size: u64, file_offset: u64) !void {
1268 if (size == 0) return;1268 if (size == 0) return;
12691269
1270 const buf = try self.base.allocator.alloc(u8, size);1270 const buf = try self.base.allocator.alloc(u8, @intCast(usize, size));
1271 defer self.base.allocator.free(buf);1271 defer self.base.allocator.free(buf);
12721272
1273 mem.set(u8, buf[0..], 0);1273 mem.set(u8, buf[0..], 0);
src/main.zig+2-2
...@@ -2541,7 +2541,7 @@ fn fmtPathFile(...@@ -2541,7 +2541,7 @@ fn fmtPathFile(
2541 check_mode: bool,2541 check_mode: bool,
2542 dir: fs.Dir,2542 dir: fs.Dir,
2543 sub_path: []const u8,2543 sub_path: []const u8,
2544) FmtError!void {2544) (FmtError || error{Overflow})!void {
2545 const source_file = try dir.openFile(sub_path, .{});2545 const source_file = try dir.openFile(sub_path, .{});
2546 var file_closed = false;2546 var file_closed = false;
2547 errdefer if (!file_closed) source_file.close();2547 errdefer if (!file_closed) source_file.close();
...@@ -2554,7 +2554,7 @@ fn fmtPathFile(...@@ -2554,7 +2554,7 @@ fn fmtPathFile(
2554 const source_code = source_file.readToEndAllocOptions(2554 const source_code = source_file.readToEndAllocOptions(
2555 fmt.gpa,2555 fmt.gpa,
2556 max_src_size,2556 max_src_size,
2557 stat.size,2557 try std.math.cast(usize, stat.size),
2558 @alignOf(u8),2558 @alignOf(u8),
2559 null,2559 null,
2560 ) catch |err| switch (err) {2560 ) catch |err| switch (err) {
src/value.zig+1-1
...@@ -842,7 +842,7 @@ pub const Value = extern union {...@@ -842,7 +842,7 @@ pub const Value = extern union {
842 .int_u64 => {842 .int_u64 => {
843 const x = self.cast(Payload.Int_u64).?.int;843 const x = self.cast(Payload.Int_u64).?.int;
844 if (x == 0) return 0;844 if (x == 0) return 0;
845 return std.math.log2(x) + 1;845 return @intCast(usize, std.math.log2(x) + 1);
846 },846 },
847 .int_i64 => {847 .int_i64 => {
848 @panic("TODO implement i64 intBitCountTwosComp");848 @panic("TODO implement i64 intBitCountTwosComp");