diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-11-04 00:39:58 +0100 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-11-04 09:13:43 +0100 |
| commit | 56296694d94e83de844e26ac28af19d7b28533fd (patch) | |
| tree | 543460d6d98f68539002cda66500611a29be0a97 /src | |
| parent | ee66137269ee5375d7a3ca030ad0989f5edc625f (diff) | |
| download | zig-56296694d94e83de844e26ac28af19d7b28533fd.tar.gz zig-56296694d94e83de844e26ac28af19d7b28533fd.zip | |
elf: fix 32bit build
Diffstat (limited to 'src')
| -rw-r--r-- | src/link/Elf.zig | 13 | ||||
| -rw-r--r-- | src/link/Elf/ZigObject.zig | 7 |
2 files changed, 11 insertions, 9 deletions
diff --git a/src/link/Elf.zig b/src/link/Elf.zig index b2ac2b687a..a16fb83f1a 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1569,19 +1569,19 @@ pub fn flushStaticLib(self: *Elf, comp: *Compilation) link.File.FlushError!void } // Update file offsets of contributing objects. - const total_size: u64 = blk: { - var pos: u64 = Archive.SARMAG; + const total_size: usize = blk: { + var pos: usize = Archive.SARMAG; pos += @sizeOf(Archive.ar_hdr) + ar_symtab.size(.p64); if (ar_strtab.size() > 0) { - pos = mem.alignForward(u64, pos, 2); + pos = mem.alignForward(usize, pos, 2); pos += @sizeOf(Archive.ar_hdr) + ar_strtab.size(); } if (self.zigObjectPtr()) |zig_object| { - pos = mem.alignForward(u64, pos, 2); + pos = mem.alignForward(usize, pos, 2); zig_object.output_ar_state.file_off = pos; - pos += @sizeOf(Archive.ar_hdr) + zig_object.output_ar_state.size; + pos += @sizeOf(Archive.ar_hdr) + (math.cast(usize, zig_object.output_ar_state.size) orelse return error.Overflow); } break :blk pos; @@ -4672,7 +4672,8 @@ fn writeSymtab(self: *Elf) !void { log.debug("writing {d} symbols at 0x{x}", .{ nsyms, symtab_shdr.sh_offset }); try self.symtab.resize(gpa, nsyms); - try self.strtab.ensureUnusedCapacity(gpa, strtab_shdr.sh_size - 1); + const needed_strtab_size = math.cast(usize, strtab_shdr.sh_size - 1) orelse return error.Overflow; + try self.strtab.ensureUnusedCapacity(gpa, needed_strtab_size); const Ctx = struct { ilocal: usize, diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig index 5442d9a4bb..fda86f8125 100644 --- a/src/link/Elf/ZigObject.zig +++ b/src/link/Elf/ZigObject.zig @@ -542,7 +542,8 @@ pub fn updateArSize(self: *ZigObject, elf_file: *Elf) void { pub fn writeAr(self: ZigObject, elf_file: *Elf, writer: anytype) !void { const gpa = elf_file.base.allocator; - const contents = try gpa.alloc(u8, self.output_ar_state.size); + const size = std.math.cast(usize, self.output_ar_state.size) orelse return error.Overflow; + const contents = try gpa.alloc(u8, size); defer gpa.free(contents); 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 { const hdr = Archive.setArHdr(.{ .name = if (name.len <= 15) .{ .name = name } else .{ .name_off = self.output_ar_state.name_off }, - .size = @intCast(self.output_ar_state.size), + .size = size, }); try writer.writeAll(mem.asBytes(&hdr)); try writer.writeAll(contents); @@ -610,7 +611,7 @@ pub fn writeRelaSections(self: ZigObject, elf_file: *Elf) !void { var relocs = std.ArrayList(elf.Elf64_Rela).init(gpa); defer relocs.deinit(); - try relocs.ensureTotalCapacityPrecise(@divExact(shdr.sh_size, shdr.sh_entsize)); + try relocs.ensureTotalCapacityPrecise(@intCast(@divExact(shdr.sh_size, shdr.sh_entsize))); while (true) { for (atom.relocs(elf_file)) |rel| { |
