authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-09 01:55:14+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-08-09 16:56:23+02:00
logef4ce7def1d4868d1d54832fba473f84938e40be
tree5f1dc8cd8b212fae19da6ba830354a721e03207a
parent2a155d75ac575c9a99918569249aecdf251e94d9
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

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.

3 files changed, 4 insertions(+), 4 deletions(-)

lib/std/os/linux/powerpc.zig+1-1
......@@ -247,7 +247,7 @@ pub fn clone() callconv(.naked) u32 {
247247 );
248248 asm volatile (
249249 \\ li 31, 0
250 \\ mtlr 0
250 \\ mtlr 31
251251 \\
252252 \\ #call funcptr: move arg (d) into r3
253253 \\ mr 3, 30
lib/std/os/linux/powerpc64.zig+1-1
......@@ -232,7 +232,7 @@ pub fn clone() callconv(.naked) u64 {
232232 );
233233 asm volatile (
234234 \\ li 31, 0
235 \\ mtlr 0
235 \\ mtlr 31
236236 \\
237237 \\ # call fn(arg)
238238 \\ ld 3, 16(1)
lib/std/start.zig+2-2
......@@ -438,7 +438,7 @@ fn _start() callconv(.naked) noreturn {
438438 \\ stwu 1, -16(1)
439439 \\ stw 0, 0(1)
440440 \\ li 31, 0
441 \\ mtlr 0
441 \\ mtlr 31
442442 \\ b %[posixCallMainAndExit]
443443 ,
444444 .powerpc64, .powerpc64le =>
......@@ -451,7 +451,7 @@ fn _start() callconv(.naked) noreturn {
451451 \\ li 0, 0
452452 \\ stdu 0, -32(1)
453453 \\ li 31, 0
454 \\ mtlr 0
454 \\ mtlr 31
455455 \\ b %[posixCallMainAndExit]
456456 \\ nop
457457 ,