mirror of
https://github.com/golang/go
synced 2024-11-26 09:18:07 -07:00
cmd/compile: use ABI0 for cgo_unsafe_args functions
cgo_unsafe_args paragma indicates that the function (or its callee) uses address and offsets to dispatch arguments, which currently using ABI0 frame layout. Pin them to ABI0. With this, "GOEXPERIMENT=regabi,regabiargs go run hello.go" works on Darwin/AMD64. Change-Id: I3eadd5a3646a9de8fa681fa0a7f46e7cdc217d24 Reviewed-on: https://go-review.googlesource.com/c/go/+/306609 Trust: Cherry Zhang <cherryyz@google.com> Reviewed-by: Austin Clements <austin@google.com> Reviewed-by: Than McIntosh <thanm@google.com>
This commit is contained in:
parent
759116b3ac
commit
6996bae5d1
@ -824,10 +824,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
|||||||
p.To.Reg = v.Args[0].Reg()
|
p.To.Reg = v.Args[0].Reg()
|
||||||
ssagen.AddAux2(&p.To, v, sc.Off64())
|
ssagen.AddAux2(&p.To, v, sc.Off64())
|
||||||
case ssa.OpAMD64MOVOstorezero:
|
case ssa.OpAMD64MOVOstorezero:
|
||||||
if s.ABI != obj.ABIInternal {
|
if !objabi.Experiment.RegabiG || s.ABI != obj.ABIInternal {
|
||||||
v.Fatalf("MOVOstorezero can be only used in ABIInternal functions")
|
|
||||||
}
|
|
||||||
if !objabi.Experiment.RegabiG {
|
|
||||||
// zero X15 manually
|
// zero X15 manually
|
||||||
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
|
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
|
||||||
}
|
}
|
||||||
@ -918,10 +915,7 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
|||||||
p.To.Type = obj.TYPE_REG
|
p.To.Type = obj.TYPE_REG
|
||||||
p.To.Reg = v.Reg()
|
p.To.Reg = v.Reg()
|
||||||
case ssa.OpAMD64DUFFZERO:
|
case ssa.OpAMD64DUFFZERO:
|
||||||
if s.ABI != obj.ABIInternal {
|
if !objabi.Experiment.RegabiG || s.ABI != obj.ABIInternal {
|
||||||
v.Fatalf("MOVOconst can be only used in ABIInternal functions")
|
|
||||||
}
|
|
||||||
if !objabi.Experiment.RegabiG {
|
|
||||||
// zero X15 manually
|
// zero X15 manually
|
||||||
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
|
opregreg(s, x86.AXORPS, x86.REG_X15, x86.REG_X15)
|
||||||
}
|
}
|
||||||
@ -1004,8 +998,8 @@ func ssaGenValue(s *ssagen.State, v *ssa.Value) {
|
|||||||
// Closure pointer is DX.
|
// Closure pointer is DX.
|
||||||
ssagen.CheckLoweredGetClosurePtr(v)
|
ssagen.CheckLoweredGetClosurePtr(v)
|
||||||
case ssa.OpAMD64LoweredGetG:
|
case ssa.OpAMD64LoweredGetG:
|
||||||
if objabi.Experiment.RegabiG {
|
if objabi.Experiment.RegabiG && s.ABI == obj.ABIInternal {
|
||||||
v.Fatalf("LoweredGetG should not appear in new ABI")
|
v.Fatalf("LoweredGetG should not appear in ABIInternal")
|
||||||
}
|
}
|
||||||
r := v.Reg()
|
r := v.Reg()
|
||||||
getgFromTLS(s, r)
|
getgFromTLS(s, r)
|
||||||
|
@ -460,7 +460,7 @@
|
|||||||
(IsInBounds idx len) => (SETB (CMPQ idx len))
|
(IsInBounds idx len) => (SETB (CMPQ idx len))
|
||||||
(IsSliceInBounds idx len) => (SETBE (CMPQ idx len))
|
(IsSliceInBounds idx len) => (SETBE (CMPQ idx len))
|
||||||
(NilCheck ...) => (LoweredNilCheck ...)
|
(NilCheck ...) => (LoweredNilCheck ...)
|
||||||
(GetG mem) && !objabi.Experiment.RegabiG => (LoweredGetG mem) // only lower in old ABI. in new ABI we have a G register.
|
(GetG mem) && !(objabi.Experiment.RegabiG && v.Block.Func.OwnAux.Fn.ABI() == obj.ABIInternal) => (LoweredGetG mem) // only lower in old ABI. in new ABI we have a G register.
|
||||||
(GetClosurePtr ...) => (LoweredGetClosurePtr ...)
|
(GetClosurePtr ...) => (LoweredGetClosurePtr ...)
|
||||||
(GetCallerPC ...) => (LoweredGetCallerPC ...)
|
(GetCallerPC ...) => (LoweredGetCallerPC ...)
|
||||||
(GetCallerSP ...) => (LoweredGetCallerSP ...)
|
(GetCallerSP ...) => (LoweredGetCallerSP ...)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
package ssa
|
package ssa
|
||||||
|
|
||||||
import "math"
|
import "math"
|
||||||
|
import "cmd/internal/obj"
|
||||||
import "cmd/internal/objabi"
|
import "cmd/internal/objabi"
|
||||||
import "cmd/compile/internal/types"
|
import "cmd/compile/internal/types"
|
||||||
|
|
||||||
@ -30465,11 +30466,11 @@ func rewriteValueAMD64_OpFloor(v *Value) bool {
|
|||||||
func rewriteValueAMD64_OpGetG(v *Value) bool {
|
func rewriteValueAMD64_OpGetG(v *Value) bool {
|
||||||
v_0 := v.Args[0]
|
v_0 := v.Args[0]
|
||||||
// match: (GetG mem)
|
// match: (GetG mem)
|
||||||
// cond: !objabi.Experiment.RegabiG
|
// cond: !(objabi.Experiment.RegabiG && v.Block.Func.OwnAux.Fn.ABI() == obj.ABIInternal)
|
||||||
// result: (LoweredGetG mem)
|
// result: (LoweredGetG mem)
|
||||||
for {
|
for {
|
||||||
mem := v_0
|
mem := v_0
|
||||||
if !(!objabi.Experiment.RegabiG) {
|
if !(!(objabi.Experiment.RegabiG && v.Block.Func.OwnAux.Fn.ABI() == obj.ABIInternal)) {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
v.reset(OpAMD64LoweredGetG)
|
v.reset(OpAMD64LoweredGetG)
|
||||||
|
@ -146,6 +146,13 @@ func (s *SymABIs) GenABIWrappers() {
|
|||||||
fn.ABI = defABI
|
fn.ABI = defABI
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if fn.Pragma&ir.CgoUnsafeArgs != 0 {
|
||||||
|
// CgoUnsafeArgs indicates the function (or its callee) uses
|
||||||
|
// offsets to dispatch arguments, which currently using ABI0
|
||||||
|
// frame layout. Pin it to ABI0.
|
||||||
|
fn.ABI = obj.ABI0
|
||||||
|
}
|
||||||
|
|
||||||
// Apply references.
|
// Apply references.
|
||||||
if abis, ok := s.refs[symName]; ok {
|
if abis, ok := s.refs[symName]; ok {
|
||||||
fn.ABIRefs |= abis
|
fn.ABIRefs |= abis
|
||||||
|
Loading…
Reference in New Issue
Block a user