aboutsummaryrefslogtreecommitdiff
path: root/lib/std
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2025-05-20 07:46:08 +0200
committerGitHub <noreply@github.com>2025-05-20 07:46:08 +0200
commitb27c5fbbdeeab12359c7f5bca0fe15fb0be9424e (patch)
tree50f2dd7a4811a047b4f99c81da04abe58fdcc86e /lib/std
parent23c817548bbd3988a5fd224b590a4f6102dbe5db (diff)
parentcd1eea09648f9ca6eeaf3882e1f74f90fe6c8ab3 (diff)
downloadzig-b27c5fbbdeeab12359c7f5bca0fe15fb0be9424e.tar.gz
zig-b27c5fbbdeeab12359c7f5bca0fe15fb0be9424e.zip
Merge pull request #23913 from alexrp/netbsd-libc
Support dynamically-linked NetBSD libc when cross-compiling
Diffstat (limited to 'lib/std')
-rw-r--r--lib/std/Target.zig26
-rw-r--r--lib/std/c.zig32
-rw-r--r--lib/std/zig/LibCDirs.zig3
-rw-r--r--lib/std/zig/target.zig43
4 files changed, 96 insertions, 8 deletions
diff --git a/lib/std/Target.zig b/lib/std/Target.zig
index 9072f3fd4d..9148fd5fdc 100644
--- a/lib/std/Target.zig
+++ b/lib/std/Target.zig
@@ -540,7 +540,19 @@ pub const Os = struct {
},
.netbsd => .{
.semver = .{
- .min = .{ .major = 9, .minor = 4, .patch = 0 },
+ .min = blk: {
+ const default_min: std.SemanticVersion = .{ .major = 9, .minor = 4, .patch = 0 };
+
+ for (std.zig.target.available_libcs) |libc| {
+ if (libc.arch != arch or libc.os != tag or libc.abi != abi) continue;
+
+ if (libc.os_ver) |min| {
+ if (min.order(default_min) == .gt) break :blk min;
+ }
+ }
+
+ break :blk default_min;
+ },
.max = .{ .major = 10, .minor = 1, .patch = 0 },
},
},
@@ -708,7 +720,6 @@ pub const Os = struct {
pub fn requiresLibC(os: Os) bool {
return switch (os.tag) {
.aix,
- .netbsd,
.driverkit,
.macos,
.ios,
@@ -726,6 +737,7 @@ pub const Os = struct {
.linux,
.windows,
.freebsd,
+ .netbsd,
.freestanding,
.fuchsia,
.ps3,
@@ -2072,6 +2084,13 @@ pub inline fn isFreeBSDLibC(target: Target) bool {
};
}
+pub inline fn isNetBSDLibC(target: Target) bool {
+ return switch (target.abi) {
+ .none, .eabi, .eabihf => target.os.tag == .netbsd,
+ else => false,
+ };
+}
+
pub inline fn isWasiLibC(target: Target) bool {
return target.os.tag == .wasi and target.abi.isMusl();
}
@@ -2486,9 +2505,6 @@ pub const DynamicLinker = struct {
.mips64,
.mips64el,
.powerpc,
- .powerpc64,
- .riscv32,
- .riscv64,
.sparc,
.sparc64,
.x86,
diff --git a/lib/std/c.zig b/lib/std/c.zig
index 3e1ddacf01..e61c8990c3 100644
--- a/lib/std/c.zig
+++ b/lib/std/c.zig
@@ -1840,16 +1840,37 @@ pub const REG = switch (native_os) {
pub const RSP = 20;
},
.netbsd => switch (builtin.cpu.arch) {
- .aarch64 => struct {
+ .aarch64, .aarch64_be => struct {
pub const FP = 29;
pub const SP = 31;
pub const PC = 32;
},
- .arm => struct {
+ .arm, .armeb => struct {
pub const FP = 11;
pub const SP = 13;
pub const PC = 15;
},
+ .x86 => struct {
+ pub const GS = 0;
+ pub const FS = 1;
+ pub const ES = 2;
+ pub const DS = 3;
+ pub const EDI = 4;
+ pub const ESI = 5;
+ pub const EBP = 6;
+ pub const ESP = 7;
+ pub const EBX = 8;
+ pub const EDX = 9;
+ pub const ECX = 10;
+ pub const EAX = 11;
+ pub const TRAPNO = 12;
+ pub const ERR = 13;
+ pub const EIP = 14;
+ pub const CS = 15;
+ pub const EFL = 16;
+ pub const UESP = 17;
+ pub const SS = 18;
+ },
.x86_64 => struct {
pub const RDI = 0;
pub const RSI = 1;
@@ -6806,11 +6827,16 @@ pub const mcontext_t = switch (native_os) {
fpregs: solaris.fpregset_t,
},
.netbsd => switch (builtin.cpu.arch) {
- .aarch64 => extern struct {
+ .aarch64, .aarch64_be => extern struct {
gregs: [35]u64,
fregs: [528]u8 align(16),
spare: [8]u64,
},
+ .x86 => extern struct {
+ gregs: [19]u32,
+ fpregs: [161]u32,
+ mc_tlsbase: u32,
+ },
.x86_64 => extern struct {
gregs: [26]u64,
mc_tlsbase: u64,
diff --git a/lib/std/zig/LibCDirs.zig b/lib/std/zig/LibCDirs.zig
index b98bbb6e0f..b9e612c2f9 100644
--- a/lib/std/zig/LibCDirs.zig
+++ b/lib/std/zig/LibCDirs.zig
@@ -172,6 +172,8 @@ pub fn detectFromBuilding(
std.zig.target.muslArchNameHeaders(target.cpu.arch)
else if (target.isFreeBSDLibC())
std.zig.target.freebsdArchNameHeaders(target.cpu.arch)
+ else if (target.isNetBSDLibC())
+ std.zig.target.netbsdArchNameHeaders(target.cpu.arch)
else
@tagName(target.cpu.arch);
const os_name = @tagName(target.os.tag);
@@ -221,6 +223,7 @@ fn libCGenericName(target: std.Target) [:0]const u8 {
.windows => return "mingw",
.macos, .ios, .tvos, .watchos, .visionos => return "darwin",
.freebsd => return "freebsd",
+ .netbsd => return "netbsd",
else => {},
}
switch (target.abi) {
diff --git a/lib/std/zig/target.zig b/lib/std/zig/target.zig
index bdf85a7217..4d9147802d 100644
--- a/lib/std/zig/target.zig
+++ b/lib/std/zig/target.zig
@@ -18,10 +18,14 @@ pub const available_libcs = [_]ArchOsAbi{
.{ .arch = .arm, .os = .linux, .abi = .gnueabihf, .os_ver = .{ .major = 2, .minor = 1, .patch = 0 } },
.{ .arch = .arm, .os = .linux, .abi = .musleabi, .os_ver = .{ .major = 2, .minor = 1, .patch = 0 } },
.{ .arch = .arm, .os = .linux, .abi = .musleabihf, .os_ver = .{ .major = 2, .minor = 1, .patch = 0 } },
+ .{ .arch = .arm, .os = .netbsd, .abi = .eabi, .os_ver = .{ .major = 1, .minor = 2, .patch = 0 } },
+ .{ .arch = .arm, .os = .netbsd, .abi = .eabihf, .os_ver = .{ .major = 1, .minor = 2, .patch = 0 } },
.{ .arch = .armeb, .os = .linux, .abi = .gnueabi, .os_ver = .{ .major = 2, .minor = 6, .patch = 0 } },
.{ .arch = .armeb, .os = .linux, .abi = .gnueabihf, .os_ver = .{ .major = 2, .minor = 6, .patch = 0 } },
.{ .arch = .armeb, .os = .linux, .abi = .musleabi, .os_ver = .{ .major = 2, .minor = 6, .patch = 0 } },
.{ .arch = .armeb, .os = .linux, .abi = .musleabihf, .os_ver = .{ .major = 2, .minor = 6, .patch = 0 } },
+ .{ .arch = .armeb, .os = .netbsd, .abi = .eabi, .os_ver = .{ .major = 1, .minor = 2, .patch = 0 } },
+ .{ .arch = .armeb, .os = .netbsd, .abi = .eabihf, .os_ver = .{ .major = 1, .minor = 2, .patch = 0 } },
.{ .arch = .thumb, .os = .freebsd, .abi = .eabihf, .os_ver = .{ .major = 11, .minor = 0, .patch = 0 } },
.{ .arch = .thumb, .os = .linux, .abi = .musleabi, .os_ver = .{ .major = 2, .minor = 1, .patch = 0 } },
.{ .arch = .thumb, .os = .linux, .abi = .musleabihf, .os_ver = .{ .major = 2, .minor = 1, .patch = 0 } },
@@ -32,9 +36,11 @@ pub const available_libcs = [_]ArchOsAbi{
.{ .arch = .aarch64, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 3, .minor = 7, .patch = 0 }, .glibc_min = .{ .major = 2, .minor = 17, .patch = 0 } },
.{ .arch = .aarch64, .os = .linux, .abi = .musl, .os_ver = .{ .major = 3, .minor = 7, .patch = 0 } },
.{ .arch = .aarch64, .os = .macos, .abi = .none, .os_ver = .{ .major = 11, .minor = 0, .patch = 0 } },
+ .{ .arch = .aarch64, .os = .netbsd, .abi = .none, .os_ver = .{ .major = 9, .minor = 0, .patch = 0 } },
.{ .arch = .aarch64, .os = .windows, .abi = .gnu },
.{ .arch = .aarch64_be, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 3, .minor = 13, .patch = 0 }, .glibc_min = .{ .major = 2, .minor = 17, .patch = 0 } },
.{ .arch = .aarch64_be, .os = .linux, .abi = .musl, .os_ver = .{ .major = 3, .minor = 13, .patch = 0 } },
+ .{ .arch = .aarch64_be, .os = .netbsd, .abi = .none, .os_ver = .{ .major = 9, .minor = 0, .patch = 0 } },
.{ .arch = .csky, .os = .linux, .abi = .gnueabi, .os_ver = .{ .major = 4, .minor = 20, .patch = 0 }, .glibc_min = .{ .major = 2, .minor = 29, .patch = 0 }, .glibc_triple = "csky-linux-gnuabiv2-soft" },
.{ .arch = .csky, .os = .linux, .abi = .gnueabihf, .os_ver = .{ .major = 4, .minor = 20, .patch = 0 }, .glibc_min = .{ .major = 2, .minor = 29, .patch = 0 }, .glibc_triple = "csky-linux-gnuabiv2" },
.{ .arch = .hexagon, .os = .linux, .abi = .musl, .os_ver = .{ .major = 3, .minor = 2, .patch = 102 } },
@@ -44,14 +50,19 @@ pub const available_libcs = [_]ArchOsAbi{
.{ .arch = .loongarch64, .os = .linux, .abi = .muslsf, .os_ver = .{ .major = 5, .minor = 19, .patch = 0 } },
.{ .arch = .m68k, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 1, .minor = 3, .patch = 94 } },
.{ .arch = .m68k, .os = .linux, .abi = .musl, .os_ver = .{ .major = 1, .minor = 3, .patch = 94 } },
+ .{ .arch = .m68k, .os = .netbsd, .abi = .none },
.{ .arch = .mips, .os = .linux, .abi = .gnueabi, .os_ver = .{ .major = 1, .minor = 1, .patch = 82 }, .glibc_triple = "mips-linux-gnu-soft" },
.{ .arch = .mips, .os = .linux, .abi = .gnueabihf, .os_ver = .{ .major = 1, .minor = 1, .patch = 82 }, .glibc_triple = "mips-linux-gnu" },
.{ .arch = .mips, .os = .linux, .abi = .musleabi, .os_ver = .{ .major = 1, .minor = 1, .patch = 82 } },
.{ .arch = .mips, .os = .linux, .abi = .musleabihf, .os_ver = .{ .major = 1, .minor = 1, .patch = 82 } },
+ .{ .arch = .mips, .os = .netbsd, .abi = .eabi, .os_ver = .{ .major = 1, .minor = 1, .patch = 0 } },
+ .{ .arch = .mips, .os = .netbsd, .abi = .eabihf, .os_ver = .{ .major = 1, .minor = 1, .patch = 0 } },
.{ .arch = .mipsel, .os = .linux, .abi = .gnueabi, .os_ver = .{ .major = 1, .minor = 1, .patch = 82 }, .glibc_triple = "mipsel-linux-gnu-soft" },
.{ .arch = .mipsel, .os = .linux, .abi = .gnueabihf, .os_ver = .{ .major = 1, .minor = 1, .patch = 82 }, .glibc_triple = "mipsel-linux-gnu" },
.{ .arch = .mipsel, .os = .linux, .abi = .musleabi, .os_ver = .{ .major = 1, .minor = 1, .patch = 82 } },
.{ .arch = .mipsel, .os = .linux, .abi = .musleabihf, .os_ver = .{ .major = 1, .minor = 1, .patch = 82 } },
+ .{ .arch = .mipsel, .os = .netbsd, .abi = .eabi, .os_ver = .{ .major = 1, .minor = 1, .patch = 0 } },
+ .{ .arch = .mipsel, .os = .netbsd, .abi = .eabihf, .os_ver = .{ .major = 1, .minor = 1, .patch = 0 } },
.{ .arch = .mips64, .os = .linux, .abi = .gnuabi64, .os_ver = .{ .major = 2, .minor = 3, .patch = 48 }, .glibc_triple = "mips64-linux-gnu-n64" },
.{ .arch = .mips64, .os = .linux, .abi = .gnuabin32, .os_ver = .{ .major = 2, .minor = 6, .patch = 0 }, .glibc_triple = "mips64-linux-gnu-n32" },
.{ .arch = .mips64, .os = .linux, .abi = .muslabi64, .os_ver = .{ .major = 2, .minor = 3, .patch = 48 } },
@@ -65,6 +76,8 @@ pub const available_libcs = [_]ArchOsAbi{
.{ .arch = .powerpc, .os = .linux, .abi = .gnueabihf, .os_ver = .{ .major = 1, .minor = 3, .patch = 45 }, .glibc_triple = "powerpc-linux-gnu" },
.{ .arch = .powerpc, .os = .linux, .abi = .musleabi, .os_ver = .{ .major = 1, .minor = 3, .patch = 45 } },
.{ .arch = .powerpc, .os = .linux, .abi = .musleabihf, .os_ver = .{ .major = 1, .minor = 3, .patch = 45 } },
+ .{ .arch = .powerpc, .os = .netbsd, .abi = .eabi, .os_ver = .{ .major = 6, .minor = 0, .patch = 0 } },
+ .{ .arch = .powerpc, .os = .netbsd, .abi = .eabihf, .os_ver = .{ .major = 1, .minor = 4, .patch = 0 } },
.{ .arch = .powerpc64, .os = .freebsd, .abi = .none, .os_ver = .{ .major = 8, .minor = 0, .patch = 0 } },
.{ .arch = .powerpc64, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 2, .minor = 6, .patch = 0 } },
.{ .arch = .powerpc64, .os = .linux, .abi = .musl, .os_ver = .{ .major = 2, .minor = 6, .patch = 0 } },
@@ -79,11 +92,14 @@ pub const available_libcs = [_]ArchOsAbi{
.{ .arch = .s390x, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 2, .minor = 4, .patch = 2 } },
.{ .arch = .s390x, .os = .linux, .abi = .musl, .os_ver = .{ .major = 2, .minor = 4, .patch = 2 } },
.{ .arch = .sparc, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 2, .minor = 1, .patch = 19 }, .glibc_triple = "sparcv9-linux-gnu" },
+ .{ .arch = .sparc, .os = .netbsd, .abi = .none },
.{ .arch = .sparc64, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 2, .minor = 1, .patch = 19 } },
+ .{ .arch = .sparc64, .os = .netbsd, .abi = .none, .os_ver = .{ .major = 1, .minor = 4, .patch = 0 } },
.{ .arch = .wasm32, .os = .wasi, .abi = .musl },
.{ .arch = .x86, .os = .freebsd, .abi = .none },
.{ .arch = .x86, .os = .linux, .abi = .gnu, .glibc_triple = "i686-linux-gnu" },
.{ .arch = .x86, .os = .linux, .abi = .musl },
+ .{ .arch = .x86, .os = .netbsd, .abi = .none },
.{ .arch = .x86, .os = .windows, .abi = .gnu },
.{ .arch = .x86_64, .os = .freebsd, .abi = .none, .os_ver = .{ .major = 5, .minor = 1, .patch = 0 } },
.{ .arch = .x86_64, .os = .linux, .abi = .gnu, .os_ver = .{ .major = 2, .minor = 6, .patch = 4 } },
@@ -91,12 +107,16 @@ pub const available_libcs = [_]ArchOsAbi{
.{ .arch = .x86_64, .os = .linux, .abi = .musl, .os_ver = .{ .major = 2, .minor = 6, .patch = 4 } },
.{ .arch = .x86_64, .os = .linux, .abi = .muslx32, .os_ver = .{ .major = 3, .minor = 4, .patch = 0 } },
.{ .arch = .x86_64, .os = .macos, .abi = .none, .os_ver = .{ .major = 10, .minor = 7, .patch = 0 } },
+ .{ .arch = .x86_64, .os = .netbsd, .abi = .none, .os_ver = .{ .major = 2, .minor = 0, .patch = 0 } },
.{ .arch = .x86_64, .os = .windows, .abi = .gnu },
};
/// The version of Zig's bundled FreeBSD libc used when linking libc statically.
pub const freebsd_libc_version: std.SemanticVersion = .{ .major = 14, .minor = 0, .patch = 0 };
+/// The version of Zig's bundled NetBSD libc used when linking libc statically.
+pub const netbsd_libc_version: std.SemanticVersion = .{ .major = 10, .minor = 1, .patch = 0 };
+
pub fn canBuildLibC(target: std.Target) bool {
for (available_libcs) |libc| {
if (target.cpu.arch == libc.arch and target.os.tag == libc.os and target.abi == libc.abi) {
@@ -221,6 +241,16 @@ pub fn freebsdArchNameHeaders(arch: std.Target.Cpu.Arch) [:0]const u8 {
};
}
+pub fn netbsdArchNameHeaders(arch: std.Target.Cpu.Arch) [:0]const u8 {
+ return switch (arch) {
+ .armeb => "arm",
+ .aarch64_be => "aarch64",
+ .mipsel => "mips",
+ .mips64el => "mips64",
+ else => @tagName(arch),
+ };
+}
+
pub fn isLibCLibName(target: std.Target, name: []const u8) bool {
const ignore_case = target.os.tag.isDarwin() or target.os.tag == .windows;
@@ -368,6 +398,19 @@ pub fn isLibCLibName(target: std.Target, name: []const u8) bool {
return true;
}
+ if (target.isNetBSDLibC()) {
+ if (eqlIgnoreCase(ignore_case, name, "execinfo"))
+ return true;
+ if (eqlIgnoreCase(ignore_case, name, "m"))
+ return true;
+ if (eqlIgnoreCase(ignore_case, name, "pthread"))
+ return true;
+ if (eqlIgnoreCase(ignore_case, name, "rt"))
+ return true;
+ if (eqlIgnoreCase(ignore_case, name, "util"))
+ return true;
+ }
+
if (target.os.tag == .haiku) {
if (eqlIgnoreCase(ignore_case, name, "root"))
return true;