Skip to content

Commit d33ace7

Browse files
leongrossdeadprogram
authored andcommitted
remove unused registers for x86_64 linux syscalls
Signed-off-by: leongross <[email protected]>
1 parent dd6fa89 commit d33ace7

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

compiler/syscall.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,17 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) {
3333
"{r10}",
3434
"{r8}",
3535
"{r9}",
36-
"{r11}",
37-
"{r12}",
38-
"{r13}",
3936
}[i]
4037
llvmValue := b.getValue(arg, getPos(call))
4138
args = append(args, llvmValue)
4239
argTypes = append(argTypes, llvmValue.Type())
4340
}
41+
// rcx and r11 are clobbered by the syscall, so make sure they are not used
4442
constraints += ",~{rcx},~{r11}"
4543
fnType := llvm.FunctionType(b.uintptrType, argTypes, false)
4644
target := llvm.InlineAsm(fnType, "syscall", constraints, true, false, llvm.InlineAsmDialectIntel, false)
4745
return b.CreateCall(fnType, target, args, ""), nil
46+
4847
case b.GOARCH == "386" && b.GOOS == "linux":
4948
// Sources:
5049
// syscall(2) man page
@@ -71,6 +70,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) {
7170
fnType := llvm.FunctionType(b.uintptrType, argTypes, false)
7271
target := llvm.InlineAsm(fnType, "int 0x80", constraints, true, false, llvm.InlineAsmDialectIntel, false)
7372
return b.CreateCall(fnType, target, args, ""), nil
73+
7474
case b.GOARCH == "arm" && b.GOOS == "linux":
7575
// Implement the EABI system call convention for Linux.
7676
// Source: syscall(2) man page.
@@ -103,6 +103,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) {
103103
fnType := llvm.FunctionType(b.uintptrType, argTypes, false)
104104
target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false)
105105
return b.CreateCall(fnType, target, args, ""), nil
106+
106107
case b.GOARCH == "arm64" && b.GOOS == "linux":
107108
// Source: syscall(2) man page.
108109
args := []llvm.Value{}
@@ -135,6 +136,7 @@ func (b *builder) createRawSyscall(call *ssa.CallCommon) (llvm.Value, error) {
135136
fnType := llvm.FunctionType(b.uintptrType, argTypes, false)
136137
target := llvm.InlineAsm(fnType, "svc #0", constraints, true, false, 0, false)
137138
return b.CreateCall(fnType, target, args, ""), nil
139+
138140
default:
139141
return llvm.Value{}, b.makeError(call.Pos(), "unknown GOOS/GOARCH for syscall: "+b.GOOS+"/"+b.GOARCH)
140142
}
@@ -217,6 +219,7 @@ func (b *builder) createSyscall(call *ssa.CallCommon) (llvm.Value, error) {
217219
retval = b.CreateInsertValue(retval, syscallResult, 0, "")
218220
retval = b.CreateInsertValue(retval, errResult, 2, "")
219221
return retval, nil
222+
220223
default:
221224
return llvm.Value{}, b.makeError(call.Pos(), "unknown GOOS/GOARCH for syscall: "+b.GOOS+"/"+b.GOARCH)
222225
}

0 commit comments

Comments
 (0)