authorgravatar for seda18@rolmail.netDavid Senoner <seda18@rolmail.net> 2026-07-30 18:03:19+02:00
committergravatar for seda18@rolmail.netDavid Senoner <seda18@rolmail.net> 2026-07-30 21:23:58+02:00
log8d888624567d6c5170ddbeda5f312c3b1762261b
treeb64495a7173187d7e103e91e03d3a029e1862869
parentea006188aaf110a33cbf0ca00888306f263cce98

elf: remove usages of deprecated elf.Phdr


6 files changed, 44 insertions(+), 44 deletions(-)

lib/std/dynamic_library.zig+16-16
......@@ -261,10 +261,10 @@ pub const ElfDynLib = struct {
261261 i += 1;
262262 ph_addr += eh.e_phentsize;
263263 }) {
264 const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));
265 switch (ph.p_type) {
266 @backingInt(elf.PT.LOAD) => virt_addr_end = @max(virt_addr_end, ph.p_vaddr + ph.p_memsz),
267 @backingInt(elf.PT.DYNAMIC) => maybe_dynv = @as([*]usize, @ptrFromInt(elf_addr + ph.p_offset)),
264 const ph = @as(*elf.ElfN.Phdr, @ptrFromInt(ph_addr));
265 switch (ph.type) {
266 .LOAD => virt_addr_end = @max(virt_addr_end, ph.vaddr + ph.memsz),
267 .DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(elf_addr + ph.offset)),
268268 else => {},
269269 }
270270 }
......@@ -292,23 +292,23 @@ pub const ElfDynLib = struct {
292292 i += 1;
293293 ph_addr += eh.e_phentsize;
294294 }) {
295 const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));
296 switch (ph.p_type) {
297 @backingInt(elf.PT.LOAD) => {
295 const ph = @as(*elf.ElfN.Phdr, @ptrFromInt(ph_addr));
296 switch (ph.type) {
297 .LOAD => {
298298 // The VirtAddr may not be page-aligned; in such case there will be
299299 // extra nonsense mapped before/after the VirtAddr,MemSiz
300 const aligned_addr = (base + ph.p_vaddr) & ~(@as(usize, page_size) - 1);
301 const extra_bytes = (base + ph.p_vaddr) - aligned_addr;
302 const extended_memsz = mem.alignForward(usize, ph.p_memsz + extra_bytes, page_size);
300 const aligned_addr = (base + ph.vaddr) & ~(@as(usize, page_size) - 1);
301 const extra_bytes = (base + ph.vaddr) - aligned_addr;
302 const extended_memsz = mem.alignForward(usize, ph.memsz + extra_bytes, page_size);
303303 const ptr = @as([*]align(std.heap.page_size_min) u8, @ptrFromInt(aligned_addr));
304 const prot = elfToProt(ph.p_flags);
304 const prot = elfToProt(ph.flags);
305305 _ = try posix.mmap(
306306 ptr,
307307 extended_memsz,
308308 prot,
309309 .{ .TYPE = .PRIVATE, .FIXED = true },
310310 file.handle,
311 ph.p_offset - extra_bytes,
311 ph.offset - extra_bytes,
312312 );
313313 },
314314 else => {},
......@@ -517,11 +517,11 @@ pub const ElfDynLib = struct {
517517 return null;
518518 }
519519
520 fn elfToProt(elf_prot: u64) posix.PROT {
520 fn elfToProt(elf_prot: elf.PF) posix.PROT {
521521 return .{
522 .READ = (elf_prot & elf.PF_R) != 0,
523 .WRITE = (elf_prot & elf.PF_W) != 0,
524 .EXEC = (elf_prot & elf.PF_X) != 0,
522 .READ = elf_prot.R,
523 .WRITE = elf_prot.W,
524 .EXEC = elf_prot.X,
525525 };
526526 }
527527};
lib/std/os/emscripten.zig+1-1
......@@ -730,7 +730,7 @@ pub const clock_t = i32;
730730pub const dl_phdr_info = extern struct {
731731 addr: usize,
732732 name: ?[*:0]const u8,
733 phdr: [*]std.elf.Phdr,
733 phdr: [*]std.elf.ElfN.Phdr,
734734 phnum: u16,
735735};
736736
lib/std/os/linux/tls.zig+11-11
......@@ -480,17 +480,17 @@ pub fn getThreadPointer() usize {
480480 };
481481}
482482
483fn computeAreaDesc(phdrs: []elf.Phdr) void {
483fn computeAreaDesc(phdrs: []elf.ElfN.Phdr) void {
484484 @setRuntimeSafety(false);
485485 @disableInstrumentation();
486486
487 var tls_phdr: ?*elf.Phdr = null;
487 var tls_phdr: ?*elf.ElfN.Phdr = null;
488488 var img_base: usize = 0;
489489
490490 for (phdrs) |*phdr| {
491 switch (phdr.p_type) {
492 @backingInt(elf.PT.PHDR) => img_base = @intFromPtr(phdrs.ptr) - phdr.p_vaddr,
493 @backingInt(elf.PT.TLS) => tls_phdr = phdr,
491 switch (phdr.type) {
492 .PHDR => img_base = @intFromPtr(phdrs.ptr) - phdr.vaddr,
493 .TLS => tls_phdr = phdr,
494494 else => {},
495495 }
496496 }
......@@ -500,12 +500,12 @@ fn computeAreaDesc(phdrs: []elf.Phdr) void {
500500 var block_size: usize = undefined;
501501
502502 if (tls_phdr) |phdr| {
503 align_factor = phdr.p_align;
503 align_factor = phdr.@"align";
504504
505 // The effective size in memory is represented by `p_memsz`; the length of the data stored
506 // in the `PT.TLS` segment is `p_filesz` and may be less than the former.
507 block_init = @as([*]u8, @ptrFromInt(img_base + phdr.p_vaddr))[0..phdr.p_filesz];
508 block_size = phdr.p_memsz;
505 // The effective size in memory is represented by `memsz`; the length of the data stored
506 // in the `PT.TLS` segment is `filesz` and may be less than the former.
507 block_init = @as([*]u8, @ptrFromInt(img_base + phdr.vaddr))[0..phdr.filesz];
508 block_size = phdr.memsz;
509509 } else {
510510 align_factor = @alignOf(usize);
511511
......@@ -651,7 +651,7 @@ var main_thread_area_buffer: [0x1000]u8 align(page_size_min) = undefined;
651651
652652/// Computes the layout of the static TLS area, allocates the area, initializes all of its fields,
653653/// and assigns the architecture-specific value to the TP register.
654pub fn initStatic(phdrs: []elf.Phdr) void {
654pub fn initStatic(phdrs: []elf.ElfN.Phdr) void {
655655 @setRuntimeSafety(false);
656656 @disableInstrumentation();
657657
lib/std/os/linux/vdso.zig+5-5
......@@ -19,14 +19,14 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
1919 i += 1;
2020 ph_addr += eh.e_phentsize;
2121 }) {
22 const this_ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));
23 switch (this_ph.p_type) {
22 const this_ph = @as(*elf.ElfN.Phdr, @ptrFromInt(ph_addr));
23 switch (this_ph.type) {
2424 // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half
25 // of the memory space (e.g. p_vaddr = 0xffffffffff700000 on WSL1).
25 // of the memory space (e.g. vaddr = 0xffffffffff700000 on WSL1).
2626 // Wrapping operations are used on this line as well as subsequent calculations relative to base
2727 // (lines 47, 78) to ensure no overflow check is tripped.
28 @backingInt(elf.PT.LOAD) => base = vdso_addr +% this_ph.p_offset -% this_ph.p_vaddr,
29 @backingInt(elf.PT.DYNAMIC) => maybe_dynv = @as([*]usize, @ptrFromInt(vdso_addr + this_ph.p_offset)),
28 .LOAD => base = vdso_addr +% this_ph.offset -% this_ph.vaddr,
29 .DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(vdso_addr + this_ph.offset)),
3030 else => {},
3131 }
3232 }
lib/std/pie.zig+3-3
......@@ -293,7 +293,7 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {
293293 };
294294}
295295
296pub fn relocate(phdrs: []const elf.Phdr) void {
296pub fn relocate(phdrs: []const elf.ElfN.Phdr) void {
297297 @setRuntimeSafety(false);
298298 @disableInstrumentation();
299299
......@@ -303,8 +303,8 @@ pub fn relocate(phdrs: []const elf.Phdr) void {
303303 // the theoretical load addresses for the `_DYNAMIC` symbol.
304304 const base_addr = base: {
305305 for (phdrs) |*phdr| {
306 if (phdr.p_type != @backingInt(elf.PT.DYNAMIC)) continue;
307 break :base @intFromPtr(dynv) - phdr.p_vaddr;
306 if (phdr.type != .DYNAMIC) continue;
307 break :base @intFromPtr(dynv) - phdr.vaddr;
308308 }
309309 // This is not supposed to happen for well-formed binaries.
310310 @trap();
lib/std/start.zig+8-8
......@@ -589,7 +589,7 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn {
589589 else => continue,
590590 }
591591 }
592 break :init @as([*]elf.Phdr, @ptrFromInt(at_phdr))[0..at_phnum];
592 break :init @as([*]elf.ElfN.Phdr, @ptrFromInt(at_phdr))[0..at_phnum];
593593 };
594594
595595 // 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 {
645645 std.process.exit(callMainWithArgs(argc, argv, envp));
646646}
647647
648fn expandStackSize(phdrs: []elf.Phdr) void {
648fn expandStackSize(phdrs: []elf.ElfN.Phdr) void {
649649 @disableInstrumentation();
650650 for (phdrs) |*phdr| {
651 switch (phdr.p_type) {
652 @backingInt(elf.PT.GNU_STACK) => {
653 if (phdr.p_memsz == 0) break;
654 assert(phdr.p_memsz % std.heap.page_size_min == 0);
651 switch (phdr.type) {
652 .GNU_STACK => {
653 if (phdr.memsz == 0) break;
654 assert(phdr.memsz % std.heap.page_size_min == 0);
655655
656656 // Silently fail if we are unable to get limits.
657657 const limits = std.posix.getrlimit(.STACK) catch break;
658658
659659 // Clamp to limits.max .
660 const wanted_stack_size = @min(phdr.p_memsz, limits.max);
660 const wanted_stack_size = @min(phdr.memsz, limits.max);
661661
662662 if (wanted_stack_size > limits.cur) {
663663 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
702702 .linux => {
703703 const at_phdr = std.c.getauxval(elf.AT_PHDR);
704704 const at_phnum = std.c.getauxval(elf.AT_PHNUM);
705 const phdrs = (@as([*]elf.Phdr, @ptrFromInt(at_phdr)))[0..at_phnum];
705 const phdrs = (@as([*]elf.ElfN.Phdr, @ptrFromInt(at_phdr)))[0..at_phnum];
706706 expandStackSize(phdrs);
707707 },
708708 .windows => {