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 => {