From ea006188aaf110a33cbf0ca00888306f263cce98 Mon Sep 17 00:00:00 2001 From: David Senoner Date: Wed, 29 Jul 2026 14:08:23 +0200 Subject: [PATCH 1/5] elf: remove all deprecated usages and definitions of std.elf.PT_* --- lib/compiler/objcopy.zig | 2 +- lib/std/Build/Step/Compile.zig | 2 +- lib/std/dynamic_library.zig | 8 ++-- lib/std/elf.zig | 41 -------------------- lib/std/os/linux/tls.zig | 8 ++-- lib/std/os/linux/vdso.zig | 4 +- lib/std/pie.zig | 2 +- lib/std/posix/test.zig | 2 +- lib/std/start.zig | 4 +- lib/std/zig/system.zig | 8 ++-- src/link/Elf.zig | 70 +++++++++++++++++----------------- src/link/Lld.zig | 4 +- 12 files changed, 57 insertions(+), 98 deletions(-) diff --git a/lib/compiler/objcopy.zig b/lib/compiler/objcopy.zig index 857299a60e16f410c3eb54ca6be8382c33b99567..136b48ef4c0cbadfd6f9309bfda8660fedb613d0 100644 --- a/lib/compiler/objcopy.zig +++ b/lib/compiler/objcopy.zig @@ -435,7 +435,7 @@ const BinaryElfOutput = struct { var program_headers = elf_hdr.iterateProgramHeaders(in); while (try program_headers.next()) |phdr| { - if (phdr.p_type == elf.PT_LOAD) { + if (phdr.p_type == @backingInt(elf.PT.LOAD)) { const newSegment = try allocator.create(BinaryElfSegment); newSegment.physicalAddress = phdr.p_paddr; diff --git a/lib/std/Build/Step/Compile.zig b/lib/std/Build/Step/Compile.zig index b14e0c254846d0bda46e06f735015f877dcf9a36..90d88f3a20785f3cb892b080212b8cda9afd5f88 100644 --- a/lib/std/Build/Step/Compile.zig +++ b/lib/std/Build/Step/Compile.zig @@ -101,7 +101,7 @@ each_lib_rpath: ?bool = null, /// This option overrides the CLI argument passed to `zig build`. build_id: ?std.zig.BuildId = null, -/// Create a .eh_frame_hdr section and a PT_GNU_EH_FRAME segment in the ELF +/// Create a .eh_frame_hdr section and a PT.GNU_EH_FRAME segment in the ELF /// file. link_eh_frame_hdr: bool = false, link_emit_relocs: bool = false, diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig index 0161644439803e7fc6dd4fbb1c1610235d97b5e0..767821f9ffe6743e1a5579ea6e231c22e5635124 100644 --- a/lib/std/dynamic_library.zig +++ b/lib/std/dynamic_library.zig @@ -103,7 +103,7 @@ pub fn get_DYNAMIC() ?[*]const elf.Dyn { pub fn linkmap_iterator() error{InvalidExe}!LinkMap.Iterator { const _DYNAMIC = get_DYNAMIC() orelse { - // No PT_DYNAMIC means this is a statically-linked non-PIE program. + // No PT.DYNAMIC means this is a statically-linked non-PIE program. return .{ .current = null }; }; @@ -263,8 +263,8 @@ pub const ElfDynLib = struct { }) { const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr)); switch (ph.p_type) { - elf.PT_LOAD => virt_addr_end = @max(virt_addr_end, ph.p_vaddr + ph.p_memsz), - elf.PT_DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(elf_addr + ph.p_offset)), + @backingInt(elf.PT.LOAD) => virt_addr_end = @max(virt_addr_end, ph.p_vaddr + ph.p_memsz), + @backingInt(elf.PT.DYNAMIC) => maybe_dynv = @as([*]usize, @ptrFromInt(elf_addr + ph.p_offset)), else => {}, } } @@ -294,7 +294,7 @@ pub const ElfDynLib = struct { }) { const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr)); switch (ph.p_type) { - elf.PT_LOAD => { + @backingInt(elf.PT.LOAD) => { // The VirtAddr may not be page-aligned; in such case there will be // extra nonsense mapped before/after the VirtAddr,MemSiz const aligned_addr = (base + ph.p_vaddr) & ~(@as(usize, page_size) - 1); diff --git a/lib/std/elf.zig b/lib/std/elf.zig index e96cb50f97512239ff86e648d4dabd91eb5f01e4..d731f44289673ae800438ac34310400ed690ec85 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -290,47 +290,6 @@ pub const VER_FLG_BASE = 1; /// Weak version identifier pub const VER_FLG_WEAK = 2; -/// Deprecated, use `@intFromEnum(std.elf.PT.NULL)` -pub const PT_NULL = @backingInt(std.elf.PT.NULL); -/// Deprecated, use `@intFromEnum(std.elf.PT.LOAD)` -pub const PT_LOAD = @backingInt(std.elf.PT.LOAD); -/// Deprecated, use `@intFromEnum(std.elf.PT.DYNAMIC)` -pub const PT_DYNAMIC = @backingInt(std.elf.PT.DYNAMIC); -/// Deprecated, use `@intFromEnum(std.elf.PT.INTERP)` -pub const PT_INTERP = @backingInt(std.elf.PT.INTERP); -/// Deprecated, use `@intFromEnum(std.elf.PT.NOTE)` -pub const PT_NOTE = @backingInt(std.elf.PT.NOTE); -/// Deprecated, use `@intFromEnum(std.elf.PT.SHLIB)` -pub const PT_SHLIB = @backingInt(std.elf.PT.SHLIB); -/// Deprecated, use `@intFromEnum(std.elf.PT.PHDR)` -pub const PT_PHDR = @backingInt(std.elf.PT.PHDR); -/// Deprecated, use `@intFromEnum(std.elf.PT.TLS)` -pub const PT_TLS = @backingInt(std.elf.PT.TLS); -/// Deprecated, use `std.elf.PT.NUM`. -pub const PT_NUM = PT.NUM; -/// Deprecated, use `@intFromEnum(std.elf.PT.LOOS)` -pub const PT_LOOS = @backingInt(std.elf.PT.LOOS); -/// Deprecated, use `@intFromEnum(std.elf.PT.GNU_EH_FRAME)` -pub const PT_GNU_EH_FRAME = @backingInt(std.elf.PT.GNU_EH_FRAME); -/// Deprecated, use `@intFromEnum(std.elf.PT.GNU_STACK)` -pub const PT_GNU_STACK = @backingInt(std.elf.PT.GNU_STACK); -/// Deprecated, use `@intFromEnum(std.elf.PT.GNU_RELRO)` -pub const PT_GNU_RELRO = @backingInt(std.elf.PT.GNU_RELRO); -/// Deprecated, use `@intFromEnum(std.elf.PT.LOSUNW)` -pub const PT_LOSUNW = @backingInt(std.elf.PT.LOSUNW); -/// Deprecated, use `@intFromEnum(std.elf.PT.SUNWBSS)` -pub const PT_SUNWBSS = @backingInt(std.elf.PT.SUNWBSS); -/// Deprecated, use `@intFromEnum(std.elf.PT.SUNWSTACK)` -pub const PT_SUNWSTACK = @backingInt(std.elf.PT.SUNWSTACK); -/// Deprecated, use `@intFromEnum(std.elf.PT.HISUNW)` -pub const PT_HISUNW = @backingInt(std.elf.PT.HISUNW); -/// Deprecated, use `@intFromEnum(std.elf.PT.HIOS)` -pub const PT_HIOS = @backingInt(std.elf.PT.HIOS); -/// Deprecated, use `@intFromEnum(std.elf.PT.LOPROC)` -pub const PT_LOPROC = @backingInt(std.elf.PT.LOPROC); -/// Deprecated, use `@intFromEnum(std.elf.PT.HIPROC)` -pub const PT_HIPROC = @backingInt(std.elf.PT.HIPROC); - pub const PN_XNUM = 0xffff; /// Deprecated, use `@intFromEnum(std.elf.SHT.NULL)` diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index e02ba39840497e2dec5d55ed1a7bb4a05b17ad01..79664061b1de96bbc00cf0714e4d8a82a5aa5f88 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -22,7 +22,7 @@ const page_size_min = std.heap.page_size_min; /// Represents an ELF TLS variant. /// /// In all variants, the TP and the TLS blocks must be aligned to the `p_align` value in the -/// `PT_TLS` ELF program header. Everything else has natural alignment. +/// `PT.TLS` ELF program header. Everything else has natural alignment. /// /// The location of the DTV does not actually matter. For simplicity, we put it in the TLS area, but /// there is no actual ABI requirement that it reside there. @@ -489,8 +489,8 @@ fn computeAreaDesc(phdrs: []elf.Phdr) void { for (phdrs) |*phdr| { switch (phdr.p_type) { - elf.PT_PHDR => img_base = @intFromPtr(phdrs.ptr) - phdr.p_vaddr, - elf.PT_TLS => tls_phdr = phdr, + @backingInt(elf.PT.PHDR) => img_base = @intFromPtr(phdrs.ptr) - phdr.p_vaddr, + @backingInt(elf.PT.TLS) => tls_phdr = phdr, else => {}, } } @@ -503,7 +503,7 @@ fn computeAreaDesc(phdrs: []elf.Phdr) void { align_factor = phdr.p_align; // The effective size in memory is represented by `p_memsz`; the length of the data stored - // in the `PT_TLS` segment is `p_filesz` and may be less than the former. + // in the `PT.TLS` segment is `p_filesz` and may be less than the former. block_init = @as([*]u8, @ptrFromInt(img_base + phdr.p_vaddr))[0..phdr.p_filesz]; block_size = phdr.p_memsz; } else { diff --git a/lib/std/os/linux/vdso.zig b/lib/std/os/linux/vdso.zig index 1106ee8bf173dd6eaff0fe372e490249d91dd89f..cc058b7ffcc3ab64f0fc7beaf0afa233d3514483 100644 --- a/lib/std/os/linux/vdso.zig +++ b/lib/std/os/linux/vdso.zig @@ -25,8 +25,8 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1). // Wrapping operations are used on this line as well as subsequent calculations relative to base // (lines 47, 78) to ensure no overflow check is tripped. - elf.PT_LOAD => base = vdso_addr +% this_ph.p_offset -% this_ph.p_vaddr, - elf.PT_DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(vdso_addr + this_ph.p_offset)), + @backingInt(elf.PT.LOAD) => base = vdso_addr +% this_ph.p_offset -% this_ph.p_vaddr, + @backingInt(elf.PT.DYNAMIC) => maybe_dynv = @as([*]usize, @ptrFromInt(vdso_addr + this_ph.p_offset)), else => {}, } } diff --git a/lib/std/pie.zig b/lib/std/pie.zig index 0252cde9e8f0161ae5a3767723c3853f94ec82f0..498fe3672e1c6e10fa940f40f2dcc380b2c49f63 100644 --- a/lib/std/pie.zig +++ b/lib/std/pie.zig @@ -303,7 +303,7 @@ pub fn relocate(phdrs: []const elf.Phdr) void { // the theoretical load addresses for the `_DYNAMIC` symbol. const base_addr = base: { for (phdrs) |*phdr| { - if (phdr.p_type != elf.PT_DYNAMIC) continue; + if (phdr.p_type != @backingInt(elf.PT.DYNAMIC)) continue; break :base @intFromPtr(dynv) - phdr.p_vaddr; } // This is not supposed to happen for well-formed binaries. diff --git a/lib/std/posix/test.zig b/lib/std/posix/test.zig index 8accb90cb7f9c79b3246fb974c838c9c28e7245d..4fb68855b5a5953b709fae4f893bc051a50dbf09 100644 --- a/lib/std/posix/test.zig +++ b/lib/std/posix/test.zig @@ -75,7 +75,7 @@ fn iter_fn(info: *dl_phdr_info, size: usize, counter: *usize) IterFnError!void { // Count how many libraries are loaded counter.* += @as(usize, 1); - // The image should contain at least a PT_LOAD segment + // The image should contain at least a PT.LOAD segment if (info.phnum < 1) return error.MissingPtLoadSegment; // Quick & dirty validation of the phdr pointers, make sure we're not diff --git a/lib/std/start.zig b/lib/std/start.zig index 2530b80d360c4e9b61bb8f2d4e25006d20aea2c3..cd72a52847d60eaa5dd30bd0a161ddff99bfc3f0 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -621,7 +621,7 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn { std.os.linux.tls.initStatic(phdrs); } - // The way Linux executables represent stack size is via the PT_GNU_STACK + // The way Linux executables represent stack size is via the PT.GNU_STACK // program header. However the kernel does not recognize it; it always gives 8 MiB. // Here we look for the stack size in our program headers and use setrlimit // to ask for more stack space. @@ -649,7 +649,7 @@ fn expandStackSize(phdrs: []elf.Phdr) void { @disableInstrumentation(); for (phdrs) |*phdr| { switch (phdr.p_type) { - elf.PT_GNU_STACK => { + @backingInt(elf.PT.GNU_STACK) => { if (phdr.p_memsz == 0) break; assert(phdr.p_memsz % std.heap.page_size_min == 0); diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 060fd1d97643beac4e5724a12ea26427e7500a31..083e7bb90f0ffb5acabf3470414262834e3cb0b1 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -597,14 +597,14 @@ fn abiAndDynamicLinkerFromFile( .ofmt = query.ofmt orelse Target.ObjectFormat.default(os.tag, cpu.arch), .dynamic_linker = query.dynamic_linker orelse .none, }; - var rpath_offset: ?u64 = null; // Found inside PT_DYNAMIC + var rpath_offset: ?u64 = null; // Found inside PT.DYNAMIC const look_for_ld = query.dynamic_linker == null; var got_dyn_section: bool = false; { var it = header.iterateProgramHeaders(file_reader); while (try it.next()) |phdr| switch (phdr.p_type) { - elf.PT_INTERP => { + @backingInt(elf.PT.INTERP) => { got_dyn_section = true; if (look_for_ld) { @@ -613,7 +613,7 @@ fn abiAndDynamicLinkerFromFile( const filesz: usize = @intCast(p_filesz); try file_reader.seekTo(phdr.p_offset); try file_reader.interface.readSliceAll(result.dynamic_linker.buffer[0..filesz]); - // PT_INTERP includes a null byte in filesz. + // PT.INTERP includes a null byte in filesz. const len = filesz - 1; // dynamic_linker.max_byte is "max", not "len". // We know it will fit in u8 because we check against dynamic_linker.buffer.len above. @@ -631,7 +631,7 @@ fn abiAndDynamicLinkerFromFile( } }, // We only need this for detecting glibc version. - elf.PT_DYNAMIC => { + @backingInt(elf.PT.DYNAMIC) => { got_dyn_section = true; if (builtin.target.os.tag == .linux and result.isGnuLibC() and query.glibc_version == null) { diff --git a/src/link/Elf.zig b/src/link/Elf.zig index cda6d5321069bfe23b53efb10eb6dc6da8a0bc6d..de53f98bd5d3a83bd548d4c8b7d41b57a60d2cba 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -159,21 +159,21 @@ const ProgramHeaderIndex = enum(u16) { }; const ProgramHeaderIndexes = struct { - /// PT_PHDR + /// PT.PHDR table: OptionalProgramHeaderIndex = .none, - /// PT_LOAD for PHDR table + /// PT.LOAD for PHDR table /// We add this special load segment to ensure the EHDR and PHDR table are always /// loaded into memory. table_load: OptionalProgramHeaderIndex = .none, - /// PT_INTERP + /// PT.INTERP interp: OptionalProgramHeaderIndex = .none, - /// PT_DYNAMIC + /// PT.DYNAMIC dynamic: OptionalProgramHeaderIndex = .none, - /// PT_GNU_EH_FRAME + /// PT.GNU_EH_FRAME gnu_eh_frame: OptionalProgramHeaderIndex = .none, - /// PT_GNU_STACK + /// PT.GNU_STACK gnu_stack: OptionalProgramHeaderIndex = .none, - /// PT_TLS + /// PT.TLS /// TODO I think ELF permits multiple TLS segments but for now, assume one per file. tls: OptionalProgramHeaderIndex = .none, }; @@ -334,7 +334,7 @@ pub fn createEmpty( if (!is_obj_or_ar) { try self.dynstrtab.append(gpa, 0); - // Initialize PT_PHDR program header + // Initialize PT.PHDR program header const p_align: u16 = switch (self.ptr_width) { .p32 => @alignOf(elf.Elf32_Phdr), .p64 => @alignOf(elf.Elf64_Phdr), @@ -350,7 +350,7 @@ pub fn createEmpty( const max_nphdrs = comptime getMaxNumberOfPhdrs(); const reserved: u64 = mem.alignForward(u64, padToIdeal(max_nphdrs * phsize), self.page_size); self.phdr_indexes.table = (try self.addPhdr(.{ - .type = elf.PT_PHDR, + .type = @backingInt(elf.PT.PHDR), .flags = elf.PF_R, .@"align" = p_align, .addr = self.image_base + ehsize, @@ -359,7 +359,7 @@ pub fn createEmpty( .memsz = reserved, })).toOptional(); self.phdr_indexes.table_load = (try self.addPhdr(.{ - .type = elf.PT_LOAD, + .type = @backingInt(elf.PT.LOAD), .flags = elf.PF_R, .@"align" = self.page_size, .addr = self.image_base, @@ -514,7 +514,7 @@ fn detectAllocCollision(self: *Elf, start: u64, size: u64) !?u64 { } for (self.phdrs.items) |phdr| { - if (phdr.p_type != elf.PT_LOAD) continue; + if (phdr.p_type != @backingInt(elf.PT.LOAD)) continue; const increased_size = padToIdeal(phdr.p_filesz); const test_end = phdr.p_offset +| increased_size; if (start < test_end) { @@ -2091,26 +2091,26 @@ fn initSpecialPhdrs(self: *Elf) !void { if (self.section_indexes.interp != null and self.phdr_indexes.interp == .none) { self.phdr_indexes.interp = (try self.addPhdr(.{ - .type = elf.PT_INTERP, + .type = @backingInt(elf.PT.INTERP), .flags = elf.PF_R, .@"align" = 1, })).toOptional(); } if (self.section_indexes.dynamic != null and self.phdr_indexes.dynamic == .none) { self.phdr_indexes.dynamic = (try self.addPhdr(.{ - .type = elf.PT_DYNAMIC, + .type = @backingInt(elf.PT.DYNAMIC), .flags = elf.PF_R | elf.PF_W, })).toOptional(); } if (self.section_indexes.eh_frame_hdr != null and self.phdr_indexes.gnu_eh_frame == .none) { self.phdr_indexes.gnu_eh_frame = (try self.addPhdr(.{ - .type = elf.PT_GNU_EH_FRAME, + .type = @backingInt(elf.PT.GNU_EH_FRAME), .flags = elf.PF_R, })).toOptional(); } if (self.phdr_indexes.gnu_stack == .none) { self.phdr_indexes.gnu_stack = (try self.addPhdr(.{ - .type = elf.PT_GNU_STACK, + .type = @backingInt(elf.PT.GNU_STACK), .flags = elf.PF_W | elf.PF_R, .memsz = self.base.stack_size, .@"align" = 1, @@ -2122,7 +2122,7 @@ fn initSpecialPhdrs(self: *Elf) !void { } else false; if (has_tls and self.phdr_indexes.tls == .none) { self.phdr_indexes.tls = (try self.addPhdr(.{ - .type = elf.PT_TLS, + .type = @backingInt(elf.PT.TLS), .flags = elf.PF_R, .@"align" = 1, })).toOptional(); @@ -2262,13 +2262,13 @@ fn setHashSections(self: *Elf) !void { fn phdrRank(phdr: elf.Elf64_Phdr) u8 { return switch (phdr.p_type) { - elf.PT_NULL => 0, - elf.PT_PHDR => 1, - elf.PT_INTERP => 2, - elf.PT_LOAD => 3, - elf.PT_DYNAMIC, elf.PT_TLS => 4, - elf.PT_GNU_EH_FRAME => 5, - elf.PT_GNU_STACK => 6, + @backingInt(elf.PT.NULL) => 0, + @backingInt(elf.PT.PHDR) => 1, + @backingInt(elf.PT.INTERP) => 2, + @backingInt(elf.PT.LOAD) => 3, + @backingInt(elf.PT.DYNAMIC), @backingInt(elf.PT.TLS) => 4, + @backingInt(elf.PT.GNU_EH_FRAME) => 5, + @backingInt(elf.PT.GNU_STACK) => 6, else => 7, }; } @@ -2655,8 +2655,8 @@ fn addLoadPhdrs(self: *Elf) error{OutOfMemory}!void { if (shdr.sh_type == elf.SHT_NULL) continue; if (shdr.sh_flags & elf.SHF_ALLOC == 0) continue; const flags = shdrToPhdrFlags(shdr.sh_flags); - if (self.getPhdr(.{ .flags = flags, .type = elf.PT_LOAD }) == .none) { - _ = try self.addPhdr(.{ .flags = flags, .type = elf.PT_LOAD }); + if (self.getPhdr(.{ .flags = flags, .type = @backingInt(elf.PT.LOAD) }) == .none) { + _ = try self.addPhdr(.{ .flags = flags, .type = @backingInt(elf.PT.LOAD) }); } } } @@ -2817,7 +2817,7 @@ pub fn allocateAllocSections(self: *Elf) !void { } const first = slice.items(.shdr)[cover.items[0]]; - const phndx = self.getPhdr(.{ .type = elf.PT_LOAD, .flags = shdrToPhdrFlags(first.sh_flags) }).unwrap().?; + const phndx = self.getPhdr(.{ .type = @backingInt(elf.PT.LOAD), .flags = shdrToPhdrFlags(first.sh_flags) }).unwrap().?; const phdr = &self.phdrs.items[phndx.int()]; const allocated_size = self.allocatedSize(phdr.p_offset); if (filesz > allocated_size) { @@ -3906,15 +3906,15 @@ fn formatPhdr(ctx: FormatPhdr, writer: *std.Io.Writer) std.Io.Writer.Error!void if (write) flags[1] = 'W'; if (read) flags[2] = 'R'; const p_type = switch (phdr.p_type) { - elf.PT_LOAD => "LOAD", - elf.PT_TLS => "TLS", - elf.PT_GNU_EH_FRAME => "GNU_EH_FRAME", - elf.PT_GNU_STACK => "GNU_STACK", - elf.PT_DYNAMIC => "DYNAMIC", - elf.PT_INTERP => "INTERP", - elf.PT_NULL => "NULL", - elf.PT_PHDR => "PHDR", - elf.PT_NOTE => "NOTE", + @backingInt(elf.PT.LOAD) => "LOAD", + @backingInt(elf.PT.TLS) => "TLS", + @backingInt(elf.PT.GNU_EH_FRAME) => "GNU_EH_FRAME", + @backingInt(elf.PT.GNU_STACK) => "GNU_STACK", + @backingInt(elf.PT.DYNAMIC) => "DYNAMIC", + @backingInt(elf.PT.INTERP) => "INTERP", + @backingInt(elf.PT.NULL) => "NULL", + @backingInt(elf.PT.PHDR) => "PHDR", + @backingInt(elf.PT.NOTE) => "NOTE", else => "UNKNOWN", }; try writer.print("{s} : {s} : @{x} ({x}) : align({x}) : filesz({x}) : memsz({x})", .{ diff --git a/src/link/Lld.zig b/src/link/Lld.zig index cf64d3fd5bc51817cc86a7554ac65ee7aa53e373..62b92f00e56db89b856acf5927f670273dcc2b92 100644 --- a/src/link/Lld.zig +++ b/src/link/Lld.zig @@ -1021,8 +1021,8 @@ fn elfLink(lld: *Lld, arena: Allocator) !void { } if (is_exe_or_dyn_lib and target.os.tag == .netbsd) { - // Add options to produce shared objects with only 2 PT_LOAD segments. - // NetBSD expects 2 PT_LOAD segments in a shared object, otherwise + // Add options to produce shared objects with only 2 PT.LOAD segments. + // NetBSD expects 2 PT.LOAD segments in a shared object, otherwise // ld.elf_so fails loading dynamic libraries with "not found" error. // See https://github.com/ziglang/zig/issues/9109 . try argv.append("--no-rosegment"); -- 2.54.0 From 8d888624567d6c5170ddbeda5f312c3b1762261b Mon Sep 17 00:00:00 2001 From: David Senoner Date: Thu, 30 Jul 2026 18:03:19 +0200 Subject: [PATCH 2/5] elf: remove usages of deprecated elf.Phdr --- lib/std/dynamic_library.zig | 32 ++++++++++++++++---------------- lib/std/os/emscripten.zig | 2 +- lib/std/os/linux/tls.zig | 22 +++++++++++----------- lib/std/os/linux/vdso.zig | 10 +++++----- lib/std/pie.zig | 6 +++--- lib/std/start.zig | 16 ++++++++-------- 6 files changed, 44 insertions(+), 44 deletions(-) diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig index 767821f9ffe6743e1a5579ea6e231c22e5635124..98bcafb88b16504cfab619d8407675b5014fd6e9 100644 --- a/lib/std/dynamic_library.zig +++ b/lib/std/dynamic_library.zig @@ -261,10 +261,10 @@ pub const ElfDynLib = struct { i += 1; ph_addr += eh.e_phentsize; }) { - const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr)); - switch (ph.p_type) { - @backingInt(elf.PT.LOAD) => virt_addr_end = @max(virt_addr_end, ph.p_vaddr + ph.p_memsz), - @backingInt(elf.PT.DYNAMIC) => maybe_dynv = @as([*]usize, @ptrFromInt(elf_addr + ph.p_offset)), + const ph = @as(*elf.ElfN.Phdr, @ptrFromInt(ph_addr)); + switch (ph.type) { + .LOAD => virt_addr_end = @max(virt_addr_end, ph.vaddr + ph.memsz), + .DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(elf_addr + ph.offset)), else => {}, } } @@ -292,23 +292,23 @@ pub const ElfDynLib = struct { i += 1; ph_addr += eh.e_phentsize; }) { - const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr)); - switch (ph.p_type) { - @backingInt(elf.PT.LOAD) => { + const ph = @as(*elf.ElfN.Phdr, @ptrFromInt(ph_addr)); + switch (ph.type) { + .LOAD => { // The VirtAddr may not be page-aligned; in such case there will be // extra nonsense mapped before/after the VirtAddr,MemSiz - const aligned_addr = (base + ph.p_vaddr) & ~(@as(usize, page_size) - 1); - const extra_bytes = (base + ph.p_vaddr) - aligned_addr; - const extended_memsz = mem.alignForward(usize, ph.p_memsz + extra_bytes, page_size); + const aligned_addr = (base + ph.vaddr) & ~(@as(usize, page_size) - 1); + const extra_bytes = (base + ph.vaddr) - aligned_addr; + const extended_memsz = mem.alignForward(usize, ph.memsz + extra_bytes, page_size); const ptr = @as([*]align(std.heap.page_size_min) u8, @ptrFromInt(aligned_addr)); - const prot = elfToProt(ph.p_flags); + const prot = elfToProt(ph.flags); _ = try posix.mmap( ptr, extended_memsz, prot, .{ .TYPE = .PRIVATE, .FIXED = true }, file.handle, - ph.p_offset - extra_bytes, + ph.offset - extra_bytes, ); }, else => {}, @@ -517,11 +517,11 @@ pub const ElfDynLib = struct { return null; } - fn elfToProt(elf_prot: u64) posix.PROT { + fn elfToProt(elf_prot: elf.PF) posix.PROT { return .{ - .READ = (elf_prot & elf.PF_R) != 0, - .WRITE = (elf_prot & elf.PF_W) != 0, - .EXEC = (elf_prot & elf.PF_X) != 0, + .READ = elf_prot.R, + .WRITE = elf_prot.W, + .EXEC = elf_prot.X, }; } }; diff --git a/lib/std/os/emscripten.zig b/lib/std/os/emscripten.zig index 5df52dd9b87fada9ccc2d5286d864902b3894e3d..da0c85d1b05a5758a52aeae315446e91fc982477 100644 --- a/lib/std/os/emscripten.zig +++ b/lib/std/os/emscripten.zig @@ -730,7 +730,7 @@ pub const clock_t = i32; pub const dl_phdr_info = extern struct { addr: usize, name: ?[*:0]const u8, - phdr: [*]std.elf.Phdr, + phdr: [*]std.elf.ElfN.Phdr, phnum: u16, }; diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index 79664061b1de96bbc00cf0714e4d8a82a5aa5f88..a42c44f29fe48de3383752055d7a63947ec52fd2 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -480,17 +480,17 @@ pub fn getThreadPointer() usize { }; } -fn computeAreaDesc(phdrs: []elf.Phdr) void { +fn computeAreaDesc(phdrs: []elf.ElfN.Phdr) void { @setRuntimeSafety(false); @disableInstrumentation(); - var tls_phdr: ?*elf.Phdr = null; + var tls_phdr: ?*elf.ElfN.Phdr = null; var img_base: usize = 0; for (phdrs) |*phdr| { - switch (phdr.p_type) { - @backingInt(elf.PT.PHDR) => img_base = @intFromPtr(phdrs.ptr) - phdr.p_vaddr, - @backingInt(elf.PT.TLS) => tls_phdr = phdr, + switch (phdr.type) { + .PHDR => img_base = @intFromPtr(phdrs.ptr) - phdr.vaddr, + .TLS => tls_phdr = phdr, else => {}, } } @@ -500,12 +500,12 @@ fn computeAreaDesc(phdrs: []elf.Phdr) void { var block_size: usize = undefined; if (tls_phdr) |phdr| { - align_factor = phdr.p_align; + align_factor = phdr.@"align"; - // The effective size in memory is represented by `p_memsz`; the length of the data stored - // in the `PT.TLS` segment is `p_filesz` and may be less than the former. - block_init = @as([*]u8, @ptrFromInt(img_base + phdr.p_vaddr))[0..phdr.p_filesz]; - block_size = phdr.p_memsz; + // The effective size in memory is represented by `memsz`; the length of the data stored + // in the `PT.TLS` segment is `filesz` and may be less than the former. + block_init = @as([*]u8, @ptrFromInt(img_base + phdr.vaddr))[0..phdr.filesz]; + block_size = phdr.memsz; } else { align_factor = @alignOf(usize); @@ -651,7 +651,7 @@ var main_thread_area_buffer: [0x1000]u8 align(page_size_min) = undefined; /// Computes the layout of the static TLS area, allocates the area, initializes all of its fields, /// and assigns the architecture-specific value to the TP register. -pub fn initStatic(phdrs: []elf.Phdr) void { +pub fn initStatic(phdrs: []elf.ElfN.Phdr) void { @setRuntimeSafety(false); @disableInstrumentation(); diff --git a/lib/std/os/linux/vdso.zig b/lib/std/os/linux/vdso.zig index cc058b7ffcc3ab64f0fc7beaf0afa233d3514483..53be1bf9d51f0048d57074313fa49aff65e0e6a2 100644 --- a/lib/std/os/linux/vdso.zig +++ b/lib/std/os/linux/vdso.zig @@ -19,14 +19,14 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { i += 1; ph_addr += eh.e_phentsize; }) { - const this_ph = @as(*elf.Phdr, @ptrFromInt(ph_addr)); - switch (this_ph.p_type) { + const this_ph = @as(*elf.ElfN.Phdr, @ptrFromInt(ph_addr)); + switch (this_ph.type) { // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half - // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1). + // of the memory space (e.g. vaddr = 0xffffffffff700000 on WSL1). // Wrapping operations are used on this line as well as subsequent calculations relative to base // (lines 47, 78) to ensure no overflow check is tripped. - @backingInt(elf.PT.LOAD) => base = vdso_addr +% this_ph.p_offset -% this_ph.p_vaddr, - @backingInt(elf.PT.DYNAMIC) => maybe_dynv = @as([*]usize, @ptrFromInt(vdso_addr + this_ph.p_offset)), + .LOAD => base = vdso_addr +% this_ph.offset -% this_ph.vaddr, + .DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(vdso_addr + this_ph.offset)), else => {}, } } diff --git a/lib/std/pie.zig b/lib/std/pie.zig index 498fe3672e1c6e10fa940f40f2dcc380b2c49f63..bcec6acd590f391c56202ff897b364ee0d456554 100644 --- a/lib/std/pie.zig +++ b/lib/std/pie.zig @@ -293,7 +293,7 @@ inline fn getDynamicSymbol() [*]const elf.Dyn { }; } -pub fn relocate(phdrs: []const elf.Phdr) void { +pub fn relocate(phdrs: []const elf.ElfN.Phdr) void { @setRuntimeSafety(false); @disableInstrumentation(); @@ -303,8 +303,8 @@ pub fn relocate(phdrs: []const elf.Phdr) void { // the theoretical load addresses for the `_DYNAMIC` symbol. const base_addr = base: { for (phdrs) |*phdr| { - if (phdr.p_type != @backingInt(elf.PT.DYNAMIC)) continue; - break :base @intFromPtr(dynv) - phdr.p_vaddr; + if (phdr.type != .DYNAMIC) continue; + break :base @intFromPtr(dynv) - phdr.vaddr; } // This is not supposed to happen for well-formed binaries. @trap(); diff --git a/lib/std/start.zig b/lib/std/start.zig index cd72a52847d60eaa5dd30bd0a161ddff99bfc3f0..6021da10325aa38a6be00d59ecc1d58634deba77 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -589,7 +589,7 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn { else => continue, } } - break :init @as([*]elf.Phdr, @ptrFromInt(at_phdr))[0..at_phnum]; + break :init @as([*]elf.ElfN.Phdr, @ptrFromInt(at_phdr))[0..at_phnum]; }; // Apply the initial relocations as early as possible in the startup process. We cannot @@ -645,19 +645,19 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn { std.process.exit(callMainWithArgs(argc, argv, envp)); } -fn expandStackSize(phdrs: []elf.Phdr) void { +fn expandStackSize(phdrs: []elf.ElfN.Phdr) void { @disableInstrumentation(); for (phdrs) |*phdr| { - switch (phdr.p_type) { - @backingInt(elf.PT.GNU_STACK) => { - if (phdr.p_memsz == 0) break; - assert(phdr.p_memsz % std.heap.page_size_min == 0); + switch (phdr.type) { + .GNU_STACK => { + if (phdr.memsz == 0) break; + assert(phdr.memsz % std.heap.page_size_min == 0); // Silently fail if we are unable to get limits. const limits = std.posix.getrlimit(.STACK) catch break; // Clamp to limits.max . - const wanted_stack_size = @min(phdr.p_memsz, limits.max); + const wanted_stack_size = @min(phdr.memsz, limits.max); if (wanted_stack_size > limits.cur) { std.posix.setrlimit(.STACK, .{ @@ -702,7 +702,7 @@ fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) cal .linux => { const at_phdr = std.c.getauxval(elf.AT_PHDR); const at_phnum = std.c.getauxval(elf.AT_PHNUM); - const phdrs = (@as([*]elf.Phdr, @ptrFromInt(at_phdr)))[0..at_phnum]; + const phdrs = (@as([*]elf.ElfN.Phdr, @ptrFromInt(at_phdr)))[0..at_phnum]; expandStackSize(phdrs); }, .windows => { -- 2.54.0 From 4843120b4c3d3bb8cc8cb56b0185af24676616ff Mon Sep 17 00:00:00 2001 From: David Senoner Date: Wed, 29 Jul 2026 15:11:54 +0200 Subject: [PATCH 3/5] elf: remove usages of deprecated Elf32_Phdr --- lib/std/debug/SelfInfo/Elf.zig | 2 +- lib/std/elf.zig | 22 +++++++++++----------- src/link/Elf.zig | 30 +++++++++++++++--------------- 3 files changed, 27 insertions(+), 27 deletions(-) diff --git a/lib/std/debug/SelfInfo/Elf.zig b/lib/std/debug/SelfInfo/Elf.zig index eb60162dcb405709a7468e97ea4b755aaefe2d90..398a3f95a8933d489f67e3c9958084f2ed4e5660 100644 --- a/lib/std/debug/SelfInfo/Elf.zig +++ b/lib/std/debug/SelfInfo/Elf.zig @@ -518,7 +518,7 @@ const DlIterContext = struct { for (info.phdr[0..info.phnum]) |phdr| { if (phdr.type != .LOAD) continue; try context.si.ranges.append(gpa, .{ - // Overflowing addition handles VSDOs having p_vaddr = 0xffffffffff700000 + // Overflowing addition handles VSDOs having vaddr = 0xffffffffff700000 .start = info.addr +% phdr.vaddr, .len = phdr.memsz, .module_index = module_index, diff --git a/lib/std/elf.zig b/lib/std/elf.zig index d731f44289673ae800438ac34310400ed690ec85..97710d03c175cc48273b8e40c324bff122fc4caa 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -811,7 +811,7 @@ pub const ProgramHeaderIterator = struct { if (it.index >= it.phnum) return null; defer it.index += 1; - const size: u64 = if (it.is_64) @sizeOf(Elf64_Phdr) else @sizeOf(Elf32_Phdr); + const size: u64 = if (it.is_64) @sizeOf(Elf64_Phdr) else @sizeOf(Elf32.Phdr); const offset = it.phoff + size * it.index; try it.file_reader.seekTo(offset); @@ -832,7 +832,7 @@ pub const ProgramHeaderBufferIterator = struct { if (it.index >= it.phnum) return null; defer it.index += 1; - const size: usize = if (it.is_64) @sizeOf(Elf64_Phdr) else @sizeOf(Elf32_Phdr); + const size: usize = if (it.is_64) @sizeOf(Elf64_Phdr) else @sizeOf(Elf32.Phdr); const offset = @as(usize, @intCast(it.phoff)) + size * it.index; var reader = Io.Reader.fixed(it.buf[offset..]); @@ -846,16 +846,16 @@ pub fn takeProgramHeader(reader: *Io.Reader, is_64: bool, endian: Endian) !Elf64 return phdr; } - const phdr = try reader.takeStruct(Elf32_Phdr, endian); + const phdr = try reader.takeStruct(Elf32.Phdr, endian); return .{ - .p_type = phdr.p_type, - .p_offset = phdr.p_offset, - .p_vaddr = phdr.p_vaddr, - .p_paddr = phdr.p_paddr, - .p_filesz = phdr.p_filesz, - .p_memsz = phdr.p_memsz, - .p_flags = phdr.p_flags, - .p_align = phdr.p_align, + .p_type = @backingInt(phdr.type), + .p_offset = phdr.offset, + .p_vaddr = phdr.vaddr, + .p_paddr = phdr.paddr, + .p_filesz = phdr.filesz, + .p_memsz = phdr.memsz, + .p_flags = @backingInt(phdr.flags), + .p_align = phdr.@"align", }; } diff --git a/src/link/Elf.zig b/src/link/Elf.zig index de53f98bd5d3a83bd548d4c8b7d41b57a60d2cba..3f82771d536a6fcc6265b1b0b366943979d2faa7 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -336,7 +336,7 @@ pub fn createEmpty( // Initialize PT.PHDR program header const p_align: u16 = switch (self.ptr_width) { - .p32 => @alignOf(elf.Elf32_Phdr), + .p32 => @alignOf(elf.Elf32.Phdr), .p64 => @alignOf(elf.Elf64_Phdr), }; const ehsize: u64 = switch (self.ptr_width) { @@ -344,7 +344,7 @@ pub fn createEmpty( .p64 => @sizeOf(elf.Elf64_Ehdr), }; const phsize: u64 = switch (self.ptr_width) { - .p32 => @sizeOf(elf.Elf32_Phdr), + .p32 => @sizeOf(elf.Elf32.Phdr), .p64 => @sizeOf(elf.Elf64_Phdr), }; const max_nphdrs = comptime getMaxNumberOfPhdrs(); @@ -1477,13 +1477,13 @@ fn writePhdrTable(self: *Elf) !void { switch (self.ptr_width) { .p32 => { - const buf = try gpa.alloc(elf.Elf32_Phdr, self.phdrs.items.len); + const buf = try gpa.alloc(elf.Elf32.Phdr, self.phdrs.items.len); defer gpa.free(buf); for (buf, 0..) |*phdr, i| { phdr.* = phdrTo32(self.phdrs.items[i]); if (foreign_endian) { - mem.byteSwapAllFields(elf.Elf32_Phdr, phdr); + mem.byteSwapAllFields(elf.Elf32.Phdr, phdr); } } try self.pwriteAll(@ptrCast(buf), phdr_table.p_offset); @@ -1622,7 +1622,7 @@ pub fn writeElfHeader(self: *Elf) !void { index += 2; const e_phentsize: u16 = switch (self.ptr_width) { - .p32 => @sizeOf(elf.Elf32_Phdr), + .p32 => @sizeOf(elf.Elf32.Phdr), .p64 => @sizeOf(elf.Elf64_Phdr), }; mem.writeInt(u16, hdr_buf[index..][0..2], e_phentsize, endian); @@ -2672,7 +2672,7 @@ fn allocatePhdrTable(self: *Elf) error{OutOfMemory}!void { .p64 => @sizeOf(elf.Elf64_Ehdr), }; const phsize: u64 = switch (self.ptr_width) { - .p32 => @sizeOf(elf.Elf32_Phdr), + .p32 => @sizeOf(elf.Elf32.Phdr), .p64 => @sizeOf(elf.Elf64_Phdr), }; const needed_size = self.phdrs.items.len * phsize; @@ -3347,16 +3347,16 @@ pub fn archPtrWidthBytes(self: Elf) u8 { return @intCast(@divExact(self.getTarget().ptrBitWidth(), 8)); } -fn phdrTo32(phdr: elf.Elf64_Phdr) elf.Elf32_Phdr { +fn phdrTo32(phdr: elf.Elf64_Phdr) elf.Elf32.Phdr { return .{ - .p_type = phdr.p_type, - .p_flags = phdr.p_flags, - .p_offset = @as(u32, @intCast(phdr.p_offset)), - .p_vaddr = @as(u32, @intCast(phdr.p_vaddr)), - .p_paddr = @as(u32, @intCast(phdr.p_paddr)), - .p_filesz = @as(u32, @intCast(phdr.p_filesz)), - .p_memsz = @as(u32, @intCast(phdr.p_memsz)), - .p_align = @as(u32, @intCast(phdr.p_align)), + .type = @fromBackingInt(phdr.p_type), + .flags = @fromBackingInt(phdr.p_flags), + .offset = @intCast(phdr.p_offset), + .vaddr = @intCast(phdr.p_vaddr), + .paddr = @intCast(phdr.p_paddr), + .filesz = @intCast(phdr.p_filesz), + .memsz = @intCast(phdr.p_memsz), + .@"align" = @intCast(phdr.p_align), }; } -- 2.54.0 From 574c80351da46a4ac836504c6591d5db068eaa06 Mon Sep 17 00:00:00 2001 From: David Senoner Date: Thu, 30 Jul 2026 18:38:51 +0200 Subject: [PATCH 4/5] elf: remove usages of deprecated Elf64_Phdr --- lib/compiler/objcopy.zig | 14 +-- lib/std/elf.zig | 28 +++--- lib/std/zig/system.zig | 12 +-- src/link/Elf.zig | 202 +++++++++++++++++++-------------------- 4 files changed, 128 insertions(+), 128 deletions(-) diff --git a/lib/compiler/objcopy.zig b/lib/compiler/objcopy.zig index 136b48ef4c0cbadfd6f9309bfda8660fedb613d0..a54c61f5000ff569a7c34461e7db80b515d3d21d 100644 --- a/lib/compiler/objcopy.zig +++ b/lib/compiler/objcopy.zig @@ -435,13 +435,13 @@ const BinaryElfOutput = struct { var program_headers = elf_hdr.iterateProgramHeaders(in); while (try program_headers.next()) |phdr| { - if (phdr.p_type == @backingInt(elf.PT.LOAD)) { + if (phdr.type == .LOAD) { const newSegment = try allocator.create(BinaryElfSegment); - newSegment.physicalAddress = phdr.p_paddr; - newSegment.virtualAddress = phdr.p_vaddr; - newSegment.fileSize = @intCast(phdr.p_filesz); - newSegment.elfOffset = phdr.p_offset; + newSegment.physicalAddress = phdr.paddr; + newSegment.virtualAddress = phdr.vaddr; + newSegment.fileSize = @intCast(phdr.filesz); + newSegment.elfOffset = phdr.offset; newSegment.binaryOffset = 0; newSegment.firstSection = null; @@ -495,8 +495,8 @@ const BinaryElfOutput = struct { return self; } - fn sectionWithinSegment(section: *BinaryElfSection, segment: elf.Elf64_Phdr) bool { - return segment.p_offset <= section.elfOffset and (segment.p_offset + segment.p_filesz) >= (section.elfOffset + section.fileSize); + fn sectionWithinSegment(section: *BinaryElfSection, segment: elf.Elf64.Phdr) bool { + return segment.offset <= section.elfOffset and (segment.offset + segment.filesz) >= (section.elfOffset + section.fileSize); } fn sectionValidForOutput(shdr: anytype) bool { diff --git a/lib/std/elf.zig b/lib/std/elf.zig index 97710d03c175cc48273b8e40c324bff122fc4caa..f2741734812a488ee400a82b7d7c4e159b61baaa 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -807,11 +807,11 @@ pub const ProgramHeaderIterator = struct { file_reader: *Io.File.Reader, index: usize = 0, - pub fn next(it: *ProgramHeaderIterator) !?Elf64_Phdr { + pub fn next(it: *ProgramHeaderIterator) !?Elf64.Phdr { if (it.index >= it.phnum) return null; defer it.index += 1; - const size: u64 = if (it.is_64) @sizeOf(Elf64_Phdr) else @sizeOf(Elf32.Phdr); + const size: u64 = if (it.is_64) @sizeOf(Elf64.Phdr) else @sizeOf(Elf32.Phdr); const offset = it.phoff + size * it.index; try it.file_reader.seekTo(offset); @@ -828,11 +828,11 @@ pub const ProgramHeaderBufferIterator = struct { buf: []const u8, index: usize = 0, - pub fn next(it: *ProgramHeaderBufferIterator) !?Elf64_Phdr { + pub fn next(it: *ProgramHeaderBufferIterator) !?Elf64.Phdr { if (it.index >= it.phnum) return null; defer it.index += 1; - const size: usize = if (it.is_64) @sizeOf(Elf64_Phdr) else @sizeOf(Elf32.Phdr); + const size: usize = if (it.is_64) @sizeOf(Elf64.Phdr) else @sizeOf(Elf32.Phdr); const offset = @as(usize, @intCast(it.phoff)) + size * it.index; var reader = Io.Reader.fixed(it.buf[offset..]); @@ -840,22 +840,22 @@ pub const ProgramHeaderBufferIterator = struct { } }; -pub fn takeProgramHeader(reader: *Io.Reader, is_64: bool, endian: Endian) !Elf64_Phdr { +pub fn takeProgramHeader(reader: *Io.Reader, is_64: bool, endian: Endian) !Elf64.Phdr { if (is_64) { - const phdr = try reader.takeStruct(Elf64_Phdr, endian); + const phdr = try reader.takeStruct(Elf64.Phdr, endian); return phdr; } const phdr = try reader.takeStruct(Elf32.Phdr, endian); return .{ - .p_type = @backingInt(phdr.type), - .p_offset = phdr.offset, - .p_vaddr = phdr.vaddr, - .p_paddr = phdr.paddr, - .p_filesz = phdr.filesz, - .p_memsz = phdr.memsz, - .p_flags = @backingInt(phdr.flags), - .p_align = phdr.@"align", + .type = phdr.type, + .offset = phdr.offset, + .vaddr = phdr.vaddr, + .paddr = phdr.paddr, + .filesz = phdr.filesz, + .memsz = phdr.memsz, + .flags = phdr.flags, + .@"align" = phdr.@"align", }; } diff --git a/lib/std/zig/system.zig b/lib/std/zig/system.zig index 083e7bb90f0ffb5acabf3470414262834e3cb0b1..4d63d0c995024fa317bb59aca5e0fc2022c63c9b 100644 --- a/lib/std/zig/system.zig +++ b/lib/std/zig/system.zig @@ -603,15 +603,15 @@ fn abiAndDynamicLinkerFromFile( var got_dyn_section: bool = false; { var it = header.iterateProgramHeaders(file_reader); - while (try it.next()) |phdr| switch (phdr.p_type) { - @backingInt(elf.PT.INTERP) => { + while (try it.next()) |phdr| switch (phdr.type) { + .INTERP => { got_dyn_section = true; if (look_for_ld) { - const p_filesz = phdr.p_filesz; + const p_filesz = phdr.filesz; if (p_filesz > result.dynamic_linker.buffer.len) return error.NameTooLong; const filesz: usize = @intCast(p_filesz); - try file_reader.seekTo(phdr.p_offset); + try file_reader.seekTo(phdr.offset); try file_reader.interface.readSliceAll(result.dynamic_linker.buffer[0..filesz]); // PT.INTERP includes a null byte in filesz. const len = filesz - 1; @@ -631,11 +631,11 @@ fn abiAndDynamicLinkerFromFile( } }, // We only need this for detecting glibc version. - @backingInt(elf.PT.DYNAMIC) => { + .DYNAMIC => { got_dyn_section = true; if (builtin.target.os.tag == .linux and result.isGnuLibC() and query.glibc_version == null) { - var dyn_it = header.iterateDynamicSection(file_reader, phdr.p_offset, phdr.p_filesz); + var dyn_it = header.iterateDynamicSection(file_reader, phdr.offset, phdr.filesz); while (try dyn_it.next()) |dyn| { if (dyn.d_tag == elf.DT_RUNPATH) { rpath_offset = dyn.d_val; diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 3f82771d536a6fcc6265b1b0b366943979d2faa7..e22680a44a450739239051ad62d27067d2efe327 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -127,7 +127,7 @@ const SectionIndexes = struct { symtab: ?u32 = null, }; -const ProgramHeaderList = std.ArrayList(elf.Elf64_Phdr); +const ProgramHeaderList = std.ArrayList(elf.Elf64.Phdr); const OptionalProgramHeaderIndex = enum(u16) { none = std.math.maxInt(u16), @@ -337,7 +337,7 @@ pub fn createEmpty( // Initialize PT.PHDR program header const p_align: u16 = switch (self.ptr_width) { .p32 => @alignOf(elf.Elf32.Phdr), - .p64 => @alignOf(elf.Elf64_Phdr), + .p64 => @alignOf(elf.Elf64.Phdr), }; const ehsize: u64 = switch (self.ptr_width) { .p32 => @sizeOf(elf.Elf32_Ehdr), @@ -345,7 +345,7 @@ pub fn createEmpty( }; const phsize: u64 = switch (self.ptr_width) { .p32 => @sizeOf(elf.Elf32.Phdr), - .p64 => @sizeOf(elf.Elf64_Phdr), + .p64 => @sizeOf(elf.Elf64.Phdr), }; const max_nphdrs = comptime getMaxNumberOfPhdrs(); const reserved: u64 = mem.alignForward(u64, padToIdeal(max_nphdrs * phsize), self.page_size); @@ -514,11 +514,11 @@ fn detectAllocCollision(self: *Elf, start: u64, size: u64) !?u64 { } for (self.phdrs.items) |phdr| { - if (phdr.p_type != @backingInt(elf.PT.LOAD)) continue; - const increased_size = padToIdeal(phdr.p_filesz); - const test_end = phdr.p_offset +| increased_size; + if (phdr.type != .LOAD) continue; + const increased_size = padToIdeal(phdr.filesz); + const test_end = phdr.offset +| increased_size; if (start < test_end) { - if (end > phdr.p_offset) return test_end; + if (end > phdr.offset) return test_end; if (test_end < std.math.maxInt(u64)) at_end = false; } } @@ -538,8 +538,8 @@ pub fn allocatedSize(self: *Elf, start: u64) u64 { if (section.sh_offset < min_pos) min_pos = section.sh_offset; } for (self.phdrs.items) |phdr| { - if (phdr.p_offset <= start) continue; - if (phdr.p_offset < min_pos) min_pos = phdr.p_offset; + if (phdr.offset <= start) continue; + if (phdr.offset < min_pos) min_pos = phdr.offset; } return min_pos - start; } @@ -1471,8 +1471,8 @@ fn writePhdrTable(self: *Elf) !void { const phdr_table = &self.phdrs.items[self.phdr_indexes.table.int().?]; log.debug("writing program headers from 0x{x} to 0x{x}", .{ - phdr_table.p_offset, - phdr_table.p_offset + phdr_table.p_filesz, + phdr_table.offset, + phdr_table.offset + phdr_table.filesz, }); switch (self.ptr_width) { @@ -1486,19 +1486,19 @@ fn writePhdrTable(self: *Elf) !void { mem.byteSwapAllFields(elf.Elf32.Phdr, phdr); } } - try self.pwriteAll(@ptrCast(buf), phdr_table.p_offset); + try self.pwriteAll(@ptrCast(buf), phdr_table.offset); }, .p64 => { - const buf = try gpa.alloc(elf.Elf64_Phdr, self.phdrs.items.len); + const buf = try gpa.alloc(elf.Elf64.Phdr, self.phdrs.items.len); defer gpa.free(buf); for (buf, 0..) |*phdr, i| { phdr.* = self.phdrs.items[i]; if (foreign_endian) { - mem.byteSwapAllFields(elf.Elf64_Phdr, phdr); + mem.byteSwapAllFields(elf.Elf64.Phdr, phdr); } } - try self.pwriteAll(@ptrCast(buf), phdr_table.p_offset); + try self.pwriteAll(@ptrCast(buf), phdr_table.offset); }, } } @@ -1581,7 +1581,7 @@ pub fn writeElfHeader(self: *Elf) !void { const entry_sym = obj.entrySymbol(self) orelse break :blk 0; break :blk @intCast(entry_sym.address(.{}, self)); } else 0; - const phdr_table_offset = if (self.phdr_indexes.table.int()) |phndx| self.phdrs.items[phndx].p_offset else 0; + const phdr_table_offset = if (self.phdr_indexes.table.int()) |phndx| self.phdrs.items[phndx].offset else 0; switch (self.ptr_width) { .p32 => { mem.writeInt(u32, hdr_buf[index..][0..4], @intCast(e_entry), endian); @@ -1623,7 +1623,7 @@ pub fn writeElfHeader(self: *Elf) !void { const e_phentsize: u16 = switch (self.ptr_width) { .p32 => @sizeOf(elf.Elf32.Phdr), - .p64 => @sizeOf(elf.Elf64_Phdr), + .p64 => @sizeOf(elf.Elf64.Phdr), }; mem.writeInt(u16, hdr_buf[index..][0..2], e_phentsize, endian); index += 2; @@ -2260,15 +2260,15 @@ fn setHashSections(self: *Elf) !void { } } -fn phdrRank(phdr: elf.Elf64_Phdr) u8 { - return switch (phdr.p_type) { - @backingInt(elf.PT.NULL) => 0, - @backingInt(elf.PT.PHDR) => 1, - @backingInt(elf.PT.INTERP) => 2, - @backingInt(elf.PT.LOAD) => 3, - @backingInt(elf.PT.DYNAMIC), @backingInt(elf.PT.TLS) => 4, - @backingInt(elf.PT.GNU_EH_FRAME) => 5, - @backingInt(elf.PT.GNU_STACK) => 6, +fn phdrRank(phdr: elf.Elf64.Phdr) u8 { + return switch (phdr.type) { + .NULL => 0, + .PHDR => 1, + .INTERP => 2, + .LOAD => 3, + .DYNAMIC, .TLS => 4, + .GNU_EH_FRAME => 5, + .GNU_STACK => 6, else => 7, }; } @@ -2282,12 +2282,12 @@ fn sortPhdrs( const Entry = struct { phndx: u16, - pub fn lessThan(program_headers: []const elf.Elf64_Phdr, lhs: @This(), rhs: @This()) bool { + pub fn lessThan(program_headers: []const elf.Elf64.Phdr, lhs: @This(), rhs: @This()) bool { const lhs_phdr = program_headers[lhs.phndx]; const rhs_phdr = program_headers[rhs.phndx]; const lhs_rank = phdrRank(lhs_phdr); const rhs_rank = phdrRank(rhs_phdr); - if (lhs_rank == rhs_rank) return lhs_phdr.p_vaddr < rhs_phdr.p_vaddr; + if (lhs_rank == rhs_rank) return lhs_phdr.vaddr < rhs_phdr.vaddr; return lhs_rank < rhs_rank; } }; @@ -2299,7 +2299,7 @@ fn sortPhdrs( } // The `@as` here works around a bug in the C backend. - mem.sort(Entry, entries, @as([]const elf.Elf64_Phdr, phdrs.items), Entry.lessThan); + mem.sort(Entry, entries, @as([]const elf.Elf64.Phdr, phdrs.items), Entry.lessThan); const backlinks = try gpa.alloc(u16, entries.len); defer gpa.free(backlinks); @@ -2673,10 +2673,10 @@ fn allocatePhdrTable(self: *Elf) error{OutOfMemory}!void { }; const phsize: u64 = switch (self.ptr_width) { .p32 => @sizeOf(elf.Elf32.Phdr), - .p64 => @sizeOf(elf.Elf64_Phdr), + .p64 => @sizeOf(elf.Elf64.Phdr), }; const needed_size = self.phdrs.items.len * phsize; - const available_space = self.allocatedSize(phdr_table.p_offset); + const available_space = self.allocatedSize(phdr_table.offset); if (needed_size > available_space) { // In this case, we have two options: @@ -2689,10 +2689,10 @@ fn allocatePhdrTable(self: *Elf) error{OutOfMemory}!void { err.addNote("required 0x{x}, available 0x{x}", .{ needed_size, available_space }); } - phdr_table_load.p_filesz = needed_size + ehsize; - phdr_table_load.p_memsz = needed_size + ehsize; - phdr_table.p_filesz = needed_size; - phdr_table.p_memsz = needed_size; + phdr_table_load.filesz = needed_size + ehsize; + phdr_table_load.memsz = needed_size + ehsize; + phdr_table.filesz = needed_size; + phdr_table.memsz = needed_size; } /// Allocates alloc sections and creates load segments for sections @@ -2758,7 +2758,7 @@ pub fn allocateAllocSections(self: *Elf) !void { // of any section that is contained in a cover and use it to align // the start address of the segement (and first section). const phdr_table = &self.phdrs.items[self.phdr_indexes.table_load.int().?]; - var addr = phdr_table.p_vaddr + phdr_table.p_memsz; + var addr = phdr_table.vaddr + phdr_table.memsz; for (covers) |cover| { if (cover.items.len == 0) continue; @@ -2819,12 +2819,12 @@ pub fn allocateAllocSections(self: *Elf) !void { const first = slice.items(.shdr)[cover.items[0]]; const phndx = self.getPhdr(.{ .type = @backingInt(elf.PT.LOAD), .flags = shdrToPhdrFlags(first.sh_flags) }).unwrap().?; const phdr = &self.phdrs.items[phndx.int()]; - const allocated_size = self.allocatedSize(phdr.p_offset); + const allocated_size = self.allocatedSize(phdr.offset); if (filesz > allocated_size) { - const old_offset = phdr.p_offset; - phdr.p_offset = 0; + const old_offset = phdr.offset; + phdr.offset = 0; var new_offset = try self.findFreeSpace(filesz, @"align"); - phdr.p_offset = new_offset; + phdr.offset = new_offset; log.debug("moving phdr({d}) from 0x{x} to 0x{x}", .{ phndx, old_offset, new_offset }); @@ -2854,11 +2854,11 @@ pub fn allocateAllocSections(self: *Elf) !void { } } - phdr.p_vaddr = first.sh_addr; - phdr.p_paddr = first.sh_addr; - phdr.p_memsz = memsz; - phdr.p_filesz = filesz; - phdr.p_align = @"align"; + phdr.vaddr = first.sh_addr; + phdr.paddr = first.sh_addr; + phdr.memsz = memsz; + phdr.filesz = filesz; + phdr.@"align" = @"align"; addr = mem.alignForward(u64, addr, self.page_size); } @@ -2902,12 +2902,12 @@ fn allocateSpecialPhdrs(self: *Elf) void { if (pair[0].int()) |index| { const shdr = slice.items(.shdr)[pair[1].?]; const phdr = &self.phdrs.items[index]; - phdr.p_align = shdr.sh_addralign; - phdr.p_offset = shdr.sh_offset; - phdr.p_vaddr = shdr.sh_addr; - phdr.p_paddr = shdr.sh_addr; - phdr.p_filesz = shdr.sh_size; - phdr.p_memsz = shdr.sh_size; + phdr.@"align" = shdr.sh_addralign; + phdr.offset = shdr.sh_offset; + phdr.vaddr = shdr.sh_addr; + phdr.paddr = shdr.sh_addr; + phdr.filesz = shdr.sh_size; + phdr.memsz = shdr.sh_size; } } @@ -2924,25 +2924,25 @@ fn allocateSpecialPhdrs(self: *Elf) void { shndx += 1; continue; } - phdr.p_offset = shdr.sh_offset; - phdr.p_vaddr = shdr.sh_addr; - phdr.p_paddr = shdr.sh_addr; - phdr.p_align = shdr.sh_addralign; + phdr.offset = shdr.sh_offset; + phdr.vaddr = shdr.sh_addr; + phdr.paddr = shdr.sh_addr; + phdr.@"align" = shdr.sh_addralign; shndx += 1; - phdr.p_align = @max(phdr.p_align, shdr.sh_addralign); + phdr.@"align" = @max(phdr.@"align", shdr.sh_addralign); if (shdr.sh_type != elf.SHT_NOBITS) { - phdr.p_filesz = shdr.sh_offset + shdr.sh_size - phdr.p_offset; + phdr.filesz = shdr.sh_offset + shdr.sh_size - phdr.offset; } - phdr.p_memsz = shdr.sh_addr + shdr.sh_size - phdr.p_vaddr; + phdr.memsz = shdr.sh_addr + shdr.sh_size - phdr.vaddr; while (shndx < shdrs.len) : (shndx += 1) { const next = shdrs[shndx]; if (next.sh_flags & elf.SHF_TLS == 0) break; - phdr.p_align = @max(phdr.p_align, next.sh_addralign); + phdr.@"align" = @max(phdr.@"align", next.sh_addralign); if (next.sh_type != elf.SHT_NOBITS) { - phdr.p_filesz = next.sh_offset + next.sh_size - phdr.p_offset; + phdr.filesz = next.sh_offset + next.sh_size - phdr.offset; } - phdr.p_memsz = next.sh_addr + next.sh_size - phdr.p_vaddr; + phdr.memsz = next.sh_addr + next.sh_size - phdr.vaddr; } } } @@ -3347,16 +3347,16 @@ pub fn archPtrWidthBytes(self: Elf) u8 { return @intCast(@divExact(self.getTarget().ptrBitWidth(), 8)); } -fn phdrTo32(phdr: elf.Elf64_Phdr) elf.Elf32.Phdr { +fn phdrTo32(phdr: elf.Elf64.Phdr) elf.Elf32.Phdr { return .{ - .type = @fromBackingInt(phdr.p_type), - .flags = @fromBackingInt(phdr.p_flags), - .offset = @intCast(phdr.p_offset), - .vaddr = @intCast(phdr.p_vaddr), - .paddr = @intCast(phdr.p_paddr), - .filesz = @intCast(phdr.p_filesz), - .memsz = @intCast(phdr.p_memsz), - .@"align" = @intCast(phdr.p_align), + .type = phdr.type, + .flags = phdr.flags, + .offset = @intCast(phdr.offset), + .vaddr = @intCast(phdr.vaddr), + .paddr = @intCast(phdr.paddr), + .filesz = @intCast(phdr.filesz), + .memsz = @intCast(phdr.memsz), + .@"align" = @intCast(phdr.@"align"), }; } @@ -3397,7 +3397,7 @@ fn getPhdr(self: *Elf, opts: struct { if (self.phdr_indexes.table_load.int()) |index| { if (phndx == index) continue; } - if (phdr.p_type == opts.type and phdr.p_flags == opts.flags) + if (@backingInt(phdr.type) == opts.type and @backingInt(phdr.flags) == opts.flags) return @fromBackingInt(@intCast(phndx)); } return .none; @@ -3415,14 +3415,14 @@ fn addPhdr(self: *Elf, opts: struct { const gpa = self.base.comp.gpa; const index: ProgramHeaderIndex = @fromBackingInt(@intCast(self.phdrs.items.len)); try self.phdrs.append(gpa, .{ - .p_type = opts.type, - .p_flags = opts.flags, - .p_offset = opts.offset, - .p_vaddr = opts.addr, - .p_paddr = opts.addr, - .p_filesz = opts.filesz, - .p_memsz = opts.memsz, - .p_align = opts.@"align", + .type = @fromBackingInt(opts.type), + .flags = @fromBackingInt(opts.flags), + .offset = opts.offset, + .vaddr = opts.addr, + .paddr = opts.addr, + .filesz = opts.filesz, + .memsz = opts.memsz, + .@"align" = opts.@"align", }); return index; } @@ -3673,9 +3673,9 @@ pub fn tpAddress(self: *Elf) i64 { const index = self.phdr_indexes.tls.int() orelse return 0; const phdr = self.phdrs.items[index]; const addr = switch (self.getTarget().cpu.arch) { - .x86_64 => mem.alignForward(u64, phdr.p_vaddr + phdr.p_memsz, phdr.p_align), - .aarch64, .aarch64_be => mem.alignBackward(u64, phdr.p_vaddr - 16, phdr.p_align), - .riscv64, .riscv64be => phdr.p_vaddr, + .x86_64 => mem.alignForward(u64, phdr.vaddr + phdr.memsz, phdr.@"align"), + .aarch64, .aarch64_be => mem.alignBackward(u64, phdr.vaddr - 16, phdr.@"align"), + .riscv64, .riscv64be => phdr.vaddr, else => |arch| std.debug.panic("TODO implement getTpAddress for {s}", .{@tagName(arch)}), }; return @intCast(addr); @@ -3684,13 +3684,13 @@ pub fn tpAddress(self: *Elf) i64 { pub fn dtpAddress(self: *Elf) i64 { const index = self.phdr_indexes.tls.int() orelse return 0; const phdr = self.phdrs.items[index]; - return @intCast(phdr.p_vaddr); + return @intCast(phdr.vaddr); } pub fn tlsAddress(self: *Elf) i64 { const index = self.phdr_indexes.tls.int() orelse return 0; const phdr = self.phdrs.items[index]; - return @intCast(phdr.p_vaddr); + return @intCast(phdr.vaddr); } pub fn getShString(self: Elf, off: u32) [:0]const u8 { @@ -3886,10 +3886,10 @@ fn formatShdrFlags(sh_flags: u64, writer: *std.Io.Writer) std.Io.Writer.Error!vo const FormatPhdr = struct { elf_file: *Elf, - phdr: elf.Elf64_Phdr, + phdr: elf.Elf64.Phdr, }; -fn fmtPhdr(self: *Elf, phdr: elf.Elf64_Phdr) std.fmt.Alt(FormatPhdr, formatPhdr) { +fn fmtPhdr(self: *Elf, phdr: elf.Elf64.Phdr) std.fmt.Alt(FormatPhdr, formatPhdr) { return .{ .data = .{ .phdr = phdr, .elf_file = self, @@ -3898,28 +3898,28 @@ fn fmtPhdr(self: *Elf, phdr: elf.Elf64_Phdr) std.fmt.Alt(FormatPhdr, formatPhdr) fn formatPhdr(ctx: FormatPhdr, writer: *std.Io.Writer) std.Io.Writer.Error!void { const phdr = ctx.phdr; - const write = phdr.p_flags & elf.PF_W != 0; - const read = phdr.p_flags & elf.PF_R != 0; - const exec = phdr.p_flags & elf.PF_X != 0; + const write = phdr.flags.W; + const read = phdr.flags.R; + const exec = phdr.flags.X; var flags: [3]u8 = @splat('_'); if (exec) flags[0] = 'X'; if (write) flags[1] = 'W'; if (read) flags[2] = 'R'; - const p_type = switch (phdr.p_type) { - @backingInt(elf.PT.LOAD) => "LOAD", - @backingInt(elf.PT.TLS) => "TLS", - @backingInt(elf.PT.GNU_EH_FRAME) => "GNU_EH_FRAME", - @backingInt(elf.PT.GNU_STACK) => "GNU_STACK", - @backingInt(elf.PT.DYNAMIC) => "DYNAMIC", - @backingInt(elf.PT.INTERP) => "INTERP", - @backingInt(elf.PT.NULL) => "NULL", - @backingInt(elf.PT.PHDR) => "PHDR", - @backingInt(elf.PT.NOTE) => "NOTE", + const p_type = switch (phdr.type) { + .LOAD => "LOAD", + .TLS => "TLS", + .GNU_EH_FRAME => "GNU_EH_FRAME", + .GNU_STACK => "GNU_STACK", + .DYNAMIC => "DYNAMIC", + .INTERP => "INTERP", + .NULL => "NULL", + .PHDR => "PHDR", + .NOTE => "NOTE", else => "UNKNOWN", }; try writer.print("{s} : {s} : @{x} ({x}) : align({x}) : filesz({x}) : memsz({x})", .{ - p_type, flags, phdr.p_offset, phdr.p_vaddr, - phdr.p_align, phdr.p_filesz, phdr.p_memsz, + p_type, flags, phdr.offset, phdr.vaddr, + phdr.@"align", phdr.filesz, phdr.memsz, }); } -- 2.54.0 From 9bc9544bc8df2b0fe5ad82bd5459a9ce7ca55bac Mon Sep 17 00:00:00 2001 From: David Senoner Date: Thu, 30 Jul 2026 21:05:04 +0200 Subject: [PATCH 5/5] elf: remove deprecated Phdr structs --- lib/std/elf.zig | 28 ---------------------------- 1 file changed, 28 deletions(-) diff --git a/lib/std/elf.zig b/lib/std/elf.zig index f2741734812a488ee400a82b7d7c4e159b61baaa..e4e905cea761ff6cbfbc81bcbd2fc44fdc8704ad 100644 --- a/lib/std/elf.zig +++ b/lib/std/elf.zig @@ -1235,28 +1235,6 @@ pub const Elf64_Ehdr = extern struct { e_shnum: Half, e_shstrndx: Half, }; -/// Deprecated, use `std.elf.Elf32.Phdr` -pub const Elf32_Phdr = extern struct { - p_type: Word, - p_offset: Elf32_Off, - p_vaddr: Elf32_Addr, - p_paddr: Elf32_Addr, - p_filesz: Word, - p_memsz: Word, - p_flags: Word, - p_align: Word, -}; -/// Deprecated, use `std.elf.Elf64.Phdr` -pub const Elf64_Phdr = extern struct { - p_type: Word, - p_flags: Word, - p_offset: Elf64_Off, - p_vaddr: Elf64_Addr, - p_paddr: Elf64_Addr, - p_filesz: Elf64_Xword, - p_memsz: Elf64_Xword, - p_align: Elf64_Xword, -}; /// Deprecated, use `std.elf.Elf32.Shdr` pub const Elf32_Shdr = extern struct { sh_name: Word, @@ -1527,12 +1505,6 @@ pub const Ehdr = switch (@sizeOf(usize)) { 8 => Elf64_Ehdr, else => @compileError("expected pointer size of 32 or 64"), }; -/// Deprecated, use `std.elf.ElfN.Phdr` -pub const Phdr = switch (@sizeOf(usize)) { - 4 => Elf32_Phdr, - 8 => Elf64_Phdr, - else => @compileError("expected pointer size of 32 or 64"), -}; pub const Dyn = switch (@sizeOf(usize)) { 4 => Elf32_Dyn, 8 => Elf64_Dyn, -- 2.54.0