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 {...@@ -261,10 +261,10 @@ pub const ElfDynLib = struct {
261 i += 1;261 i += 1;
262 ph_addr += eh.e_phentsize;262 ph_addr += eh.e_phentsize;
263 }) {263 }) {
264 const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));264 const ph = @as(*elf.ElfN.Phdr, @ptrFromInt(ph_addr));
265 switch (ph.p_type) {265 switch (ph.type) {
266 @backingInt(elf.PT.LOAD) => virt_addr_end = @max(virt_addr_end, ph.p_vaddr + ph.p_memsz),266 .LOAD => virt_addr_end = @max(virt_addr_end, ph.vaddr + ph.memsz),
267 @backingInt(elf.PT.DYNAMIC) => maybe_dynv = @as([*]usize, @ptrFromInt(elf_addr + ph.p_offset)),267 .DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(elf_addr + ph.offset)),
268 else => {},268 else => {},
269 }269 }
270 }270 }
...@@ -292,23 +292,23 @@ pub const ElfDynLib = struct {...@@ -292,23 +292,23 @@ pub const ElfDynLib = struct {
292 i += 1;292 i += 1;
293 ph_addr += eh.e_phentsize;293 ph_addr += eh.e_phentsize;
294 }) {294 }) {
295 const ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));295 const ph = @as(*elf.ElfN.Phdr, @ptrFromInt(ph_addr));
296 switch (ph.p_type) {296 switch (ph.type) {
297 @backingInt(elf.PT.LOAD) => {297 .LOAD => {
298 // The VirtAddr may not be page-aligned; in such case there will be298 // The VirtAddr may not be page-aligned; in such case there will be
299 // extra nonsense mapped before/after the VirtAddr,MemSiz299 // extra nonsense mapped before/after the VirtAddr,MemSiz
300 const aligned_addr = (base + ph.p_vaddr) & ~(@as(usize, page_size) - 1);300 const aligned_addr = (base + ph.vaddr) & ~(@as(usize, page_size) - 1);
301 const extra_bytes = (base + ph.p_vaddr) - aligned_addr;301 const extra_bytes = (base + ph.vaddr) - aligned_addr;
302 const extended_memsz = mem.alignForward(usize, ph.p_memsz + extra_bytes, page_size);302 const extended_memsz = mem.alignForward(usize, ph.memsz + extra_bytes, page_size);
303 const ptr = @as([*]align(std.heap.page_size_min) u8, @ptrFromInt(aligned_addr));303 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);
305 _ = try posix.mmap(305 _ = try posix.mmap(
306 ptr,306 ptr,
307 extended_memsz,307 extended_memsz,
308 prot,308 prot,
309 .{ .TYPE = .PRIVATE, .FIXED = true },309 .{ .TYPE = .PRIVATE, .FIXED = true },
310 file.handle,310 file.handle,
311 ph.p_offset - extra_bytes,311 ph.offset - extra_bytes,
312 );312 );
313 },313 },
314 else => {},314 else => {},
...@@ -517,11 +517,11 @@ pub const ElfDynLib = struct {...@@ -517,11 +517,11 @@ pub const ElfDynLib = struct {
517 return null;517 return null;
518 }518 }
519519
520 fn elfToProt(elf_prot: u64) posix.PROT {520 fn elfToProt(elf_prot: elf.PF) posix.PROT {
521 return .{521 return .{
522 .READ = (elf_prot & elf.PF_R) != 0,522 .READ = elf_prot.R,
523 .WRITE = (elf_prot & elf.PF_W) != 0,523 .WRITE = elf_prot.W,
524 .EXEC = (elf_prot & elf.PF_X) != 0,524 .EXEC = elf_prot.X,
525 };525 };
526 }526 }
527};527};
lib/std/os/emscripten.zig+1-1
...@@ -730,7 +730,7 @@ pub const clock_t = i32;...@@ -730,7 +730,7 @@ pub const clock_t = i32;
730pub const dl_phdr_info = extern struct {730pub const dl_phdr_info = extern struct {
731 addr: usize,731 addr: usize,
732 name: ?[*:0]const u8,732 name: ?[*:0]const u8,
733 phdr: [*]std.elf.Phdr,733 phdr: [*]std.elf.ElfN.Phdr,
734 phnum: u16,734 phnum: u16,
735};735};
736736
lib/std/os/linux/tls.zig+11-11
...@@ -480,17 +480,17 @@ pub fn getThreadPointer() usize {...@@ -480,17 +480,17 @@ pub fn getThreadPointer() usize {
480 };480 };
481}481}
482482
483fn computeAreaDesc(phdrs: []elf.Phdr) void {483fn computeAreaDesc(phdrs: []elf.ElfN.Phdr) void {
484 @setRuntimeSafety(false);484 @setRuntimeSafety(false);
485 @disableInstrumentation();485 @disableInstrumentation();
486486
487 var tls_phdr: ?*elf.Phdr = null;487 var tls_phdr: ?*elf.ElfN.Phdr = null;
488 var img_base: usize = 0;488 var img_base: usize = 0;
489489
490 for (phdrs) |*phdr| {490 for (phdrs) |*phdr| {
491 switch (phdr.p_type) {491 switch (phdr.type) {
492 @backingInt(elf.PT.PHDR) => img_base = @intFromPtr(phdrs.ptr) - phdr.p_vaddr,492 .PHDR => img_base = @intFromPtr(phdrs.ptr) - phdr.vaddr,
493 @backingInt(elf.PT.TLS) => tls_phdr = phdr,493 .TLS => tls_phdr = phdr,
494 else => {},494 else => {},
495 }495 }
496 }496 }
...@@ -500,12 +500,12 @@ fn computeAreaDesc(phdrs: []elf.Phdr) void {...@@ -500,12 +500,12 @@ fn computeAreaDesc(phdrs: []elf.Phdr) void {
500 var block_size: usize = undefined;500 var block_size: usize = undefined;
501501
502 if (tls_phdr) |phdr| {502 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 stored505 // The effective size in memory is represented by `memsz`; the length of the data stored
506 // in the `PT.TLS` segment is `p_filesz` and may be less than the former.506 // in the `PT.TLS` segment is `filesz` and may be less than the former.
507 block_init = @as([*]u8, @ptrFromInt(img_base + phdr.p_vaddr))[0..phdr.p_filesz];507 block_init = @as([*]u8, @ptrFromInt(img_base + phdr.vaddr))[0..phdr.filesz];
508 block_size = phdr.p_memsz;508 block_size = phdr.memsz;
509 } else {509 } else {
510 align_factor = @alignOf(usize);510 align_factor = @alignOf(usize);
511511
...@@ -651,7 +651,7 @@ var main_thread_area_buffer: [0x1000]u8 align(page_size_min) = undefined;...@@ -651,7 +651,7 @@ var main_thread_area_buffer: [0x1000]u8 align(page_size_min) = undefined;
651651
652/// Computes the layout of the static TLS area, allocates the area, initializes all of its fields,652/// Computes the layout of the static TLS area, allocates the area, initializes all of its fields,
653/// and assigns the architecture-specific value to the TP register.653/// 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 {
655 @setRuntimeSafety(false);655 @setRuntimeSafety(false);
656 @disableInstrumentation();656 @disableInstrumentation();
657657
lib/std/os/linux/vdso.zig+5-5
...@@ -19,14 +19,14 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {...@@ -19,14 +19,14 @@ pub fn lookup(vername: []const u8, name: []const u8) usize {
19 i += 1;19 i += 1;
20 ph_addr += eh.e_phentsize;20 ph_addr += eh.e_phentsize;
21 }) {21 }) {
22 const this_ph = @as(*elf.Phdr, @ptrFromInt(ph_addr));22 const this_ph = @as(*elf.ElfN.Phdr, @ptrFromInt(ph_addr));
23 switch (this_ph.p_type) {23 switch (this_ph.type) {
24 // On WSL1 as well as older kernels, the VDSO ELF image is pre-linked in the upper half24 // 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).
26 // Wrapping operations are used on this line as well as subsequent calculations relative to base26 // Wrapping operations are used on this line as well as subsequent calculations relative to base
27 // (lines 47, 78) to ensure no overflow check is tripped.27 // (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,28 .LOAD => base = vdso_addr +% this_ph.offset -% this_ph.vaddr,
29 @backingInt(elf.PT.DYNAMIC) => maybe_dynv = @as([*]usize, @ptrFromInt(vdso_addr + this_ph.p_offset)),29 .DYNAMIC => maybe_dynv = @as([*]usize, @ptrFromInt(vdso_addr + this_ph.offset)),
30 else => {},30 else => {},
31 }31 }
32 }32 }
lib/std/pie.zig+3-3
...@@ -293,7 +293,7 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {...@@ -293,7 +293,7 @@ inline fn getDynamicSymbol() [*]const elf.Dyn {
293 };293 };
294}294}
295295
296pub fn relocate(phdrs: []const elf.Phdr) void {296pub fn relocate(phdrs: []const elf.ElfN.Phdr) void {
297 @setRuntimeSafety(false);297 @setRuntimeSafety(false);
298 @disableInstrumentation();298 @disableInstrumentation();
299299
...@@ -303,8 +303,8 @@ pub fn relocate(phdrs: []const elf.Phdr) void {...@@ -303,8 +303,8 @@ pub fn relocate(phdrs: []const elf.Phdr) void {
303 // the theoretical load addresses for the `_DYNAMIC` symbol.303 // the theoretical load addresses for the `_DYNAMIC` symbol.
304 const base_addr = base: {304 const base_addr = base: {
305 for (phdrs) |*phdr| {305 for (phdrs) |*phdr| {
306 if (phdr.p_type != @backingInt(elf.PT.DYNAMIC)) continue;306 if (phdr.type != .DYNAMIC) continue;
307 break :base @intFromPtr(dynv) - phdr.p_vaddr;307 break :base @intFromPtr(dynv) - phdr.vaddr;
308 }308 }
309 // This is not supposed to happen for well-formed binaries.309 // This is not supposed to happen for well-formed binaries.
310 @trap();310 @trap();
lib/std/start.zig+8-8
...@@ -589,7 +589,7 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn {...@@ -589,7 +589,7 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn {
589 else => continue,589 else => continue,
590 }590 }
591 }591 }
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];
593 };593 };
594594
595 // Apply the initial relocations as early as possible in the startup process. We cannot595 // 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 {...@@ -645,19 +645,19 @@ fn posixCallMainAndExit(argc_argv_ptr: [*]usize) callconv(.c) noreturn {
645 std.process.exit(callMainWithArgs(argc, argv, envp));645 std.process.exit(callMainWithArgs(argc, argv, envp));
646}646}
647647
648fn expandStackSize(phdrs: []elf.Phdr) void {648fn expandStackSize(phdrs: []elf.ElfN.Phdr) void {
649 @disableInstrumentation();649 @disableInstrumentation();
650 for (phdrs) |*phdr| {650 for (phdrs) |*phdr| {
651 switch (phdr.p_type) {651 switch (phdr.type) {
652 @backingInt(elf.PT.GNU_STACK) => {652 .GNU_STACK => {
653 if (phdr.p_memsz == 0) break;653 if (phdr.memsz == 0) break;
654 assert(phdr.p_memsz % std.heap.page_size_min == 0);654 assert(phdr.memsz % std.heap.page_size_min == 0);
655655
656 // Silently fail if we are unable to get limits.656 // Silently fail if we are unable to get limits.
657 const limits = std.posix.getrlimit(.STACK) catch break;657 const limits = std.posix.getrlimit(.STACK) catch break;
658658
659 // Clamp to limits.max .659 // 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
662 if (wanted_stack_size > limits.cur) {662 if (wanted_stack_size > limits.cur) {
663 std.posix.setrlimit(.STACK, .{663 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...@@ -702,7 +702,7 @@ fn main(c_argc: c_int, c_argv: [*][*:0]c_char, c_envp: [*:null]?[*:0]c_char) cal
702 .linux => {702 .linux => {
703 const at_phdr = std.c.getauxval(elf.AT_PHDR);703 const at_phdr = std.c.getauxval(elf.AT_PHDR);
704 const at_phnum = std.c.getauxval(elf.AT_PHNUM);704 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];
706 expandStackSize(phdrs);706 expandStackSize(phdrs);
707 },707 },
708 .windows => {708 .windows => {