From 0cf5f0d0b085e66eb5421b5bb8a179d9b7fad6db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Wed, 26 Mar 2025 18:26:48 +0100 Subject: [PATCH 1/3] std.process: Fix getBaseAddress() for linux + libc. In this case we should use the getauxval() from libc, not our own. --- lib/std/process.zig | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/std/process.zig b/lib/std/process.zig index b734276444..3320513b0f 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -1652,11 +1652,12 @@ pub fn posixGetUserInfo(name: []const u8) !UserInfo { pub fn getBaseAddress() usize { switch (native_os) { .linux => { - const base = std.os.linux.getauxval(std.elf.AT_BASE); + const getauxval = if (builtin.link_libc) std.c.getauxval else std.os.linux.getauxval; + const base = getauxval(std.elf.AT_BASE); if (base != 0) { return base; } - const phdr = std.os.linux.getauxval(std.elf.AT_PHDR); + const phdr = getauxval(std.elf.AT_PHDR); return phdr - @sizeOf(std.elf.Ehdr); }, .macos, .freebsd, .netbsd => { From d56a99442becc38a74dddd1189530c13e39e9b2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Wed, 26 Mar 2025 18:27:43 +0100 Subject: [PATCH 2/3] std.process: Don't use _mh_execute_header in getBaseAddress() on BSDs. Only the Mach-O format has this symbol. --- lib/std/process.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/process.zig b/lib/std/process.zig index 3320513b0f..6c9ae4eb50 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -1660,7 +1660,7 @@ pub fn getBaseAddress() usize { const phdr = getauxval(std.elf.AT_PHDR); return phdr - @sizeOf(std.elf.Ehdr); }, - .macos, .freebsd, .netbsd => { + .macos => { return @intFromPtr(&std.c._mh_execute_header); }, .windows => return @intFromPtr(windows.kernel32.GetModuleHandleW(null)), From b9efdbb412fa9e5691553eca49aacd31e9d7ff69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Wed, 26 Mar 2025 18:28:21 +0100 Subject: [PATCH 3/3] std.process: Fix getBaseAddress() to handle all Darwin OSs. --- lib/std/process.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/process.zig b/lib/std/process.zig index 6c9ae4eb50..c2d18086fc 100644 --- a/lib/std/process.zig +++ b/lib/std/process.zig @@ -1660,7 +1660,7 @@ pub fn getBaseAddress() usize { const phdr = getauxval(std.elf.AT_PHDR); return phdr - @sizeOf(std.elf.Ehdr); }, - .macos => { + .driverkit, .ios, .macos, .tvos, .visionos, .watchos => { return @intFromPtr(&std.c._mh_execute_header); }, .windows => return @intFromPtr(windows.kernel32.GetModuleHandleW(null)),