Skip to content

Commit

Permalink
reflect: use abi.FuncPCABIInternal
Browse files Browse the repository at this point in the history
Use abi.FuncPCABIInternal instead of going through assembly or
unsafe.Pointer hacks.

For golang#38783
  • Loading branch information
TheCount committed Sep 4, 2023
1 parent 524b4b7 commit d6d3755
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 16 deletions.
9 changes: 1 addition & 8 deletions src/reflect/asm_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ TEXT ·methodValueCall(SB),(NOSPLIT|WRAPPER),$312
// at any of the initial call instructions. The entry point is used to determine
// the closure which implements the method.
// No preamble of any kind, we need to do things manually.
TEXT ·dispatchToMethod(SB),(NOSPLIT|NOFRAME),$0-0
TEXT ·dispatchToMethod<ABIInternal>(SB),(NOSPLIT|NOFRAME),$0-0
CALL ·dispatchLabel(SB)
CALL ·dispatchLabel(SB)
CALL ·dispatchLabel(SB)
Expand Down Expand Up @@ -913,10 +913,3 @@ TEXT ·dispatchLabel(SB),(NOSPLIT|NOFRAME),$0-0
// Currently, (DX) is always makeFuncStub, but this method of dispatch
// might have other clients in the future, so we leave the indirect jump in.
JMP (DX)

// getDispatchToMethodAddr simply returns the address of the actual code of
// dispatchToMethod. This needs to be in ASM since trying to get the address
// from Go yields the address ABI conversion wrapper instead.
TEXT ·getDispatchToMethodAddr<ABIInternal>(SB),(NOSPLIT|NOFRAME),$0-0
MOVQ $·dispatchToMethod(SB), AX
RET
10 changes: 2 additions & 8 deletions src/reflect/makefunc.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,8 @@ func dispatchToMethod()
// assembly used in the implementation of dispatchToMethod.
func dispatchLabel()

// getDispatchToMethodAddr returns the address of the actual code of
// dispatchToMethod. This must happen in ASM to obtain the correct
// address independet of the used ABI.
func getDispatchToMethodAddr() uintptr

// dispatchToMethodAddr is the address of the actual code of dispatchToMethod.
var dispatchToMethodAddr = getDispatchToMethodAddr()
var dispatchToMethodAddr = abi.FuncPCABIInternal(dispatchToMethod)

// currentMethodKey is the most recent method key used for creating a method
// at runtime. Initially, it's the actual code address of dispatchToMethod.
Expand Down Expand Up @@ -242,8 +237,7 @@ func allocMethodSlot(closure unsafe.Pointer) unsafe.Pointer {
newKey := atomic.AddUintptr(&currentMethodKey, dispatchStep)
if newKey > dispatchToMethodAddr+dispatchLimit {
atomic.AddUintptr(&currentMethodKey, ^uintptr(dispatchStep)+1)
dummy := methodSlotsExhausted
return unsafe.Pointer(**(**uintptr)(unsafe.Pointer(&dummy)))
return unsafe.Pointer(abi.FuncPCABIInternal(methodSlotsExhausted))
}
methodMap.Store(newKey, closure)
return unsafe.Pointer(newKey - dispatchStep)
Expand Down

0 comments on commit d6d3755

Please sign in to comment.