authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-02 21:18:22+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-06-03 00:23:04+02:00
logd1f60a63bdd7bd838c210a888dfe23c9ea9f2669
tree76f2bf28518fe9ec56cd070857ae913f0eba4112
parenta9dd8d75431357a59238da3fd949aa1f11eead84

zld: fix the linker for 32bit comp targets


4 files changed, 10 insertions(+), 10 deletions(-)

src/link/MachO/Archive.zig+4-4
......@@ -58,7 +58,7 @@ const ar_hdr = extern struct {
5858
5959 const NameOrLength = union(enum) {
6060 Name: []const u8,
61 Length: u64,
61 Length: u32,
6262 };
6363 fn nameOrLength(self: ar_hdr) !NameOrLength {
6464 const value = getValue(&self.ar_name);
......@@ -70,14 +70,14 @@ const ar_hdr = extern struct {
7070 } else {
7171 // Name follows the header directly and its length is encoded in
7272 // the name field.
73 const length = try std.fmt.parseInt(u64, value[slash_index + 1 ..], 10);
73 const length = try std.fmt.parseInt(u32, value[slash_index + 1 ..], 10);
7474 return NameOrLength{ .Length = length };
7575 }
7676 }
7777
78 fn size(self: ar_hdr) !u64 {
78 fn size(self: ar_hdr) !u32 {
7979 const value = getValue(&self.ar_size);
80 return std.fmt.parseInt(u64, value, 10);
80 return std.fmt.parseInt(u32, value, 10);
8181 }
8282
8383 fn getValue(raw: []const u8) []const u8 {
src/link/MachO/Object.zig+2-2
......@@ -284,7 +284,7 @@ pub fn parseSections(self: *Object) !void {
284284 for (seg.sections.items) |sect| {
285285 log.debug("parsing section '{s},{s}'", .{ parseName(&sect.segname), parseName(&sect.sectname) });
286286 // Read sections' code
287 var code = try self.allocator.alloc(u8, sect.size);
287 var code = try self.allocator.alloc(u8, @intCast(usize, sect.size));
288288 _ = try self.file.?.preadAll(code, sect.offset);
289289
290290 var section = Section{
......@@ -461,7 +461,7 @@ pub fn parseDebugInfo(self: *Object) !void {
461461fn readSection(self: Object, allocator: *Allocator, index: u16) ![]u8 {
462462 const seg = self.load_commands.items[self.segment_cmd_index.?].Segment;
463463 const sect = seg.sections.items[index];
464 var buffer = try allocator.alloc(u8, sect.size);
464 var buffer = try allocator.alloc(u8, @intCast(usize, sect.size));
465465 _ = try self.file.?.preadAll(buffer, sect.offset);
466466 return buffer;
467467}
src/link/MachO/Zld.zig+1-1
......@@ -2214,7 +2214,7 @@ fn flush(self: *Zld) !void {
22142214 const seg = self.load_commands.items[self.data_segment_cmd_index.?].Segment;
22152215 const sect = &seg.sections.items[index];
22162216
2217 var buffer = try self.allocator.alloc(u8, sect.size);
2217 var buffer = try self.allocator.alloc(u8, @intCast(usize, sect.size));
22182218 defer self.allocator.free(buffer);
22192219 _ = try self.file.?.preadAll(buffer, sect.offset);
22202220
src/link/MachO/reloc.zig+3-3
......@@ -179,12 +179,12 @@ pub fn parse(
179179
180180pub const RelocIterator = struct {
181181 buffer: []const macho.relocation_info,
182 index: i64 = -1,
182 index: i32 = -1,
183183
184184 pub fn next(self: *RelocIterator) ?macho.relocation_info {
185185 self.index += 1;
186186 if (self.index < self.buffer.len) {
187 const reloc = self.buffer[@intCast(u64, self.index)];
187 const reloc = self.buffer[@intCast(u32, self.index)];
188188 log.debug("relocation", .{});
189189 log.debug(" | type = {}", .{reloc.r_type});
190190 log.debug(" | offset = {}", .{reloc.r_address});
......@@ -199,6 +199,6 @@ pub const RelocIterator = struct {
199199
200200 pub fn peek(self: RelocIterator) macho.relocation_info {
201201 assert(self.index + 1 < self.buffer.len);
202 return self.buffer[@intCast(u64, self.index + 1)];
202 return self.buffer[@intCast(u32, self.index + 1)];
203203 }
204204};