From e8b432aa5ebc5ecea5e52145ef0b3238aa460c54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 15 Sep 2026 06:11:02 +0200 Subject: [PATCH 1/7] std.os.linux: fix comment syntax in microblaze and sh inline asm --- lib/std/os/linux/microblaze.zig | 4 ++-- lib/std/os/linux/sh.zig | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/os/linux/microblaze.zig b/lib/std/os/linux/microblaze.zig index ae450c1970eee1c5430633284a391ec0fcc41211..00c3028bbb94bf6fd32b14b443bbf61866dd739d 100644 --- a/lib/std/os/linux/microblaze.zig +++ b/lib/std/os/linux/microblaze.zig @@ -130,11 +130,11 @@ pub fn clone() callconv(.naked) u32 { \\ brki r14, 0x8 \\ beqi r3, 1f \\ - \\ // parent + \\ # parent \\ rtsd r15, 8 \\ nop \\ - \\ // child + \\ # child \\1: \\ ori r15, r0, 0 \\ ori r19, r0, 0 diff --git a/lib/std/os/linux/sh.zig b/lib/std/os/linux/sh.zig index bda7330343c722cdf211d6b17aa8edb250db48d3..ca5e8f9c8a13796a9f0d3be5de882a25d112d1a3 100644 --- a/lib/std/os/linux/sh.zig +++ b/lib/std/os/linux/sh.zig @@ -179,11 +179,11 @@ pub fn clone() callconv(.naked) u32 { \\ cmp/eq #0, r0 \\ bt 1f \\ - \\ // parent + \\ ! parent \\ rts \\ nop \\ - \\ // child + \\ ! child \\1: ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( -- 2.54.0 From 906bf82596bf50e9396568df0144b3cbb3001199 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 15 Sep 2026 05:49:43 +0200 Subject: [PATCH 2/7] std.os.linux: fix some clone() impls not passing fn return value to SYS_exit --- lib/std/os/linux/hexagon.zig | 1 - lib/std/os/linux/microblaze.zig | 1 + lib/std/os/linux/sh.zig | 1 + lib/std/os/linux/xtensa.zig | 2 ++ 4 files changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/std/os/linux/hexagon.zig b/lib/std/os/linux/hexagon.zig index 3777c1510449d0e937b1e392b21e33e9c524c00d..8e6898f8e05e3fe3feb45bf9da6424ef5baa5e63 100644 --- a/lib/std/os/linux/hexagon.zig +++ b/lib/std/os/linux/hexagon.zig @@ -136,7 +136,6 @@ pub fn clone() callconv(.naked) u32 { \\ callr r11 \\ \\ r6 = #93 // SYS_exit - \\ r0 = #0 \\ trap0(#1) ); } diff --git a/lib/std/os/linux/microblaze.zig b/lib/std/os/linux/microblaze.zig index 00c3028bbb94bf6fd32b14b443bbf61866dd739d..e524b0555a1bc317236758f3b3c11f49cefb4d24 100644 --- a/lib/std/os/linux/microblaze.zig +++ b/lib/std/os/linux/microblaze.zig @@ -144,6 +144,7 @@ pub fn clone() callconv(.naked) u32 { \\ brald r15, r3 \\ nop \\ + \\ ori r5, r3, 0 \\ ori r12, r0, 1 # SYS_exit \\ brki r14, 0x8 ); diff --git a/lib/std/os/linux/sh.zig b/lib/std/os/linux/sh.zig index ca5e8f9c8a13796a9f0d3be5de882a25d112d1a3..b8f3cc8029a35ff910598d4a99465817e9450376 100644 --- a/lib/std/os/linux/sh.zig +++ b/lib/std/os/linux/sh.zig @@ -199,6 +199,7 @@ pub fn clone() callconv(.naked) u32 { \\ nop \\ \\ mov #1, r3 ! SYS_exit + \\ mov r0, r4 \\ trapa #31 \\ or r0, r0 \\ or r0, r0 diff --git a/lib/std/os/linux/xtensa.zig b/lib/std/os/linux/xtensa.zig index 0bda5a9331365dea6c333818b1624cbfd7aba444..c3c7517abf32b85c5a7b1dc9991e84d745b52026 100644 --- a/lib/std/os/linux/xtensa.zig +++ b/lib/std/os/linux/xtensa.zig @@ -151,6 +151,8 @@ pub fn clone() callconv(.naked) u32 { \\ \\ mov a2, a10 \\ callx0 a9 + \\ + \\ mov a6, a2 ) else asm volatile ( \\ beqz a2, 1f \\ // parent -- 2.54.0 From 06572679616ab0d92b7af8a3674b3c21f7106cf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 15 Sep 2026 06:20:30 +0200 Subject: [PATCH 3/7] std.os.linux.or1k: fix swapped ctid/tls in clone() --- lib/std/os/linux/or1k.zig | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/os/linux/or1k.zig b/lib/std/os/linux/or1k.zig index a54b9bd43ff5464c29d920d222c4988440a267d7..2b34a200569292ebd89e6485ce27695788c6a46a 100644 --- a/lib/std/os/linux/or1k.zig +++ b/lib/std/os/linux/or1k.zig @@ -120,8 +120,8 @@ pub fn clone() callconv(.naked) u32 { // __clone(func, stack, flags, arg, ptid, tls, ctid) // r3, r4, r5, r6, r7, r8, +0 // - // syscall(SYS_clone, flags, stack, ptid, tls, ctid) - // r11 r3, r4, r5, r6, r7 + // syscall(SYS_clone, flags, stack, ptid, ctid, tls) + // r11 r3, r4, r5, r6, r7 asm volatile ( \\ # Save function pointer and argument pointer on new thread stack \\ l.addi r13, r0, -4 @@ -134,8 +134,8 @@ pub fn clone() callconv(.naked) u32 { \\ l.ori r11, r0, 220 # SYS_clone \\ l.ori r3, r5, 0 \\ l.ori r5, r7, 0 - \\ l.ori r6, r8, 0 - \\ l.lwz r7, 0(r1) + \\ l.lwz r6, 0(r1) + \\ l.ori r7, r8, 0 \\ l.sys 1 \\ l.sfeqi r11, 0 \\ l.bf 1f -- 2.54.0 From 4edb8c9908f8e5b09194ca07a8ccdc724fd0f150 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 15 Sep 2026 06:09:13 +0200 Subject: [PATCH 4/7] std: fix .cfi_undefined operands for or1k --- lib/std/os/linux/or1k.zig | 2 +- lib/std/start.zig | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/os/linux/or1k.zig b/lib/std/os/linux/or1k.zig index 2b34a200569292ebd89e6485ce27695788c6a46a..edf8745fede27b6af7235547befbfcf438351d8c 100644 --- a/lib/std/os/linux/or1k.zig +++ b/lib/std/os/linux/or1k.zig @@ -145,7 +145,7 @@ pub fn clone() callconv(.naked) u32 { \\1: ); if (builtin.unwind_tables != .none or !builtin.strip_debug_info) asm volatile ( - \\ .cfi_undefined r9 + \\ .cfi_undefined 9 ); asm volatile ( \\ l.ori r2, r0, 0 diff --git a/lib/std/start.zig b/lib/std/start.zig index d86e6172523d7b3999e04c3fee07633792630a9d..0a83ece4f107c1bda7a770b23f7cc56a04296705 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -189,7 +189,7 @@ fn _start() callconv(.naked) noreturn { .m88k => ".cfi_undefined %%r1", .microblaze, .microblazeel => "", // No CFI support. .mips, .mipsel, .mips64, .mips64el => ".cfi_undefined $ra", - .or1k => ".cfi_undefined r9", + .or1k => ".cfi_undefined 9", .powerpc, .powerpcle, .powerpc64, .powerpc64le => ".cfi_undefined lr", .riscv32, .riscv32be, .riscv64, .riscv64be => if (builtin.zig_backend == .stage2_riscv64) "" -- 2.54.0 From 00a75075d3a20cb09053bc7ea0aeb83b988dfa95 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Tue, 15 Sep 2026 17:32:40 +0200 Subject: [PATCH 5/7] std.os.linux: fix syscall_pipe() return value for mips closes https://codeberg.org/ziglang/zig/issues/36847 --- lib/std/os/linux/mips.zig | 1 + lib/std/os/linux/mips64.zig | 1 + lib/std/os/linux/mipsn32.zig | 1 + 3 files changed, 3 insertions(+) diff --git a/lib/std/os/linux/mips.zig b/lib/std/os/linux/mips.zig index ce15e83d4bfafa9d6bbf355f5cbad21aefc6d353..8409aad1023c53a93f21fb87cd202ada89c3d227 100644 --- a/lib/std/os/linux/mips.zig +++ b/lib/std/os/linux/mips.zig @@ -190,6 +190,7 @@ pub fn syscall_pipe( \\1: \\ sw $v0, 0($a0) \\ sw $v1, 4($a0) + \\ move $v0, $zero \\2: : [ret] "={$2}" (-> u32), : [number] "{$2}" (@backingInt(SYS.pipe)), diff --git a/lib/std/os/linux/mips64.zig b/lib/std/os/linux/mips64.zig index aee211ec8aa3aa77265a79c9055df39b606cf390..50f65ef93136257e1c942c80719b0ef929adcef4 100644 --- a/lib/std/os/linux/mips64.zig +++ b/lib/std/os/linux/mips64.zig @@ -148,6 +148,7 @@ pub fn syscall_pipe( \\1: \\ sw $v0, 0($a0) \\ sw $v1, 4($a0) + \\ move $v0, $zero \\2: : [ret] "={$2}" (-> u64), : [number] "{$2}" (@backingInt(SYS.pipe)), diff --git a/lib/std/os/linux/mipsn32.zig b/lib/std/os/linux/mipsn32.zig index fa9b2cc298d3a5c70707bbb020cf0669ac73f7c5..414f96230b9dad0b923208bf055f0be912b4aae1 100644 --- a/lib/std/os/linux/mipsn32.zig +++ b/lib/std/os/linux/mipsn32.zig @@ -148,6 +148,7 @@ pub fn syscall_pipe( \\1: \\ sw $v0, 0($a0) \\ sw $v1, 4($a0) + \\ move $v0, $zero \\2: : [ret] "={$2}" (-> u32), : [number] "{$2}" (@backingInt(SYS.pipe)), -- 2.54.0 From c60a3bbdc11c10d4ee60e42d198ab11d8da03265 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 14 Sep 2026 23:38:02 +0200 Subject: [PATCH 6/7] std.os.windows: use the peb() cbe workaround for all architectures like teb() --- lib/std/os/windows.zig | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/lib/std/os/windows.zig b/lib/std/os/windows.zig index d7b4c61331b1d30eab3255183ca376a65a5f340c..0f6eaae0122b2dc59d2dcc1d0cd40a262686938b 100644 --- a/lib/std/os/windows.zig +++ b/lib/std/os/windows.zig @@ -3645,14 +3645,12 @@ pub fn teb() *TEB { } pub fn peb() *PEB { - if (builtin.zig_backend == .stage2_c) switch (native_arch) { - .x86, .x86_64 => return @ptrCast(@alignCast(struct { - /// This is a workaround for the C backend until zig has the ability to put - /// C code in inline assembly. - extern fn zig_windows_peb() callconv(.c) *anyopaque; - }.zig_windows_peb())), - else => {}, - } else switch (native_arch) { + if (builtin.zig_backend == .stage2_c) return @ptrCast(@alignCast(struct { + /// This is a workaround for the C backend until zig has the ability to put + /// C code in inline assembly. + extern fn zig_windows_peb() callconv(.c) *anyopaque; + }.zig_windows_peb())); + switch (native_arch) { .aarch64 => { comptime assert(@offsetOf(TEB, "ProcessEnvironmentBlock") == 0x60); return asm ( -- 2.54.0 From 1235bc67e20730dbf8741f56a15ac21989d72833 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 14 Sep 2026 23:46:14 +0200 Subject: [PATCH 7/7] std.zig.system.loongarch: remove cbe workaround in cpucfg() Not really sure why I thought this was necessary. Clearly we're not going to be targeting LoongArch with MSVC. --- lib/std/zig/system/loongarch.zig | 20 ++++---------------- lib/zig.h | 14 +------------- 2 files changed, 5 insertions(+), 29 deletions(-) diff --git a/lib/std/zig/system/loongarch.zig b/lib/std/zig/system/loongarch.zig index afc26d5db1be83ad95b105dfbd60ba7967ce30c5..da0d6fecb2807b7fa8b01afcb9ad74ab4f029a2c 100644 --- a/lib/std/zig/system/loongarch.zig +++ b/lib/std/zig/system/loongarch.zig @@ -94,21 +94,9 @@ pub fn detectNativeCpuAndFeatures( return cpu; } -/// This is a workaround for the C backend until zig has the ability to put -/// C code in inline assembly. -extern fn zig_loongarch_cpucfg(word: u32, result: *u32) callconv(.c) void; - fn cpucfg(word: u32) u32 { - var result: u32 = undefined; - - if (builtin.zig_backend == .stage2_c) { - zig_loongarch_cpucfg(word, &result); - } else { - asm ("cpucfg %[result], %[word]" - : [result] "=r" (result), - : [word] "r" (word), - ); - } - - return result; + return asm ("cpucfg %[result], %[word]" + : [result] "=r" (-> u32), + : [word] "r" (word), + ); } diff --git a/lib/zig.h b/lib/zig.h index dd9fa902f34bf2073c111763208937b4abbac01f..ad4156b64a1abf3503a3d55eee385690e6b59a54 100644 --- a/lib/zig.h +++ b/lib/zig.h @@ -6750,19 +6750,7 @@ static inline void* zig_e_zig_windows_peb(void) { #endif -#if defined(zig_loongarch) - -static inline void zig_e_zig_loongarch_cpucfg(uint32_t word, uint32_t* result) zig_mangled(zig_e_zig_loongarch_cpucfg, "zig_loongarch_cpucfg"); - -static inline void zig_e_zig_loongarch_cpucfg(uint32_t word, uint32_t* result) { -#if defined(zig_gnuc_asm) - __asm__("cpucfg %[result], %[word]" : [result] "=r" (*result) : [word] "r" (word)); -#else - *result = 0; -#endif -} - -#elif defined(zig_x86) && !defined(zig_x86_16) +#if defined(zig_x86) && !defined(zig_x86_16) static inline void zig_e_zig_x86_cpuid(uint32_t leaf_id, uint32_t subid, uint32_t* eax, uint32_t* ebx, uint32_t* ecx, uint32_t* edx) zig_mangled(zig_e_zig_x86_cpuid, "zig_x86_cpuid"); static inline uint32_t zig_e_zig_x86_get_xcr0(void) zig_mangled(zig_e_zig_x86_get_xcr0, "zig_x86_get_xcr0"); -- 2.54.0