Skip to content

Commit fa28560

Browse files
committed
Fix PowerPC restore_rt
* Clang fails to compile the CBE translation of this code ("non-ASM statement in naked function"). Similar to the implementations of `restore_rt` on x86 and ARM, when the CBE is in use, this commit employs alternative inline assembly that avoids using non-immediate input operands. * As with all syscalls, the registers r0, r3, ctr, and xer should also be specified as clobbers.
1 parent 32a1aab commit fa28560

File tree

2 files changed

+26
-10
lines changed

2 files changed

+26
-10
lines changed

lib/std/os/linux/powerpc.zig

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,11 +193,19 @@ pub fn clone() callconv(.naked) usize {
193193
pub const restore = restore_rt;
194194

195195
pub fn restore_rt() callconv(.naked) noreturn {
196-
asm volatile (
197-
\\ sc
198-
:
199-
: [number] "{r0}" (@intFromEnum(SYS.rt_sigreturn)),
200-
: .{ .memory = true, .cr0 = true, .r4 = true, .r5 = true, .r6 = true, .r7 = true, .r8 = true, .r9 = true, .r10 = true, .r11 = true, .r12 = true });
196+
switch (@import("builtin").zig_backend) {
197+
.stage2_c => asm volatile (
198+
\\ li 0, %[number]
199+
\\ sc
200+
:
201+
: [number] "i" (@intFromEnum(SYS.rt_sigreturn)),
202+
: .{ .memory = true, .cr0 = true, .r0 = true, .r3 = true, .r4 = true, .r5 = true, .r6 = true, .r7 = true, .r8 = true, .r9 = true, .r10 = true, .r11 = true, .r12 = true, .ctr = true, .xer = true }),
203+
else => asm volatile (
204+
\\ sc
205+
:
206+
: [number] "{r0}" (@intFromEnum(SYS.rt_sigreturn)),
207+
: .{ .memory = true, .cr0 = true, .r0 = true, .r3 = true, .r4 = true, .r5 = true, .r6 = true, .r7 = true, .r8 = true, .r9 = true, .r10 = true, .r11 = true, .r12 = true, .ctr = true, .xer = true }),
208+
}
201209
}
202210

203211
pub const F = struct {

lib/std/os/linux/powerpc64.zig

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,19 @@ pub fn clone() callconv(.naked) usize {
178178
pub const restore = restore_rt;
179179

180180
pub fn restore_rt() callconv(.naked) noreturn {
181-
asm volatile (
182-
\\ sc
183-
:
184-
: [number] "{r0}" (@intFromEnum(SYS.rt_sigreturn)),
185-
: .{ .memory = true, .cr0 = true, .r4 = true, .r5 = true, .r6 = true, .r7 = true, .r8 = true, .r9 = true, .r10 = true, .r11 = true, .r12 = true });
181+
switch (@import("builtin").zig_backend) {
182+
.stage2_c => asm volatile (
183+
\\ li 0, %[number]
184+
\\ sc
185+
:
186+
: [number] "i" (@intFromEnum(SYS.rt_sigreturn)),
187+
: .{ .memory = true, .cr0 = true, .r0 = true, .r3 = true, .r4 = true, .r5 = true, .r6 = true, .r7 = true, .r8 = true, .r9 = true, .r10 = true, .r11 = true, .r12 = true, .ctr = true, .xer = true }),
188+
else => asm volatile (
189+
\\ sc
190+
:
191+
: [number] "{r0}" (@intFromEnum(SYS.rt_sigreturn)),
192+
: .{ .memory = true, .cr0 = true, .r0 = true, .r3 = true, .r4 = true, .r5 = true, .r6 = true, .r7 = true, .r8 = true, .r9 = true, .r10 = true, .r11 = true, .r12 = true, .ctr = true, .xer = true }),
193+
}
186194
}
187195

188196
pub const F = struct {

0 commit comments

Comments
 (0)