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 {...@@ -58,7 +58,7 @@ const ar_hdr = extern struct {
5858
59 const NameOrLength = union(enum) {59 const NameOrLength = union(enum) {
60 Name: []const u8,60 Name: []const u8,
61 Length: u64,61 Length: u32,
62 };62 };
63 fn nameOrLength(self: ar_hdr) !NameOrLength {63 fn nameOrLength(self: ar_hdr) !NameOrLength {
64 const value = getValue(&self.ar_name);64 const value = getValue(&self.ar_name);
...@@ -70,14 +70,14 @@ const ar_hdr = extern struct {...@@ -70,14 +70,14 @@ const ar_hdr = extern struct {
70 } else {70 } else {
71 // Name follows the header directly and its length is encoded in71 // Name follows the header directly and its length is encoded in
72 // the name field.72 // 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);
74 return NameOrLength{ .Length = length };74 return NameOrLength{ .Length = length };
75 }75 }
76 }76 }
7777
78 fn size(self: ar_hdr) !u64 {78 fn size(self: ar_hdr) !u32 {
79 const value = getValue(&self.ar_size);79 const value = getValue(&self.ar_size);
80 return std.fmt.parseInt(u64, value, 10);80 return std.fmt.parseInt(u32, value, 10);
81 }81 }
8282
83 fn getValue(raw: []const u8) []const u8 {83 fn getValue(raw: []const u8) []const u8 {
src/link/MachO/Object.zig+2-2
...@@ -284,7 +284,7 @@ pub fn parseSections(self: *Object) !void {...@@ -284,7 +284,7 @@ pub fn parseSections(self: *Object) !void {
284 for (seg.sections.items) |sect| {284 for (seg.sections.items) |sect| {
285 log.debug("parsing section '{s},{s}'", .{ parseName(&sect.segname), parseName(&sect.sectname) });285 log.debug("parsing section '{s},{s}'", .{ parseName(&sect.segname), parseName(&sect.sectname) });
286 // Read sections' code286 // 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));
288 _ = try self.file.?.preadAll(code, sect.offset);288 _ = try self.file.?.preadAll(code, sect.offset);
289289
290 var section = Section{290 var section = Section{
...@@ -461,7 +461,7 @@ pub fn parseDebugInfo(self: *Object) !void {...@@ -461,7 +461,7 @@ pub fn parseDebugInfo(self: *Object) !void {
461fn readSection(self: Object, allocator: *Allocator, index: u16) ![]u8 {461fn readSection(self: Object, allocator: *Allocator, index: u16) ![]u8 {
462 const seg = self.load_commands.items[self.segment_cmd_index.?].Segment;462 const seg = self.load_commands.items[self.segment_cmd_index.?].Segment;
463 const sect = seg.sections.items[index];463 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));
465 _ = try self.file.?.preadAll(buffer, sect.offset);465 _ = try self.file.?.preadAll(buffer, sect.offset);
466 return buffer;466 return buffer;
467}467}
src/link/MachO/Zld.zig+1-1
...@@ -2214,7 +2214,7 @@ fn flush(self: *Zld) !void {...@@ -2214,7 +2214,7 @@ fn flush(self: *Zld) !void {
2214 const seg = self.load_commands.items[self.data_segment_cmd_index.?].Segment;2214 const seg = self.load_commands.items[self.data_segment_cmd_index.?].Segment;
2215 const sect = &seg.sections.items[index];2215 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));
2218 defer self.allocator.free(buffer);2218 defer self.allocator.free(buffer);
2219 _ = try self.file.?.preadAll(buffer, sect.offset);2219 _ = try self.file.?.preadAll(buffer, sect.offset);
22202220
src/link/MachO/reloc.zig+3-3
...@@ -179,12 +179,12 @@ pub fn parse(...@@ -179,12 +179,12 @@ pub fn parse(
179179
180pub const RelocIterator = struct {180pub const RelocIterator = struct {
181 buffer: []const macho.relocation_info,181 buffer: []const macho.relocation_info,
182 index: i64 = -1,182 index: i32 = -1,
183183
184 pub fn next(self: *RelocIterator) ?macho.relocation_info {184 pub fn next(self: *RelocIterator) ?macho.relocation_info {
185 self.index += 1;185 self.index += 1;
186 if (self.index < self.buffer.len) {186 if (self.index < self.buffer.len) {
187 const reloc = self.buffer[@intCast(u64, self.index)];187 const reloc = self.buffer[@intCast(u32, self.index)];
188 log.debug("relocation", .{});188 log.debug("relocation", .{});
189 log.debug(" | type = {}", .{reloc.r_type});189 log.debug(" | type = {}", .{reloc.r_type});
190 log.debug(" | offset = {}", .{reloc.r_address});190 log.debug(" | offset = {}", .{reloc.r_address});
...@@ -199,6 +199,6 @@ pub const RelocIterator = struct {...@@ -199,6 +199,6 @@ pub const RelocIterator = struct {
199199
200 pub fn peek(self: RelocIterator) macho.relocation_info {200 pub fn peek(self: RelocIterator) macho.relocation_info {
201 assert(self.index + 1 < self.buffer.len);201 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)];
203 }203 }
204};204};