From f6427426787b292ec28cfd826615e3ae9a66b54a Mon Sep 17 00:00:00 2001 From: Cherry Mui Date: Fri, 21 May 2021 18:28:25 -0400 Subject: [PATCH] [dev.typeparams] reflect: use internal/abi.FuncPCABI0 to take address of assembly functions makeFuncStub and methodValueCall on AMD64 are marked as ABIInternal, so Go code can get their (unwrapped) addresses (using open-coded funcPC). Ues internal/abi.FuncPCABI0 instead, and un-mark the functions. Change-Id: Id28b6101ec7e55bc5a357d4236482cec70cd7e5d Reviewed-on: https://go-review.googlesource.com/c/go/+/322350 Trust: Cherry Mui Run-TryBot: Cherry Mui TryBot-Result: Go Bot Reviewed-by: Michael Knyszek --- src/reflect/asm_amd64.s | 8 ++------ src/reflect/makefunc.go | 12 ++---------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/src/reflect/asm_amd64.s b/src/reflect/asm_amd64.s index 86d3f4e4bf..7491c772ac 100644 --- a/src/reflect/asm_amd64.s +++ b/src/reflect/asm_amd64.s @@ -24,10 +24,8 @@ // See the comment on the declaration of makeFuncStub in makefunc.go // for more details. // No arg size here; runtime pulls arg map out of the func value. -// makeFuncStub must be ABIInternal because it is placed directly -// in function values. // This frame contains two locals. See the comment above LOCAL_RETVALID. -TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$312 +TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$312 NO_LOCAL_POINTERS // NO_LOCAL_POINTERS is a lie. The stack map for the two locals in this // frame is specially handled in the runtime. See the comment above LOCAL_RETVALID. @@ -55,10 +53,8 @@ TEXT ·makeFuncStub(SB),(NOSPLIT|WRAPPER),$312 // See the comment on the declaration of methodValueCall in makefunc.go // for more details. // No arg size here; runtime pulls arg map out of the func value. -// methodValueCall must be ABIInternal because it is placed directly -// in function values. // This frame contains two locals. See the comment above LOCAL_RETVALID. -TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$312 +TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$312 NO_LOCAL_POINTERS // NO_LOCAL_POINTERS is a lie. The stack map for the two locals in this // frame is specially handled in the runtime. See the comment above LOCAL_RETVALID. diff --git a/src/reflect/makefunc.go b/src/reflect/makefunc.go index d53e68a359..588be8bcc1 100644 --- a/src/reflect/makefunc.go +++ b/src/reflect/makefunc.go @@ -52,11 +52,7 @@ func MakeFunc(typ Type, fn func(args []Value) (results []Value)) Value { t := typ.common() ftyp := (*funcType)(unsafe.Pointer(t)) - // Indirect Go func value (dummy) to obtain - // actual code address. (A Go func value is a pointer - // to a C function pointer. https://golang.org/s/go11func.) - dummy := makeFuncStub - code := **(**uintptr)(unsafe.Pointer(&dummy)) + code := abi.FuncPCABI0(makeFuncStub) // makeFuncImpl contains a stack map for use by the runtime _, _, abi := funcLayout(ftyp, nil) @@ -111,11 +107,7 @@ func makeMethodValue(op string, v Value) Value { // v.Type returns the actual type of the method value. ftyp := (*funcType)(unsafe.Pointer(v.Type().(*rtype))) - // Indirect Go func value (dummy) to obtain - // actual code address. (A Go func value is a pointer - // to a C function pointer. https://golang.org/s/go11func.) - dummy := methodValueCall - code := **(**uintptr)(unsafe.Pointer(&dummy)) + code := abi.FuncPCABI0(methodValueCall) // methodValue contains a stack map for use by the runtime _, _, abi := funcLayout(ftyp, nil)