authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-04 00:39:58+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-04 09:13:43+01:00
log56296694d94e83de844e26ac28af19d7b28533fd
tree543460d6d98f68539002cda66500611a29be0a97
parentee66137269ee5375d7a3ca030ad0989f5edc625f

elf: fix 32bit build


2 files changed, 11 insertions(+), 9 deletions(-)

src/link/Elf.zig+7-6
......@@ -1569,19 +1569,19 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void
15691569 }
15701570
15711571 // Update file offsets of contributing objects.
1572 const total_size: u64 = blk: {
1573 var pos: u64 = Archive.SARMAG;
1572 const total_size: usize = blk: {
1573 var pos: usize = Archive.SARMAG;
15741574 pos += @sizeOf(Archive.ar_hdr) + ar_symtab.size(.p64);
15751575
15761576 if (ar_strtab.size() > 0) {
1577 pos = mem.alignForward(u64, pos, 2);
1577 pos = mem.alignForward(usize, pos, 2);
15781578 pos += @sizeOf(Archive.ar_hdr) + ar_strtab.size();
15791579 }
15801580
15811581 if (self.zigObjectPtr()) |zig_object| {
1582 pos = mem.alignForward(u64, pos, 2);
1582 pos = mem.alignForward(usize, pos, 2);
15831583 zig_object.output_ar_state.file_off = pos;
1584 pos += @sizeOf(Archive.ar_hdr) + zig_object.output_ar_state.size;
1584 pos += @sizeOf(Archive.ar_hdr) + (math.cast(usize, zig_object.output_ar_state.size) orelse return error.Overflow);
15851585 }
15861586
15871587 break :blk pos;
......@@ -4672,7 +4672,8 @@ fn writeSymtab(self: *Elf) !void {
46724672 log.debug("writing {d} symbols at 0x{x}", .{ nsyms, symtab_shdr.sh_offset });
46734673
46744674 try self.symtab.resize(gpa, nsyms);
4675 try self.strtab.ensureUnusedCapacity(gpa, strtab_shdr.sh_size - 1);
4675 const needed_strtab_size = math.cast(usize, strtab_shdr.sh_size - 1) orelse return error.Overflow;
4676 try self.strtab.ensureUnusedCapacity(gpa, needed_strtab_size);
46764677
46774678 const Ctx = struct {
46784679 ilocal: usize,
src/link/Elf/ZigObject.zig+4-3
......@@ -542,7 +542,8 @@ pub fn updateArSize(self: *ZigObject, elf_file: *Elf) void {
542542pub fn writeAr(self: ZigObject, elf_file: *Elf, writer: anytype) !void {
543543 const gpa = elf_file.base.allocator;
544544
545 const contents = try gpa.alloc(u8, self.output_ar_state.size);
545 const size = std.math.cast(usize, self.output_ar_state.size) orelse return error.Overflow;
546 const contents = try gpa.alloc(u8, size);
546547 defer gpa.free(contents);
547548
548549 const amt = try elf_file.base.file.?.preadAll(contents, 0);
......@@ -553,7 +554,7 @@ pub fn writeAr(self: ZigObject, elf_file: *Elf, writer: anytype) !void {
553554
554555 const hdr = Archive.setArHdr(.{
555556 .name = if (name.len <= 15) .{ .name = name } else .{ .name_off = self.output_ar_state.name_off },
556 .size = @intCast(self.output_ar_state.size),
557 .size = size,
557558 });
558559 try writer.writeAll(mem.asBytes(&hdr));
559560 try writer.writeAll(contents);
......@@ -610,7 +611,7 @@ pub fn writeRelaSections(self: ZigObject, elf_file: *Elf) !void {
610611
611612 var relocs = std.ArrayList(elf.Elf64_Rela).init(gpa);
612613 defer relocs.deinit();
613 try relocs.ensureTotalCapacityPrecise(@divExact(shdr.sh_size, shdr.sh_entsize));
614 try relocs.ensureTotalCapacityPrecise(@intCast(@divExact(shdr.sh_size, shdr.sh_entsize)));
614615
615616 while (true) {
616617 for (atom.relocs(elf_file)) |rel| {