| ... | ... | @@ -755,7 +755,7 @@ const ElfContents = struct { |
| 755 | 755 | const need_strings = (idx == header.shstrndx); |
| 756 | 756 | |
| 757 | 757 | if (need_data or need_strings) { |
| 758 | | const buffer = try allocator.alignedAlloc(u8, section_memory_align, section.section.sh_size); |
| 758 | const buffer = try allocator.alignedAlloc(u8, section_memory_align, @intCast(usize, section.section.sh_size)); |
| 759 | 759 | const bytes_read = try source.preadAll(buffer, section.section.sh_offset); |
| 760 | 760 | if (bytes_read != section.section.sh_size) return error.TRUNCATED_ELF; |
| 761 | 761 | section.payload = buffer; |
| ... | ... | @@ -838,7 +838,7 @@ const ElfContents = struct { |
| 838 | 838 | switch (section.section.sh_type) { |
| 839 | 839 | elf.DT_VERSYM => { |
| 840 | 840 | std.debug.assert(section.section.sh_entsize == @sizeOf(elf.Elf64_Verdef)); |
| 841 | | const defs = @ptrCast([*]const elf.Elf64_Verdef, data)[0 .. section.section.sh_size / @sizeOf(elf.Elf64_Verdef)]; |
| 841 | const defs = @ptrCast([*]const elf.Elf64_Verdef, data)[0 .. @intCast(usize, section.section.sh_size) / @sizeOf(elf.Elf64_Verdef)]; |
| 842 | 842 | for (defs) |def| { |
| 843 | 843 | if (def.vd_ndx != elf.SHN_UNDEF) |
| 844 | 844 | dirty |= Local.propagateUsage(&sections[def.vd_ndx].usage, section.usage); |
| ... | ... | @@ -846,7 +846,7 @@ const ElfContents = struct { |
| 846 | 846 | }, |
| 847 | 847 | elf.SHT_SYMTAB, elf.SHT_DYNSYM => { |
| 848 | 848 | std.debug.assert(section.section.sh_entsize == @sizeOf(elf.Elf64_Sym)); |
| 849 | | const syms = @ptrCast([*]const elf.Elf64_Sym, data)[0 .. section.section.sh_size / @sizeOf(elf.Elf64_Sym)]; |
| 849 | const syms = @ptrCast([*]const elf.Elf64_Sym, data)[0 .. @intCast(usize, section.section.sh_size) / @sizeOf(elf.Elf64_Sym)]; |
| 850 | 850 | |
| 851 | 851 | for (syms) |sym| { |
| 852 | 852 | if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE) |
| ... | ... | @@ -1020,7 +1020,7 @@ const ElfContents = struct { |
| 1020 | 1020 | dest.sh_size = data.len; |
| 1021 | 1021 | |
| 1022 | 1022 | const addralign = if (src.sh_addralign == 0 or dest.sh_type == elf.SHT_NOBITS) 1 else src.sh_addralign; |
| 1023 | | dest.sh_offset = std.mem.alignForward(eof_offset, addralign); |
| 1023 | dest.sh_offset = std.mem.alignForwardGeneric(u64, eof_offset, addralign); |
| 1024 | 1024 | if (src.sh_offset != dest.sh_offset and section.segment != null and update.action != .empty and dest.sh_type != elf.SHT_NOTE) { |
| 1025 | 1025 | if (src.sh_offset > dest.sh_offset) { |
| 1026 | 1026 | dest.sh_offset = src.sh_offset; // add padding to avoid modifing the program segments |
| ... | ... | @@ -1041,14 +1041,14 @@ const ElfContents = struct { |
| 1041 | 1041 | |
| 1042 | 1042 | switch (src.sh_type) { |
| 1043 | 1043 | elf.DT_VERSYM => { |
| 1044 | | const defs = @ptrCast([*]elf.Elf64_Verdef, data)[0 .. src.sh_size / @sizeOf(elf.Elf64_Verdef)]; |
| 1044 | const defs = @ptrCast([*]elf.Elf64_Verdef, data)[0 .. @intCast(usize, src.sh_size) / @sizeOf(elf.Elf64_Verdef)]; |
| 1045 | 1045 | for (defs) |*def| { |
| 1046 | 1046 | if (def.vd_ndx != elf.SHN_UNDEF) |
| 1047 | 1047 | def.vd_ndx = sections_update[src.sh_info].remap_idx; |
| 1048 | 1048 | } |
| 1049 | 1049 | }, |
| 1050 | 1050 | elf.SHT_SYMTAB, elf.SHT_DYNSYM => { |
| 1051 | | const syms = @ptrCast([*]elf.Elf64_Sym, data)[0 .. src.sh_size / @sizeOf(elf.Elf64_Sym)]; |
| 1051 | const syms = @ptrCast([*]elf.Elf64_Sym, data)[0 .. @intCast(usize, src.sh_size) / @sizeOf(elf.Elf64_Sym)]; |
| 1052 | 1052 | for (syms) |*sym| { |
| 1053 | 1053 | if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE) |
| 1054 | 1054 | sym.st_shndx = sections_update[sym.st_shndx].remap_idx; |
| ... | ... | @@ -1106,7 +1106,7 @@ const ElfContents = struct { |
| 1106 | 1106 | |
| 1107 | 1107 | // write the section header at the tail |
| 1108 | 1108 | { |
| 1109 | | const offset = std.mem.alignForward(eof_offset, @alignOf(elf.Elf64_Shdr)); |
| 1109 | const offset = std.mem.alignForwardGeneric(u64, eof_offset, @alignOf(elf.Elf64_Shdr)); |
| 1110 | 1110 | |
| 1111 | 1111 | const data = std.mem.sliceAsBytes(updated_section_header); |
| 1112 | 1112 | std.debug.assert(data.len == @as(usize, updated_elf_header.e_shentsize) * new_shnum); |