From b3e82b899fdc911a64bd25d3690321e6f5cf17ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 22:53:37 +0200 Subject: [PATCH 01/10] std.os.linux: Import arch bits for armeb and thumbeb too. --- 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 9ceaaaad817d..49d74f0fe5e0 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -38,7 +38,7 @@ const arch_bits = switch (native_arch) { .x86 => @import("linux/x86.zig"), .x86_64 => @import("linux/x86_64.zig"), .aarch64, .aarch64_be => @import("linux/arm64.zig"), - .arm, .thumb => @import("linux/arm-eabi.zig"), + .arm, .armeb, .thumb, .thumbeb => @import("linux/arm-eabi.zig"), .riscv64 => @import("linux/riscv64.zig"), .sparc64 => @import("linux/sparc64.zig"), .mips, .mipsel => @import("linux/mips.zig"), From b21de4de5e031fdca56d5e5d5a582ce233240f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 22:54:02 +0200 Subject: [PATCH 02/10] std.os.linux: Define syscalls for armeb and thumbeb too. --- 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 49d74f0fe5e0..056fbd68be99 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -103,7 +103,7 @@ pub const SYS = switch (@import("builtin").cpu.arch) { .x86 => syscalls.X86, .x86_64 => syscalls.X64, .aarch64, .aarch64_be => syscalls.Arm64, - .arm, .thumb => syscalls.Arm, + .arm, .armeb, .thumb, .thumbeb => syscalls.Arm, .riscv64 => syscalls.RiscV64, .sparc64 => syscalls.Sparc64, .mips, .mipsel => syscalls.Mips, From fcbb192b4909ecbaedc7a148e8006ba6e57c06b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 22:54:39 +0200 Subject: [PATCH 03/10] std.os.linux: Define (MIN)SIGSTKSZ for all supported Linux architectures. --- lib/std/os/linux.zig | 67 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 63 insertions(+), 4 deletions(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index 056fbd68be99..0b318ae913bd 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -4787,13 +4787,72 @@ pub fn CPU_COUNT(set: cpu_set_t) cpu_count_t { } pub const MINSIGSTKSZ = switch (native_arch) { - .x86, .x86_64, .arm, .mipsel => 2048, - .aarch64 => 5120, + .arc, + .arm, + .armeb, + .csky, + .hexagon, + .m68k, + .mips, + .mipsel, + .mips64, + .mips64el, + .powerpc, + .powerpcle, + .riscv32, + .riscv64, + .s390x, + .thumb, + .thumbeb, + .x86, + .x86_64, + .xtensa, + => 2048, + .loongarch64, + .sparc, + .sparcel, + .sparc64, + => 4096, + .aarch64, + .aarch64_be, + => 5120, + .powerpc64, + .powerpc64le, + => 8192, else => @compileError("MINSIGSTKSZ not defined for this architecture"), }; pub const SIGSTKSZ = switch (native_arch) { - .x86, .x86_64, .arm, .mipsel => 8192, - .aarch64 => 16384, + .arc, + .arm, + .armeb, + .csky, + .hexagon, + .m68k, + .mips, + .mipsel, + .mips64, + .mips64el, + .powerpc, + .powerpcle, + .riscv32, + .riscv64, + .s390x, + .thumb, + .thumbeb, + .x86, + .x86_64, + .xtensa, + => 8192, + .aarch64, + .aarch64_be, + .loongarch64, + .sparc, + .sparcel, + .sparc64, + => 16384, + .powerpc64, + .powerpc64le, + => 32768, else => @compileError("SIGSTKSZ not defined for this architecture"), }; From 92bc802033ec7c206ae3a10c94cc67d85c4b9104 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 22:55:12 +0200 Subject: [PATCH 04/10] std.os.linux: Also define MAP for armeb and thumbeb. --- 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 0b318ae913bd..579f7f4f5a46 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -142,7 +142,7 @@ pub const MAP = switch (native_arch) { UNINITIALIZED: bool = false, _: u5 = 0, }, - .aarch64, .aarch64_be, .arm, .thumb => packed struct(u32) { + .aarch64, .aarch64_be, .arm, .armeb, .thumb, .thumbeb => packed struct(u32) { TYPE: MAP_TYPE, FIXED: bool = false, ANONYMOUS: bool = false, From 93311d6bca579be7201ab204c1100e1487e2cf8a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 22:55:27 +0200 Subject: [PATCH 05/10] std.os.linux: Also define O for armeb and thumbeb. --- 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 579f7f4f5a46..f49b31ef717b 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -290,7 +290,7 @@ pub const O = switch (native_arch) { TMPFILE: bool = false, _: u9 = 0, }, - .aarch64, .aarch64_be, .arm, .thumb => packed struct(u32) { + .aarch64, .aarch64_be, .arm, .armeb, .thumb, .thumbeb => packed struct(u32) { ACCMODE: ACCMODE = .RDONLY, _2: u4 = 0, CREAT: bool = false, From d2d325a86211e70c3a1f5387e4c0c7995438e07c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 23:19:55 +0200 Subject: [PATCH 06/10] std.os.linux.AUDIT: Fix s390x; add loongarch64 and xtensa. --- lib/std/os/linux.zig | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/std/os/linux.zig b/lib/std/os/linux.zig index f49b31ef717b..781741bfca20 100644 --- a/lib/std/os/linux.zig +++ b/lib/std/os/linux.zig @@ -7353,7 +7353,7 @@ pub const AUDIT = struct { ARMEB = toAudit(.armeb), CSKY = toAudit(.csky), HEXAGON = @intFromEnum(std.elf.EM.HEXAGON), - X86 = toAudit(.x86), + LOONGARCH64 = toAudit(.loongarch64), M68K = toAudit(.m68k), MIPS = toAudit(.mips), MIPSEL = toAudit(.mips) | LE, @@ -7367,18 +7367,22 @@ pub const AUDIT = struct { S390X = toAudit(.s390x), SPARC = toAudit(.sparc), SPARC64 = toAudit(.sparc64), + X86 = toAudit(.x86), X86_64 = toAudit(.x86_64), + XTENSA = toAudit(.xtensa), fn toAudit(arch: std.Target.Cpu.Arch) u32 { var res: u32 = @intFromEnum(arch.toElfMachine()); if (arch.endian() == .little) res |= LE; switch (arch) { .aarch64, + .loongarch64, .mips64, .mips64el, .powerpc64, .powerpc64le, .riscv64, + .s390x, .sparc64, .x86_64, => res |= @"64BIT", From d694ddd279d8f0d36185ac6741901e4ac3cb0cd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 23:38:13 +0200 Subject: [PATCH 07/10] std.os.linux.tls: Set tls_variant correctly for thumbeb. --- lib/std/os/linux/tls.zig | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index 5eedb769b571..290fbed96e1c 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -49,7 +49,23 @@ const TLSVariant = enum { }; const tls_variant = switch (native_arch) { - .arm, .armeb, .thumb, .aarch64, .aarch64_be, .riscv32, .riscv64, .mips, .mipsel, .mips64, .mips64el, .powerpc, .powerpcle, .powerpc64, .powerpc64le => TLSVariant.VariantI, + .arm, + .armeb, + .thumb, + .thumbeb, + .aarch64, + .aarch64_be, + .riscv32, + .riscv64, + .mips, + .mipsel, + .mips64, + .mips64el, + .powerpc, + .powerpcle, + .powerpc64, + .powerpc64le, + => TLSVariant.VariantI, .x86_64, .x86, .sparc64 => TLSVariant.VariantII, else => @compileError("undefined tls_variant for this architecture"), }; From c631110f5c664a26520e59d7cec7585156cb5e7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 23:39:02 +0200 Subject: [PATCH 08/10] std.os.linux.tls: Set tls_tcb_size correctly for thumbeb. --- lib/std/os/linux/tls.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index 290fbed96e1c..49c317bb8bb9 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -74,7 +74,7 @@ const tls_variant = switch (native_arch) { const tls_tcb_size = switch (native_arch) { // ARM EABI mandates enough space for two pointers: the first one points to // the DTV while the second one is unspecified but reserved - .arm, .armeb, .thumb, .aarch64, .aarch64_be => 2 * @sizeOf(usize), + .arm, .armeb, .thumb, .thumbeb, .aarch64, .aarch64_be => 2 * @sizeOf(usize), // One pointer-sized word that points either to the DTV or the TCB itself else => @sizeOf(usize), }; From 0473457b6818a2c5055465a82baca34fee726136 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 23:39:18 +0200 Subject: [PATCH 09/10] std.os.linux.tls: Set some constants correctly for powerpcle. --- lib/std/os/linux/tls.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index 49c317bb8bb9..7d2dfa682ff4 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -81,7 +81,7 @@ const tls_tcb_size = switch (native_arch) { // Controls if the TP points to the end of the TCB instead of its beginning const tls_tp_points_past_tcb = switch (native_arch) { - .riscv32, .riscv64, .mips, .mipsel, .mips64, .mips64el, .powerpc, .powerpc64, .powerpc64le => true, + .riscv32, .riscv64, .mips, .mipsel, .mips64, .mips64el, .powerpc, .powerpcle, .powerpc64, .powerpc64le => true, else => false, }; @@ -89,12 +89,12 @@ const tls_tp_points_past_tcb = switch (native_arch) { // make the generated code more efficient const tls_tp_offset = switch (native_arch) { - .mips, .mipsel, .mips64, .mips64el, .powerpc, .powerpc64, .powerpc64le => 0x7000, + .mips, .mipsel, .mips64, .mips64el, .powerpc, .powerpcle, .powerpc64, .powerpc64le => 0x7000, else => 0, }; const tls_dtv_offset = switch (native_arch) { - .mips, .mipsel, .mips64, .mips64el, .powerpc, .powerpc64, .powerpc64le => 0x8000, + .mips, .mipsel, .mips64, .mips64el, .powerpc, .powerpcle, .powerpc64, .powerpc64le => 0x8000, .riscv32, .riscv64 => 0x800, else => 0, }; From 2d4fc1bb7a0c8b7ac42ace3e2bc05cc72c0efba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 21 Jul 2024 23:39:36 +0200 Subject: [PATCH 10/10] std.os.linux.tls: Fix setThreadPointer() for armeb and thumbeb. --- lib/std/os/linux/tls.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/std/os/linux/tls.zig b/lib/std/os/linux/tls.zig index 7d2dfa682ff4..2611e9a05c51 100644 --- a/lib/std/os/linux/tls.zig +++ b/lib/std/os/linux/tls.zig @@ -166,7 +166,7 @@ pub fn setThreadPointer(addr: usize) void { : [addr] "r" (addr), ); }, - .arm, .thumb => { + .arm, .armeb, .thumb, .thumbeb => { const rc = @call(.always_inline, linux.syscall1, .{ .set_tls, addr }); assert(rc == 0); },