From ef4ce7def1d4868d1d54832fba473f84938e40be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Sun, 9 Aug 2026 01:55:14 +0200 Subject: [PATCH] std: fix zeroing of lr in powerpc _start and clone assembly PowerPC assembly is wonderful because you can't tell at a glance whether an operand is an immediate integer or a register number. In this case, mtlr takes a register number, but we haven't zeroed r0, and it's not a hardwired zero register as on other architectures. Fix this by copying from r31 which we've just zeroed. --- lib/std/os/linux/powerpc.zig | 2 +- lib/std/os/linux/powerpc64.zig | 2 +- lib/std/start.zig | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/std/os/linux/powerpc.zig b/lib/std/os/linux/powerpc.zig index 614c981f8ff891e2e3fed978b65866da9d9a6ab3..5bfaae2767ee33b4d0b1ff32ccafab0ed5f1a1b1 100644 --- a/lib/std/os/linux/powerpc.zig +++ b/lib/std/os/linux/powerpc.zig @@ -247,7 +247,7 @@ pub fn clone() callconv(.naked) u32 { ); asm volatile ( \\ li 31, 0 - \\ mtlr 0 + \\ mtlr 31 \\ \\ #call funcptr: move arg (d) into r3 \\ mr 3, 30 diff --git a/lib/std/os/linux/powerpc64.zig b/lib/std/os/linux/powerpc64.zig index 89f3dbde7b3736d7cc021d55f0b9fb753f347789..5dd1fc9a9d8163ec50b37e58749a63d2eaf5312a 100644 --- a/lib/std/os/linux/powerpc64.zig +++ b/lib/std/os/linux/powerpc64.zig @@ -232,7 +232,7 @@ pub fn clone() callconv(.naked) u64 { ); asm volatile ( \\ li 31, 0 - \\ mtlr 0 + \\ mtlr 31 \\ \\ # call fn(arg) \\ ld 3, 16(1) diff --git a/lib/std/start.zig b/lib/std/start.zig index c49453246fcc59f09d717fe08a9d000a418cd891..ccfc572f0690ccbc254270b4d9c6c76bb66ccfa7 100644 --- a/lib/std/start.zig +++ b/lib/std/start.zig @@ -438,7 +438,7 @@ fn _start() callconv(.naked) noreturn { \\ stwu 1, -16(1) \\ stw 0, 0(1) \\ li 31, 0 - \\ mtlr 0 + \\ mtlr 31 \\ b %[posixCallMainAndExit] , .powerpc64, .powerpc64le => @@ -451,7 +451,7 @@ fn _start() callconv(.naked) noreturn { \\ li 0, 0 \\ stdu 0, -32(1) \\ li 31, 0 - \\ mtlr 0 + \\ mtlr 31 \\ b %[posixCallMainAndExit] \\ nop , -- 2.54.0