authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-01-01 21:28:52+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2021-01-01 21:28:52+01:00
log5dfeb6cbc89d64f2a44eece41918e1c391c7c989
tree65b5a182a9f8819635f38e401d81fde82cb19e77
parent1cef0be01b80b087492c652b18304ec1946a81e6
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

macho: unblock stage2 on 32bit platforms (#7632)

* macho: unblock stage2 on 32bit platforms Unblocks compilation of stage2 on 32bit platforms, and fixes #7630. * Use libstd convention: reads - usize, writes - u64

5 files changed, 20 insertions(+), 21 deletions(-)

src/link/MachO.zig+8-8
......@@ -907,7 +907,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
907907 const size = try self.binding_info_table.calcSize();
908908 assert(dyld_info.bind_size >= size);
909909
910 var buffer = try self.base.allocator.alloc(u8, size);
910 var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
911911 defer self.base.allocator.free(buffer);
912912
913913 var stream = std.io.fixedBufferStream(buffer);
......@@ -919,7 +919,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
919919 const size = try self.lazy_binding_info_table.calcSize();
920920 assert(dyld_info.lazy_bind_size >= size);
921921
922 var buffer = try self.base.allocator.alloc(u8, size);
922 var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
923923 defer self.base.allocator.free(buffer);
924924
925925 var stream = std.io.fixedBufferStream(buffer);
......@@ -1875,13 +1875,13 @@ pub fn makeStaticString(comptime bytes: []const u8) [16]u8 {
18751875
18761876fn makeString(self: *MachO, bytes: []const u8) !u32 {
18771877 try self.string_table.ensureCapacity(self.base.allocator, self.string_table.items.len + bytes.len + 1);
1878 const result = self.string_table.items.len;
1878 const result = @intCast(u32, self.string_table.items.len);
18791879 self.string_table.appendSliceAssumeCapacity(bytes);
18801880 self.string_table.appendAssumeCapacity(0);
18811881 self.string_table_dirty = true;
18821882 if (self.d_sym) |*ds|
18831883 ds.string_table_dirty = true;
1884 return @intCast(u32, result);
1884 return result;
18851885}
18861886
18871887fn getString(self: *MachO, str_off: u32) []const u8 {
......@@ -2245,7 +2245,7 @@ fn writeExportTrie(self: *MachO) !void {
22452245 }
22462246
22472247 try trie.finalize();
2248 var buffer = try self.base.allocator.alloc(u8, trie.size);
2248 var buffer = try self.base.allocator.alloc(u8, @intCast(usize, trie.size));
22492249 defer self.base.allocator.free(buffer);
22502250 var stream = std.io.fixedBufferStream(buffer);
22512251 const nwritten = try trie.write(stream.writer());
......@@ -2275,7 +2275,7 @@ fn writeBindingInfoTable(self: *MachO) !void {
22752275 defer tracy.end();
22762276
22772277 const size = try self.binding_info_table.calcSize();
2278 var buffer = try self.base.allocator.alloc(u8, size);
2278 var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
22792279 defer self.base.allocator.free(buffer);
22802280
22812281 var stream = std.io.fixedBufferStream(buffer);
......@@ -2303,7 +2303,7 @@ fn writeLazyBindingInfoTable(self: *MachO) !void {
23032303 if (!self.lazy_binding_info_dirty) return;
23042304
23052305 const size = try self.lazy_binding_info_table.calcSize();
2306 var buffer = try self.base.allocator.alloc(u8, size);
2306 var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
23072307 defer self.base.allocator.free(buffer);
23082308
23092309 var stream = std.io.fixedBufferStream(buffer);
......@@ -2400,7 +2400,7 @@ fn updateLinkeditSegmentSizes(self: *MachO) !void {
24002400fn writeLoadCommands(self: *MachO) !void {
24012401 if (!self.load_commands_dirty) return;
24022402
2403 var sizeofcmds: usize = 0;
2403 var sizeofcmds: u32 = 0;
24042404 for (self.load_commands.items) |lc| {
24052405 sizeofcmds += lc.cmdsize();
24062406 }
src/link/MachO/CodeSignature.zig+1-1
......@@ -84,7 +84,7 @@ pub fn calcAdhocSignature(
8484 .identOffset = 0,
8585 .nSpecialSlots = 0,
8686 .nCodeSlots = 0,
87 .codeLimit = @intCast(u32, file_size),
87 .codeLimit = file_size,
8888 .hashSize = hash_size,
8989 .hashType = macho.CS_HASHTYPE_SHA256,
9090 .platform = 0,
src/link/MachO/DebugSymbols.zig+1-1
......@@ -747,7 +747,7 @@ fn updateDwarfSegment(self: *DebugSymbols) void {
747747fn writeLoadCommands(self: *DebugSymbols, allocator: *Allocator) !void {
748748 if (!self.load_commands_dirty) return;
749749
750 var sizeofcmds: usize = 0;
750 var sizeofcmds: u32 = 0;
751751 for (self.load_commands.items) |lc| {
752752 sizeofcmds += lc.cmdsize();
753753 }
src/link/MachO/Trie.zig+6-7
......@@ -52,7 +52,7 @@ pub const Node = struct {
5252 } = null,
5353
5454 /// Offset of this node in the trie output byte stream.
55 trie_offset: ?usize = null,
55 trie_offset: ?u64 = null,
5656
5757 /// List of all edges originating from this node.
5858 edges: std.ArrayListUnmanaged(Edge) = .{},
......@@ -199,7 +199,6 @@ pub const Node = struct {
199199 assert(!self.node_dirty);
200200 if (self.terminal_info) |info| {
201201 // Terminal node info: encode export flags and vmaddr offset of this symbol.
202 var info_buf_len: usize = 0;
203202 var info_buf: [@sizeOf(u64) * 2]u8 = undefined;
204203 var info_stream = std.io.fixedBufferStream(&info_buf);
205204 // TODO Implement for special flags.
......@@ -233,7 +232,7 @@ pub const Node = struct {
233232
234233 const FinalizeResult = struct {
235234 /// Current size of this node in bytes.
236 node_size: usize,
235 node_size: u64,
237236
238237 /// True if the trie offset of this node in the output byte stream
239238 /// would need updating; false otherwise.
......@@ -241,11 +240,11 @@ pub const Node = struct {
241240 };
242241
243242 /// Updates offset of this node in the output byte stream.
244 fn finalize(self: *Node, offset_in_trie: usize) !FinalizeResult {
243 fn finalize(self: *Node, offset_in_trie: u64) !FinalizeResult {
245244 var stream = std.io.countingWriter(std.io.null_writer);
246245 var writer = stream.writer();
247246
248 var node_size: usize = 0;
247 var node_size: u64 = 0;
249248 if (self.terminal_info) |info| {
250249 try leb.writeULEB128(writer, info.export_flags);
251250 try leb.writeULEB128(writer, info.vmaddr_offset);
......@@ -288,7 +287,7 @@ ordered_nodes: std.ArrayListUnmanaged(*Node) = .{},
288287/// insertions performed after `finalize` was called.
289288/// Call `finalize` before accessing this value to ensure
290289/// it is up-to-date.
291size: usize = 0,
290size: u64 = 0,
292291
293292/// Number of nodes currently in the trie.
294293node_count: usize = 0,
......@@ -374,7 +373,7 @@ pub fn read(self: *Trie, reader: anytype) ReadError!usize {
374373
375374/// Write the trie to a byte stream.
376375/// Panics if the trie was not finalized using `finalize` before calling this method.
377pub fn write(self: Trie, writer: anytype) !usize {
376pub fn write(self: Trie, writer: anytype) !u64 {
378377 assert(!self.trie_dirty);
379378 var counting_writer = std.io.countingWriter(writer);
380379 for (self.ordered_nodes.items) |node| {
src/link/MachO/imports.zig+4-4
......@@ -138,10 +138,10 @@ pub const BindingInfoTable = struct {
138138 }
139139
140140 /// Calculate size in bytes of this binding info table.
141 pub fn calcSize(self: *BindingInfoTable) !usize {
141 pub fn calcSize(self: *BindingInfoTable) !u64 {
142142 var stream = std.io.countingWriter(std.io.null_writer);
143143 var writer = stream.writer();
144 var size: usize = 1;
144 var size: u64 = 1;
145145
146146 if (self.dylib_ordinal > 15) {
147147 try leb.writeULEB128(writer, @bitCast(u64, self.dylib_ordinal));
......@@ -296,10 +296,10 @@ pub const LazyBindingInfoTable = struct {
296296 }
297297
298298 /// Calculate size in bytes of this binding info table.
299 pub fn calcSize(self: *LazyBindingInfoTable) !usize {
299 pub fn calcSize(self: *LazyBindingInfoTable) !u64 {
300300 var stream = std.io.countingWriter(std.io.null_writer);
301301 var writer = stream.writer();
302 var size: usize = 0;
302 var size: u64 = 0;
303303
304304 for (self.symbols.items) |symbol| {
305305 size += 1;