From d71076c9826ddd66bfcc04b9a6ded9dbf540d239 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sat, 3 Aug 2024 18:46:04 +0200 Subject: [PATCH 1/3] std.os.linux: Replace `@hasDecl()` with `!= void` check for VDSO. If there is a VDSO, it will have clock_gettime(). The main thing we're concerned about is architectures that don't have a VDSO at all, of which there are a few. --- lib/std/os/linux.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 198481c373..7eb0fdba69 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -1399,7 +1399,7 @@ const VdsoClockGettime = *align(1) const fn (clockid_t, *timespec) callconv(.C) var vdso_clock_gettime: ?VdsoClockGettime = &init_vdso_clock_gettime; pub fn clock_gettime(clk_id: clockid_t, tp: *timespec) usize { - if (@hasDecl(VDSO, "CGT_SYM")) { + if (VDSO != void) { const ptr = @atomicLoad(?VdsoClockGettime, &vdso_clock_gettime, .unordered); if (ptr) |f| { const rc = f(clk_id, tp); From 64e119124f03e94467032949cbd9b51c8311db05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sat, 3 Aug 2024 18:48:53 +0200 Subject: [PATCH 2/3] std.os.linux: Fix CGT_SYM for mips/mips64. --- lib/std/os/linux/mips.zig | 4 ++-- lib/std/os/linux/mips64.zig | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig index abf047e838..853df45fce 100644 --- a/lib/std/os/linux/mips.zig +++ b/lib/std/os/linux/mips.zig @@ -242,8 +242,8 @@ pub const F = struct { pub const MMAP2_UNIT = 4096; pub const VDSO = struct { - pub const CGT_SYM = "__kernel_clock_gettime"; - pub const CGT_VER = "LINUX_2.6.39"; + pub const CGT_SYM = "__vdso_clock_gettime"; + pub const CGT_VER = "LINUX_2.6"; }; pub const Flock = extern struct { diff --git a/lib/std/os/linux/mips64.zig b/lib/std/os/linux/mips64.zig index 9be0f41c4f..5089ba6fd3 100644 --- a/lib/std/os/linux/mips64.zig +++ b/lib/std/os/linux/mips64.zig @@ -227,8 +227,8 @@ pub const F = struct { pub const MMAP2_UNIT = 4096; pub const VDSO = struct { - pub const CGT_SYM = "__kernel_clock_gettime"; - pub const CGT_VER = "LINUX_2.6.39"; + pub const CGT_SYM = "__vdso_clock_gettime"; + pub const CGT_VER = "LINUX_2.6"; }; pub const Flock = extern struct { From 0ad97b41229805fac0e20d88cb24118535fbf056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sat, 3 Aug 2024 18:49:12 +0200 Subject: [PATCH 3/3] std.os.linux: Add VDSO definition for riscv32/riscv64. --- lib/std/os/linux/riscv32.zig | 5 ++++- lib/std/os/linux/riscv64.zig | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/std/os/linux/riscv32.zig b/lib/std/os/linux/riscv32.zig index 219eb5cc19..b8023c5d5c 100644 --- a/lib/std/os/linux/riscv32.zig +++ b/lib/std/os/linux/riscv32.zig @@ -188,7 +188,10 @@ pub const Elf_Symndx = u32; pub const MMAP2_UNIT = 4096; -pub const VDSO = struct {}; +pub const VDSO = struct { + pub const CGT_SYM = "__vdso_clock_gettime"; + pub const CGT_VER = "LINUX_4.15"; +}; /// TODO pub const ucontext_t = void; diff --git a/lib/std/os/linux/riscv64.zig b/lib/std/os/linux/riscv64.zig index fc0893d5c1..8c3c8fe289 100644 --- a/lib/std/os/linux/riscv64.zig +++ b/lib/std/os/linux/riscv64.zig @@ -215,7 +215,10 @@ pub const Stat = extern struct { pub const Elf_Symndx = u32; -pub const VDSO = struct {}; +pub const VDSO = struct { + pub const CGT_SYM = "__vdso_clock_gettime"; + pub const CGT_VER = "LINUX_4.15"; +}; /// TODO pub const ucontext_t = void;