authorgravatar for xavierb@gmail.comXavier Bouchoux <xavierb@gmail.com> 2023-03-12 09:58:35+01:00
committergravatar for xavierb@gmail.comXavier Bouchoux <xavierb@gmail.com> 2023-03-20 08:39:23+01:00
log60d033d1f3e052cf0b469b6739ee0e12f9409c26
treec1b1d5092545d6be2265476e5f4235878260f05c
parent3a700d60baf419d837c0e71518e388337cb1bb33

objcopy: fix compilation on 32-bit systems


1 files changed, 7 insertions(+), 7 deletions(-)

src/objcopy.zig+7-7
...@@ -755,7 +755,7 @@ const ElfContents = struct {...@@ -755,7 +755,7 @@ const ElfContents = struct {
755 const need_strings = (idx == header.shstrndx);755 const need_strings = (idx == header.shstrndx);
756756
757 if (need_data or need_strings) {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 const bytes_read = try source.preadAll(buffer, section.section.sh_offset);759 const bytes_read = try source.preadAll(buffer, section.section.sh_offset);
760 if (bytes_read != section.section.sh_size) return error.TRUNCATED_ELF;760 if (bytes_read != section.section.sh_size) return error.TRUNCATED_ELF;
761 section.payload = buffer;761 section.payload = buffer;
...@@ -838,7 +838,7 @@ const ElfContents = struct {...@@ -838,7 +838,7 @@ const ElfContents = struct {
838 switch (section.section.sh_type) {838 switch (section.section.sh_type) {
839 elf.DT_VERSYM => {839 elf.DT_VERSYM => {
840 std.debug.assert(section.section.sh_entsize == @sizeOf(elf.Elf64_Verdef));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 for (defs) |def| {842 for (defs) |def| {
843 if (def.vd_ndx != elf.SHN_UNDEF)843 if (def.vd_ndx != elf.SHN_UNDEF)
844 dirty |= Local.propagateUsage(&sections[def.vd_ndx].usage, section.usage);844 dirty |= Local.propagateUsage(&sections[def.vd_ndx].usage, section.usage);
...@@ -846,7 +846,7 @@ const ElfContents = struct {...@@ -846,7 +846,7 @@ const ElfContents = struct {
846 },846 },
847 elf.SHT_SYMTAB, elf.SHT_DYNSYM => {847 elf.SHT_SYMTAB, elf.SHT_DYNSYM => {
848 std.debug.assert(section.section.sh_entsize == @sizeOf(elf.Elf64_Sym));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)];
850850
851 for (syms) |sym| {851 for (syms) |sym| {
852 if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE)852 if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE)
...@@ -1020,7 +1020,7 @@ const ElfContents = struct {...@@ -1020,7 +1020,7 @@ const ElfContents = struct {
1020 dest.sh_size = data.len;1020 dest.sh_size = data.len;
10211021
1022 const addralign = if (src.sh_addralign == 0 or dest.sh_type == elf.SHT_NOBITS) 1 else src.sh_addralign;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 if (src.sh_offset != dest.sh_offset and section.segment != null and update.action != .empty and dest.sh_type != elf.SHT_NOTE) {1024 if (src.sh_offset != dest.sh_offset and section.segment != null and update.action != .empty and dest.sh_type != elf.SHT_NOTE) {
1025 if (src.sh_offset > dest.sh_offset) {1025 if (src.sh_offset > dest.sh_offset) {
1026 dest.sh_offset = src.sh_offset; // add padding to avoid modifing the program segments1026 dest.sh_offset = src.sh_offset; // add padding to avoid modifing the program segments
...@@ -1041,14 +1041,14 @@ const ElfContents = struct {...@@ -1041,14 +1041,14 @@ const ElfContents = struct {
10411041
1042 switch (src.sh_type) {1042 switch (src.sh_type) {
1043 elf.DT_VERSYM => {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 for (defs) |*def| {1045 for (defs) |*def| {
1046 if (def.vd_ndx != elf.SHN_UNDEF)1046 if (def.vd_ndx != elf.SHN_UNDEF)
1047 def.vd_ndx = sections_update[src.sh_info].remap_idx;1047 def.vd_ndx = sections_update[src.sh_info].remap_idx;
1048 }1048 }
1049 },1049 },
1050 elf.SHT_SYMTAB, elf.SHT_DYNSYM => {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 for (syms) |*sym| {1052 for (syms) |*sym| {
1053 if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE)1053 if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE)
1054 sym.st_shndx = sections_update[sym.st_shndx].remap_idx;1054 sym.st_shndx = sections_update[sym.st_shndx].remap_idx;
...@@ -1106,7 +1106,7 @@ const ElfContents = struct {...@@ -1106,7 +1106,7 @@ const ElfContents = struct {
11061106
1107 // write the section header at the tail1107 // 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));
11101110
1111 const data = std.mem.sliceAsBytes(updated_section_header);1111 const data = std.mem.sliceAsBytes(updated_section_header);
1112 std.debug.assert(data.len == @as(usize, updated_elf_header.e_shentsize) * new_shnum);1112 std.debug.assert(data.len == @as(usize, updated_elf_header.e_shentsize) * new_shnum);