authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-08-28 04:57:57+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-08-30 14:48:17-07:00
logcb0e6d8aa6f258e2ad9b21287c49c34a434750b2
tree67f66081a4177336fc5e1ef2ee224e70f3af1732
parente4e91a1314abd78a0f06df718459e42e3c9fb62a

std.os.linux: Fix syscall6() when building for PIC/PIE.

LLVM would run out of registers due to the edi usage. Just extend what we're already doing for ebp to edi as well.

1 files changed, 10 insertions(+), 7 deletions(-)

lib/std/os/linux/x86.zig+10-7
...@@ -85,24 +85,27 @@ pub fn syscall6(...@@ -85,24 +85,27 @@ pub fn syscall6(
85 arg5: usize,85 arg5: usize,
86 arg6: usize,86 arg6: usize,
87) usize {87) usize {
88 // The 6th argument is passed via memory as we're out of registers if ebp is88 // arg5/arg6 are passed via memory as we're out of registers if ebp is used as frame pointer, or
89 // used as frame pointer. We push arg6 value on the stack before changing89 // if we're compiling with PIC. We push arg5/arg6 on the stack before changing ebp/esp as the
90 // ebp or esp as the compiler may reference it as an offset relative to one90 // compiler may reference arg5/arg6 as an offset relative to ebp/esp.
91 // of those two registers.
92 return asm volatile (91 return asm volatile (
92 \\ push %[arg5]
93 \\ push %[arg6]93 \\ push %[arg6]
94 \\ push %%edi
94 \\ push %%ebp95 \\ push %%ebp
95 \\ mov 4(%%esp), %%ebp96 \\ mov 12(%%esp), %%edi
97 \\ mov 8(%%esp), %%ebp
96 \\ int $0x8098 \\ int $0x80
97 \\ pop %%ebp99 \\ pop %%ebp
98 \\ add $4, %%esp100 \\ pop %%edi
101 \\ add $8, %%esp
99 : [ret] "={eax}" (-> usize),102 : [ret] "={eax}" (-> usize),
100 : [number] "{eax}" (@intFromEnum(number)),103 : [number] "{eax}" (@intFromEnum(number)),
101 [arg1] "{ebx}" (arg1),104 [arg1] "{ebx}" (arg1),
102 [arg2] "{ecx}" (arg2),105 [arg2] "{ecx}" (arg2),
103 [arg3] "{edx}" (arg3),106 [arg3] "{edx}" (arg3),
104 [arg4] "{esi}" (arg4),107 [arg4] "{esi}" (arg4),
105 [arg5] "{edi}" (arg5),108 [arg5] "rm" (arg5),
106 [arg6] "rm" (arg6),109 [arg6] "rm" (arg6),
107 : "memory"110 : "memory"
108 );111 );