From de04a8a1ef0ea37df7c09a997f60a3c1138de124 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sat, 12 Oct 2024 10:43:58 -0700 Subject: [PATCH] std.dynamic_library: update to new elf API --- lib/std/dynamic_library.zig | 30 ++++++++++++++---------------- lib/std/os/linux/vdso.zig | 17 ++++++++--------- 2 files changed, 22 insertions(+), 25 deletions(-) diff --git a/lib/std/dynamic_library.zig b/lib/std/dynamic_library.zig index 7fd231aba7..8f07db68da 100644 --- a/lib/std/dynamic_library.zig +++ b/lib/std/dynamic_library.zig @@ -141,7 +141,7 @@ pub const ElfDynLib = struct { strings: [*:0]u8, syms: [*]elf.Sym, hashtab: [*]posix.Elf_Symndx, - versym: ?[*]u16, + versym: ?[*]elf.Versym, verdef: ?*elf.Verdef, memory: []align(mem.page_size) u8, @@ -319,7 +319,7 @@ pub const ElfDynLib = struct { var maybe_strings: ?[*:0]u8 = null; var maybe_syms: ?[*]elf.Sym = null; var maybe_hashtab: ?[*]posix.Elf_Symndx = null; - var maybe_versym: ?[*]u16 = null; + var maybe_versym: ?[*]elf.Versym = null; var maybe_verdef: ?*elf.Verdef = null; { @@ -327,11 +327,11 @@ pub const ElfDynLib = struct { while (dynv[i] != 0) : (i += 2) { const p = base + dynv[i + 1]; switch (dynv[i]) { - elf.DT_STRTAB => maybe_strings = @as([*:0]u8, @ptrFromInt(p)), - elf.DT_SYMTAB => maybe_syms = @as([*]elf.Sym, @ptrFromInt(p)), - elf.DT_HASH => maybe_hashtab = @as([*]posix.Elf_Symndx, @ptrFromInt(p)), - elf.DT_VERSYM => maybe_versym = @as([*]u16, @ptrFromInt(p)), - elf.DT_VERDEF => maybe_verdef = @as(*elf.Verdef, @ptrFromInt(p)), + elf.DT_STRTAB => maybe_strings = @ptrFromInt(p), + elf.DT_SYMTAB => maybe_syms = @ptrFromInt(p), + elf.DT_HASH => maybe_hashtab = @ptrFromInt(p), + elf.DT_VERSYM => maybe_versym = @ptrFromInt(p), + elf.DT_VERDEF => maybe_verdef = @ptrFromInt(p), else => {}, } } @@ -399,18 +399,16 @@ pub const ElfDynLib = struct { } }; -fn checkver(def_arg: *elf.Verdef, vsym_arg: i32, vername: []const u8, strings: [*:0]u8) bool { +fn checkver(def_arg: *elf.Verdef, vsym_arg: elf.Versym, vername: []const u8, strings: [*:0]u8) bool { var def = def_arg; - const vsym = @as(u32, @bitCast(vsym_arg)) & 0x7fff; + const vsym_index = vsym_arg.VERSION; while (true) { - if (0 == (def.vd_flags & elf.VER_FLG_BASE) and (def.vd_ndx & 0x7fff) == vsym) - break; - if (def.vd_next == 0) - return false; - def = @as(*elf.Verdef, @ptrFromInt(@intFromPtr(def) + def.vd_next)); + if (0 == (def.flags & elf.VER_FLG_BASE) and @intFromEnum(def.ndx) == vsym_index) break; + if (def.next == 0) return false; + def = @ptrFromInt(@intFromPtr(def) + def.next); } - const aux = @as(*elf.Verdaux, @ptrFromInt(@intFromPtr(def) + def.vd_aux)); - return mem.eql(u8, vername, mem.sliceTo(strings + aux.vda_name, 0)); + const aux: *elf.Verdaux = @ptrFromInt(@intFromPtr(def) + def.aux); + return mem.eql(u8, vername, mem.sliceTo(strings + aux.name, 0)); } test "ElfDynLib" { diff --git a/lib/std/os/linux/vdso.zig b/lib/std/os/linux/vdso.zig index 516976098d..3d418994a6 100644 --- a/lib/std/os/linux/vdso.zig +++ b/lib/std/os/linux/vdso.zig @@ -34,7 +34,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { const dynv = maybe_dynv orelse return 0; if (base == maxInt(usize)) return 0; - var maybe_strings: ?[*]u8 = null; + var maybe_strings: ?[*:0]u8 = null; var maybe_syms: ?[*]elf.Sym = null; var maybe_hashtab: ?[*]linux.Elf_Symndx = null; var maybe_versym: ?[*]elf.Versym = null; @@ -45,11 +45,11 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { while (dynv[i] != 0) : (i += 2) { const p = base +% dynv[i + 1]; switch (dynv[i]) { - elf.DT_STRTAB => maybe_strings = @as([*]u8, @ptrFromInt(p)), - elf.DT_SYMTAB => maybe_syms = @as([*]elf.Sym, @ptrFromInt(p)), - elf.DT_HASH => maybe_hashtab = @as([*]linux.Elf_Symndx, @ptrFromInt(p)), - elf.DT_VERSYM => maybe_versym = @as([*]elf.Versym, @ptrFromInt(p)), - elf.DT_VERDEF => maybe_verdef = @as(*elf.Verdef, @ptrFromInt(p)), + elf.DT_STRTAB => maybe_strings = @ptrFromInt(p), + elf.DT_SYMTAB => maybe_syms = @ptrFromInt(p), + elf.DT_HASH => maybe_hashtab = @ptrFromInt(p), + elf.DT_VERSYM => maybe_versym = @ptrFromInt(p), + elf.DT_VERDEF => maybe_verdef = @ptrFromInt(p), else => {}, } } @@ -80,7 +80,7 @@ pub fn lookup(vername: []const u8, name: []const u8) usize { return 0; } -fn checkver(def_arg: *elf.Verdef, vsym_arg: elf.Versym, vername: []const u8, strings: [*]u8) bool { +fn checkver(def_arg: *elf.Verdef, vsym_arg: elf.Versym, vername: []const u8, strings: [*:0]u8) bool { var def = def_arg; const vsym_index = vsym_arg.VERSION; while (true) { @@ -89,6 +89,5 @@ fn checkver(def_arg: *elf.Verdef, vsym_arg: elf.Versym, vername: []const u8, str def = @ptrFromInt(@intFromPtr(def) + def.next); } const aux: *elf.Verdaux = @ptrFromInt(@intFromPtr(def) + def.aux); - const vda_name: [*:0]u8 = @ptrCast(strings + aux.name); - return mem.eql(u8, vername, mem.sliceTo(vda_name, 0)); + return mem.eql(u8, vername, mem.sliceTo(strings + aux.name, 0)); }