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 {
755755 const need_strings = (idx == header.shstrndx);
756756
757757 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));
759759 const bytes_read = try source.preadAll(buffer, section.section.sh_offset);
760760 if (bytes_read != section.section.sh_size) return error.TRUNCATED_ELF;
761761 section.payload = buffer;
......@@ -838,7 +838,7 @@ const ElfContents = struct {
838838 switch (section.section.sh_type) {
839839 elf.DT_VERSYM => {
840840 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)];
842842 for (defs) |def| {
843843 if (def.vd_ndx != elf.SHN_UNDEF)
844844 dirty |= Local.propagateUsage(&sections[def.vd_ndx].usage, section.usage);
......@@ -846,7 +846,7 @@ const ElfContents = struct {
846846 },
847847 elf.SHT_SYMTAB, elf.SHT_DYNSYM => {
848848 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
851851 for (syms) |sym| {
852852 if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE)
......@@ -1020,7 +1020,7 @@ const ElfContents = struct {
10201020 dest.sh_size = data.len;
10211021
10221022 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);
10241024 if (src.sh_offset != dest.sh_offset and section.segment != null and update.action != .empty and dest.sh_type != elf.SHT_NOTE) {
10251025 if (src.sh_offset > dest.sh_offset) {
10261026 dest.sh_offset = src.sh_offset; // add padding to avoid modifing the program segments
......@@ -1041,14 +1041,14 @@ const ElfContents = struct {
10411041
10421042 switch (src.sh_type) {
10431043 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)];
10451045 for (defs) |*def| {
10461046 if (def.vd_ndx != elf.SHN_UNDEF)
10471047 def.vd_ndx = sections_update[src.sh_info].remap_idx;
10481048 }
10491049 },
10501050 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)];
10521052 for (syms) |*sym| {
10531053 if (sym.st_shndx != elf.SHN_UNDEF and sym.st_shndx < elf.SHN_LORESERVE)
10541054 sym.st_shndx = sections_update[sym.st_shndx].remap_idx;
......@@ -1106,7 +1106,7 @@ const ElfContents = struct {
11061106
11071107 // write the section header at the tail
11081108 {
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
11111111 const data = std.mem.sliceAsBytes(updated_section_header);
11121112 std.debug.assert(data.len == @as(usize, updated_elf_header.e_shentsize) * new_shnum);