Skip to content

Commit 91c4f0c

Browse files
committed
reflect: avoid a bounds check in stack-constrained code
Since CL 682496 we need more stack space to handle bounds checks. The code modified here normally has no bounds checks, but in -N builds it still does and thus uses too much stack. Use unsafe arithmetic to avoid the bounds check. This will hopefully fix some of the arm64 linux builders. Change-Id: I5b3096a14b4fb9553e635b7f340e60b8ffba8755 Reviewed-on: https://go-review.googlesource.com/c/go/+/690415 LUCI-TryBot-Result: Go LUCI <[email protected]> Reviewed-by: David Chase <[email protected]> Reviewed-by: Keith Randall <[email protected]>
1 parent 3636ced commit 91c4f0c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/reflect/makefunc.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package reflect
88

99
import (
1010
"internal/abi"
11+
"internal/goarch"
1112
"unsafe"
1213
)
1314

@@ -164,13 +165,18 @@ func moveMakeFuncArgPtrs(ctxt *makeFuncCtxt, args *abi.RegArgs) {
164165
for i, arg := range args.Ints {
165166
// Avoid write barriers! Because our write barrier enqueues what
166167
// was there before, we might enqueue garbage.
168+
// Also avoid bounds checks, we don't have the stack space for it.
169+
// (Normally the prove pass removes them, but for -N builds we
170+
// use too much stack.)
171+
// ptr := &args.Ptrs[i] (but cast from *unsafe.Pointer to *uintptr)
172+
ptr := (*uintptr)(add(unsafe.Pointer(unsafe.SliceData(args.Ptrs[:])), uintptr(i)*goarch.PtrSize, "always in [0:IntArgRegs]"))
167173
if ctxt.regPtrs.Get(i) {
168-
*(*uintptr)(unsafe.Pointer(&args.Ptrs[i])) = arg
174+
*ptr = arg
169175
} else {
170176
// We *must* zero this space ourselves because it's defined in
171177
// assembly code and the GC will scan these pointers. Otherwise,
172178
// there will be garbage here.
173-
*(*uintptr)(unsafe.Pointer(&args.Ptrs[i])) = 0
179+
*ptr = 0
174180
}
175181
}
176182
}

0 commit comments

Comments
 (0)