mirror of
https://github.com/ziglang/zig.git
synced 2026-02-13 04:48:20 +00:00
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
This commit is contained in:
parent
1cef0be01b
commit
5dfeb6cbc8
@ -907,7 +907,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
|
||||
const size = try self.binding_info_table.calcSize();
|
||||
assert(dyld_info.bind_size >= size);
|
||||
|
||||
var buffer = try self.base.allocator.alloc(u8, size);
|
||||
var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
|
||||
defer self.base.allocator.free(buffer);
|
||||
|
||||
var stream = std.io.fixedBufferStream(buffer);
|
||||
@ -919,7 +919,7 @@ fn linkWithLLD(self: *MachO, comp: *Compilation) !void {
|
||||
const size = try self.lazy_binding_info_table.calcSize();
|
||||
assert(dyld_info.lazy_bind_size >= size);
|
||||
|
||||
var buffer = try self.base.allocator.alloc(u8, size);
|
||||
var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
|
||||
defer self.base.allocator.free(buffer);
|
||||
|
||||
var stream = std.io.fixedBufferStream(buffer);
|
||||
@ -1875,13 +1875,13 @@ pub fn makeStaticString(comptime bytes: []const u8) [16]u8 {
|
||||
|
||||
fn makeString(self: *MachO, bytes: []const u8) !u32 {
|
||||
try self.string_table.ensureCapacity(self.base.allocator, self.string_table.items.len + bytes.len + 1);
|
||||
const result = self.string_table.items.len;
|
||||
const result = @intCast(u32, self.string_table.items.len);
|
||||
self.string_table.appendSliceAssumeCapacity(bytes);
|
||||
self.string_table.appendAssumeCapacity(0);
|
||||
self.string_table_dirty = true;
|
||||
if (self.d_sym) |*ds|
|
||||
ds.string_table_dirty = true;
|
||||
return @intCast(u32, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
fn getString(self: *MachO, str_off: u32) []const u8 {
|
||||
@ -2245,7 +2245,7 @@ fn writeExportTrie(self: *MachO) !void {
|
||||
}
|
||||
|
||||
try trie.finalize();
|
||||
var buffer = try self.base.allocator.alloc(u8, trie.size);
|
||||
var buffer = try self.base.allocator.alloc(u8, @intCast(usize, trie.size));
|
||||
defer self.base.allocator.free(buffer);
|
||||
var stream = std.io.fixedBufferStream(buffer);
|
||||
const nwritten = try trie.write(stream.writer());
|
||||
@ -2275,7 +2275,7 @@ fn writeBindingInfoTable(self: *MachO) !void {
|
||||
defer tracy.end();
|
||||
|
||||
const size = try self.binding_info_table.calcSize();
|
||||
var buffer = try self.base.allocator.alloc(u8, size);
|
||||
var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
|
||||
defer self.base.allocator.free(buffer);
|
||||
|
||||
var stream = std.io.fixedBufferStream(buffer);
|
||||
@ -2303,7 +2303,7 @@ fn writeLazyBindingInfoTable(self: *MachO) !void {
|
||||
if (!self.lazy_binding_info_dirty) return;
|
||||
|
||||
const size = try self.lazy_binding_info_table.calcSize();
|
||||
var buffer = try self.base.allocator.alloc(u8, size);
|
||||
var buffer = try self.base.allocator.alloc(u8, @intCast(usize, size));
|
||||
defer self.base.allocator.free(buffer);
|
||||
|
||||
var stream = std.io.fixedBufferStream(buffer);
|
||||
@ -2400,7 +2400,7 @@ fn updateLinkeditSegmentSizes(self: *MachO) !void {
|
||||
fn writeLoadCommands(self: *MachO) !void {
|
||||
if (!self.load_commands_dirty) return;
|
||||
|
||||
var sizeofcmds: usize = 0;
|
||||
var sizeofcmds: u32 = 0;
|
||||
for (self.load_commands.items) |lc| {
|
||||
sizeofcmds += lc.cmdsize();
|
||||
}
|
||||
|
||||
@ -84,7 +84,7 @@ pub fn calcAdhocSignature(
|
||||
.identOffset = 0,
|
||||
.nSpecialSlots = 0,
|
||||
.nCodeSlots = 0,
|
||||
.codeLimit = @intCast(u32, file_size),
|
||||
.codeLimit = file_size,
|
||||
.hashSize = hash_size,
|
||||
.hashType = macho.CS_HASHTYPE_SHA256,
|
||||
.platform = 0,
|
||||
|
||||
@ -747,7 +747,7 @@ fn updateDwarfSegment(self: *DebugSymbols) void {
|
||||
fn writeLoadCommands(self: *DebugSymbols, allocator: *Allocator) !void {
|
||||
if (!self.load_commands_dirty) return;
|
||||
|
||||
var sizeofcmds: usize = 0;
|
||||
var sizeofcmds: u32 = 0;
|
||||
for (self.load_commands.items) |lc| {
|
||||
sizeofcmds += lc.cmdsize();
|
||||
}
|
||||
|
||||
@ -52,7 +52,7 @@ pub const Node = struct {
|
||||
} = null,
|
||||
|
||||
/// Offset of this node in the trie output byte stream.
|
||||
trie_offset: ?usize = null,
|
||||
trie_offset: ?u64 = null,
|
||||
|
||||
/// List of all edges originating from this node.
|
||||
edges: std.ArrayListUnmanaged(Edge) = .{},
|
||||
@ -199,7 +199,6 @@ pub const Node = struct {
|
||||
assert(!self.node_dirty);
|
||||
if (self.terminal_info) |info| {
|
||||
// Terminal node info: encode export flags and vmaddr offset of this symbol.
|
||||
var info_buf_len: usize = 0;
|
||||
var info_buf: [@sizeOf(u64) * 2]u8 = undefined;
|
||||
var info_stream = std.io.fixedBufferStream(&info_buf);
|
||||
// TODO Implement for special flags.
|
||||
@ -233,7 +232,7 @@ pub const Node = struct {
|
||||
|
||||
const FinalizeResult = struct {
|
||||
/// Current size of this node in bytes.
|
||||
node_size: usize,
|
||||
node_size: u64,
|
||||
|
||||
/// True if the trie offset of this node in the output byte stream
|
||||
/// would need updating; false otherwise.
|
||||
@ -241,11 +240,11 @@ pub const Node = struct {
|
||||
};
|
||||
|
||||
/// Updates offset of this node in the output byte stream.
|
||||
fn finalize(self: *Node, offset_in_trie: usize) !FinalizeResult {
|
||||
fn finalize(self: *Node, offset_in_trie: u64) !FinalizeResult {
|
||||
var stream = std.io.countingWriter(std.io.null_writer);
|
||||
var writer = stream.writer();
|
||||
|
||||
var node_size: usize = 0;
|
||||
var node_size: u64 = 0;
|
||||
if (self.terminal_info) |info| {
|
||||
try leb.writeULEB128(writer, info.export_flags);
|
||||
try leb.writeULEB128(writer, info.vmaddr_offset);
|
||||
@ -288,7 +287,7 @@ ordered_nodes: std.ArrayListUnmanaged(*Node) = .{},
|
||||
/// insertions performed after `finalize` was called.
|
||||
/// Call `finalize` before accessing this value to ensure
|
||||
/// it is up-to-date.
|
||||
size: usize = 0,
|
||||
size: u64 = 0,
|
||||
|
||||
/// Number of nodes currently in the trie.
|
||||
node_count: usize = 0,
|
||||
@ -374,7 +373,7 @@ pub fn read(self: *Trie, reader: anytype) ReadError!usize {
|
||||
|
||||
/// Write the trie to a byte stream.
|
||||
/// Panics if the trie was not finalized using `finalize` before calling this method.
|
||||
pub fn write(self: Trie, writer: anytype) !usize {
|
||||
pub fn write(self: Trie, writer: anytype) !u64 {
|
||||
assert(!self.trie_dirty);
|
||||
var counting_writer = std.io.countingWriter(writer);
|
||||
for (self.ordered_nodes.items) |node| {
|
||||
|
||||
@ -138,10 +138,10 @@ pub const BindingInfoTable = struct {
|
||||
}
|
||||
|
||||
/// Calculate size in bytes of this binding info table.
|
||||
pub fn calcSize(self: *BindingInfoTable) !usize {
|
||||
pub fn calcSize(self: *BindingInfoTable) !u64 {
|
||||
var stream = std.io.countingWriter(std.io.null_writer);
|
||||
var writer = stream.writer();
|
||||
var size: usize = 1;
|
||||
var size: u64 = 1;
|
||||
|
||||
if (self.dylib_ordinal > 15) {
|
||||
try leb.writeULEB128(writer, @bitCast(u64, self.dylib_ordinal));
|
||||
@ -296,10 +296,10 @@ pub const LazyBindingInfoTable = struct {
|
||||
}
|
||||
|
||||
/// Calculate size in bytes of this binding info table.
|
||||
pub fn calcSize(self: *LazyBindingInfoTable) !usize {
|
||||
pub fn calcSize(self: *LazyBindingInfoTable) !u64 {
|
||||
var stream = std.io.countingWriter(std.io.null_writer);
|
||||
var writer = stream.writer();
|
||||
var size: usize = 0;
|
||||
var size: u64 = 0;
|
||||
|
||||
for (self.symbols.items) |symbol| {
|
||||
size += 1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user