From 9b0a3942ef22e35a08377265daf4bc3168a1ae21 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 12 Oct 2024 01:50:01 -0700 Subject: [PATCH] objcopy: update for std.elf type safety the new types make this code seem a bit strange --- lib/compiler/objcopy.zig | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/compiler/objcopy.zig b/lib/compiler/objcopy.zig index 9794671e6f..a46dcab9c8 100644 --- a/lib/compiler/objcopy.zig +++ b/lib/compiler/objcopy.zig @@ -832,7 +832,6 @@ fn ElfFile(comptime is_64: bool) type { const Elf_Shdr = if (is_64) elf.Elf64_Shdr else elf.Elf32_Shdr; const Elf_Chdr = if (is_64) elf.Elf64_Chdr else elf.Elf32_Chdr; const Elf_Sym = if (is_64) elf.Elf64_Sym else elf.Elf32_Sym; - const Elf_Verdef = if (is_64) elf.Elf64_Verdef else elf.Elf32_Verdef; const Elf_OffSize = if (is_64) elf.Elf64_Off else elf.Elf32_Off; return struct { @@ -1179,10 +1178,13 @@ fn ElfFile(comptime is_64: bool) type { const data = try allocator.alignedAlloc(u8, section_memory_align, src_data.len); @memcpy(data, src_data); - const defs = @as([*]Elf_Verdef, @ptrCast(data))[0 .. @as(usize, @intCast(src.sh_size)) / @sizeOf(Elf_Verdef)]; + const defs = @as([*]elf.Verdef, @ptrCast(data))[0 .. @as(usize, @intCast(src.sh_size)) / @sizeOf(elf.Verdef)]; for (defs) |*def| { - if (def.vd_ndx != elf.SHN_UNDEF) - def.vd_ndx = sections_update[src.sh_info].remap_idx; + // Original author of this next line had elf.SHN_UNDEF + // here which does not make sense given that this field + // is elf.VER_NDX + if (def.ndx != .LOCAL) + def.ndx = @enumFromInt(sections_update[src.sh_info].remap_idx); } break :dst_data data;