1
0
mirror of https://github.com/golang/go synced 2024-11-22 20:24:47 -07:00

reflect: fix memmove for big endian cases with new ABI

Some memmoves in reflect/value.go for copying arguments
related to the new ABI were using the address of the target
or source instead of using IntArgRegAddr or FloatArgRegAddr
to adjust the address for big endian.

This was found when testing patches for ppc64 and fixes the
failures that were found.

Change-Id: I119aa090a2a8eb859020ff1a1736107a6d0b76f1
Reviewed-on: https://go-review.googlesource.com/c/go/+/343869
Run-TryBot: Lynn Boger <laboger@linux.vnet.ibm.com>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Trust: Michael Knyszek <mknyszek@google.com>
Trust: Lynn Boger <laboger@linux.vnet.ibm.com>
This commit is contained in:
Lynn Boger 2021-08-20 07:01:50 -05:00
parent 4fbb5c8666
commit f1d8ea1da3

View File

@ -508,7 +508,7 @@ func (v Value) call(op string, in []Value) []Value {
// Copy values to "integer registers."
if v.flag&flagIndir != 0 {
offset := add(v.ptr, st.offset, "precomputed value offset")
memmove(unsafe.Pointer(&regArgs.Ints[st.ireg]), offset, st.size)
memmove(regArgs.IntRegArgAddr(st.ireg, st.size), offset, st.size)
} else {
if st.kind == abiStepPointer {
// Duplicate this pointer in the pointer area of the
@ -524,7 +524,7 @@ func (v Value) call(op string, in []Value) []Value {
panic("attempted to copy pointer to FP register")
}
offset := add(v.ptr, st.offset, "precomputed value offset")
memmove(unsafe.Pointer(&regArgs.Floats[st.freg]), offset, st.size)
memmove(regArgs.FloatRegArgAddr(st.freg, st.size), offset, st.size)
default:
panic("unknown ABI part kind")
}
@ -610,13 +610,13 @@ func (v Value) call(op string, in []Value) []Value {
switch st.kind {
case abiStepIntReg:
offset := add(s, st.offset, "precomputed value offset")
memmove(offset, unsafe.Pointer(&regArgs.Ints[st.ireg]), st.size)
memmove(offset, regArgs.IntRegArgAddr(st.ireg, st.size), st.size)
case abiStepPointer:
s := add(s, st.offset, "precomputed value offset")
*((*unsafe.Pointer)(s)) = regArgs.Ptrs[st.ireg]
case abiStepFloatReg:
offset := add(s, st.offset, "precomputed value offset")
memmove(offset, unsafe.Pointer(&regArgs.Floats[st.freg]), st.size)
memmove(offset, regArgs.FloatRegArgAddr(st.freg, st.size), st.size)
case abiStepStack:
panic("register-based return value has stack component")
default:
@ -698,13 +698,13 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
switch st.kind {
case abiStepIntReg:
offset := add(v.ptr, st.offset, "precomputed value offset")
memmove(offset, unsafe.Pointer(&regs.Ints[st.ireg]), st.size)
memmove(offset, regs.IntRegArgAddr(st.ireg, st.size), st.size)
case abiStepPointer:
s := add(v.ptr, st.offset, "precomputed value offset")
*((*unsafe.Pointer)(s)) = regs.Ptrs[st.ireg]
case abiStepFloatReg:
offset := add(v.ptr, st.offset, "precomputed value offset")
memmove(offset, unsafe.Pointer(&regs.Floats[st.freg]), st.size)
memmove(offset, regs.FloatRegArgAddr(st.freg, st.size), st.size)
case abiStepStack:
panic("register-based return value has stack component")
default:
@ -784,7 +784,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
// Copy values to "integer registers."
if v.flag&flagIndir != 0 {
offset := add(v.ptr, st.offset, "precomputed value offset")
memmove(unsafe.Pointer(&regs.Ints[st.ireg]), offset, st.size)
memmove(regs.IntRegArgAddr(st.ireg, st.size), offset, st.size)
} else {
// Only populate the Ints space on the return path.
// This is safe because out is kept alive until the
@ -799,7 +799,7 @@ func callReflect(ctxt *makeFuncImpl, frame unsafe.Pointer, retValid *bool, regs
panic("attempted to copy pointer to FP register")
}
offset := add(v.ptr, st.offset, "precomputed value offset")
memmove(unsafe.Pointer(&regs.Floats[st.freg]), offset, st.size)
memmove(regs.FloatRegArgAddr(st.freg, st.size), offset, st.size)
default:
panic("unknown ABI part kind")
}