Skip to content

Commit

Permalink
internal/abi, runtime, cmd: merge funcID_* consts into internal/abi
Browse files Browse the repository at this point in the history
For #59670.

Change-Id: I517e97ea74cf232e5cfbb77b127fa8804f74d84b
Reviewed-on: https://go-review.googlesource.com/c/go/+/485495
Reviewed-by: Michael Pratt <mpratt@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Austin Clements <austin@google.com>
Run-TryBot: Austin Clements <austin@google.com>
  • Loading branch information
aclements authored and gopherbot committed Apr 21, 2023
1 parent eaecd64 commit 9754521
Show file tree
Hide file tree
Showing 16 changed files with 124 additions and 134 deletions.
5 changes: 3 additions & 2 deletions src/cmd/internal/goobj/funcinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"bytes"
"cmd/internal/objabi"
"encoding/binary"
"internal/abi"
)

// CUFileIndex is used to index the filenames that are stored in the
Expand All @@ -19,7 +20,7 @@ type CUFileIndex uint32
type FuncInfo struct {
Args uint32
Locals uint32
FuncID objabi.FuncID
FuncID abi.FuncID
FuncFlag objabi.FuncFlag
StartLine int32
File []CUFileIndex
Expand Down Expand Up @@ -89,7 +90,7 @@ func (*FuncInfo) ReadArgs(b []byte) uint32 { return binary.LittleEndian.Uint32(b

func (*FuncInfo) ReadLocals(b []byte) uint32 { return binary.LittleEndian.Uint32(b[4:]) }

func (*FuncInfo) ReadFuncID(b []byte) objabi.FuncID { return objabi.FuncID(b[8]) }
func (*FuncInfo) ReadFuncID(b []byte) abi.FuncID { return abi.FuncID(b[8]) }

func (*FuncInfo) ReadFuncFlag(b []byte) objabi.FuncFlag { return objabi.FuncFlag(b[9]) }

Expand Down
3 changes: 2 additions & 1 deletion src/cmd/internal/obj/link.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import (
"cmd/internal/sys"
"encoding/binary"
"fmt"
"internal/abi"
"sync"
"sync/atomic"
)
Expand Down Expand Up @@ -476,7 +477,7 @@ type FuncInfo struct {
Args int32
Locals int32
Align int32
FuncID objabi.FuncID
FuncID abi.FuncID
FuncFlag objabi.FuncFlag
StartLine int32
Text *Prog
Expand Down
91 changes: 31 additions & 60 deletions src/cmd/internal/objabi/funcid.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

package objabi

import "strings"
import (
"internal/abi"
"strings"
)

// A FuncFlag records bits about a function, passed to the runtime.
type FuncFlag uint8
Expand All @@ -16,76 +19,44 @@ const (
FuncFlag_ASM
)

// A FuncID identifies particular functions that need to be treated
// specially by the runtime.
// Note that in some situations involving plugins, there may be multiple
// copies of a particular special runtime function.
type FuncID uint8

// Note: this list must match the list in runtime/symtab.go.
const (
FuncID_normal FuncID = iota // not a special function
FuncID_abort
FuncID_asmcgocall
FuncID_asyncPreempt
FuncID_cgocallback
FuncID_debugCallV2
FuncID_gcBgMarkWorker
FuncID_goexit
FuncID_gogo
FuncID_gopanic
FuncID_handleAsyncEvent
FuncID_mcall
FuncID_morestack
FuncID_mstart
FuncID_panicwrap
FuncID_rt0_go
FuncID_runfinq
FuncID_runtime_main
FuncID_sigpanic
FuncID_systemstack
FuncID_systemstack_switch
FuncID_wrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.)
)

var funcIDs = map[string]FuncID{
"abort": FuncID_abort,
"asmcgocall": FuncID_asmcgocall,
"asyncPreempt": FuncID_asyncPreempt,
"cgocallback": FuncID_cgocallback,
"debugCallV2": FuncID_debugCallV2,
"gcBgMarkWorker": FuncID_gcBgMarkWorker,
"rt0_go": FuncID_rt0_go,
"goexit": FuncID_goexit,
"gogo": FuncID_gogo,
"gopanic": FuncID_gopanic,
"handleAsyncEvent": FuncID_handleAsyncEvent,
"main": FuncID_runtime_main,
"mcall": FuncID_mcall,
"morestack": FuncID_morestack,
"mstart": FuncID_mstart,
"panicwrap": FuncID_panicwrap,
"runfinq": FuncID_runfinq,
"sigpanic": FuncID_sigpanic,
"systemstack_switch": FuncID_systemstack_switch,
"systemstack": FuncID_systemstack,
var funcIDs = map[string]abi.FuncID{
"abort": abi.FuncID_abort,
"asmcgocall": abi.FuncID_asmcgocall,
"asyncPreempt": abi.FuncID_asyncPreempt,
"cgocallback": abi.FuncID_cgocallback,
"debugCallV2": abi.FuncID_debugCallV2,
"gcBgMarkWorker": abi.FuncID_gcBgMarkWorker,
"rt0_go": abi.FuncID_rt0_go,
"goexit": abi.FuncID_goexit,
"gogo": abi.FuncID_gogo,
"gopanic": abi.FuncID_gopanic,
"handleAsyncEvent": abi.FuncID_handleAsyncEvent,
"main": abi.FuncID_runtime_main,
"mcall": abi.FuncID_mcall,
"morestack": abi.FuncID_morestack,
"mstart": abi.FuncID_mstart,
"panicwrap": abi.FuncID_panicwrap,
"runfinq": abi.FuncID_runfinq,
"sigpanic": abi.FuncID_sigpanic,
"systemstack_switch": abi.FuncID_systemstack_switch,
"systemstack": abi.FuncID_systemstack,

// Don't show in call stack but otherwise not special.
"deferreturn": FuncID_wrapper,
"runOpenDeferFrame": FuncID_wrapper,
"deferCallSave": FuncID_wrapper,
"deferreturn": abi.FuncIDWrapper,
"runOpenDeferFrame": abi.FuncIDWrapper,
"deferCallSave": abi.FuncIDWrapper,
}

// Get the function ID for the named function in the named file.
// The function should be package-qualified.
func GetFuncID(name string, isWrapper bool) FuncID {
func GetFuncID(name string, isWrapper bool) abi.FuncID {
if isWrapper {
return FuncID_wrapper
return abi.FuncIDWrapper
}
if strings.HasPrefix(name, "runtime.") {
if id, ok := funcIDs[name[len("runtime."):]]; ok {
return id
}
}
return FuncID_normal
return abi.FuncIDNormal
}
5 changes: 3 additions & 2 deletions src/cmd/link/internal/ld/pcln.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"cmd/link/internal/loader"
"cmd/link/internal/sym"
"fmt"
"internal/abi"
"internal/buildcfg"
"os"
"path/filepath"
Expand Down Expand Up @@ -168,7 +169,7 @@ func genInlTreeSym(ctxt *Link, cu *sym.CompilationUnit, fi loader.FuncInfo, arch
}

inlFunc := ldr.FuncInfo(call.Func)
var funcID objabi.FuncID
var funcID abi.FuncID
startLine := int32(0)
if inlFunc.Valid() {
funcID = inlFunc.FuncID()
Expand Down Expand Up @@ -698,7 +699,7 @@ func writeFuncs(ctxt *Link, sb *loader.SymbolBuilder, funcs []loader.Sym, inlSym
off = sb.SetUint32(ctxt.Arch, off, uint32(startLine))

// funcID uint8
var funcID objabi.FuncID
var funcID abi.FuncID
if fi.Valid() {
funcID = fi.FuncID()
}
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/link/internal/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"cmd/link/internal/sym"
"debug/elf"
"fmt"
"internal/abi"
"io"
"log"
"math/bits"
Expand Down Expand Up @@ -1990,7 +1991,7 @@ func (fi *FuncInfo) Locals() int {
return int((*goobj.FuncInfo)(nil).ReadLocals(fi.data))
}

func (fi *FuncInfo) FuncID() objabi.FuncID {
func (fi *FuncInfo) FuncID() abi.FuncID {
return (*goobj.FuncInfo)(nil).ReadFuncID(fi.data)
}

Expand Down
39 changes: 39 additions & 0 deletions src/internal/abi/symtab.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package abi

// A FuncID identifies particular functions that need to be treated
// specially by the runtime.
// Note that in some situations involving plugins, there may be multiple
// copies of a particular special runtime function.
type FuncID uint8

const (
// If you add a FuncID, you probably also want to add an entry to the map in
// ../../cmd/internal/objabi/funcid.go

FuncIDNormal FuncID = iota // not a special function
FuncID_abort
FuncID_asmcgocall
FuncID_asyncPreempt
FuncID_cgocallback
FuncID_debugCallV2
FuncID_gcBgMarkWorker
FuncID_goexit
FuncID_gogo
FuncID_gopanic
FuncID_handleAsyncEvent
FuncID_mcall
FuncID_morestack
FuncID_mstart
FuncID_panicwrap
FuncID_rt0_go
FuncID_runfinq
FuncID_runtime_main
FuncID_sigpanic
FuncID_systemstack
FuncID_systemstack_switch
FuncIDWrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.)
)
5 changes: 3 additions & 2 deletions src/runtime/mgcmark.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package runtime

import (
"internal/abi"
"internal/goarch"
"runtime/internal/atomic"
"runtime/internal/sys"
Expand Down Expand Up @@ -919,8 +920,8 @@ func scanframeworker(frame *stkframe, state *stackScanState, gcw *gcWork) {
print("scanframe ", funcname(frame.fn), "\n")
}

isAsyncPreempt := frame.fn.valid() && frame.fn.funcID == funcID_asyncPreempt
isDebugCall := frame.fn.valid() && frame.fn.funcID == funcID_debugCallV2
isAsyncPreempt := frame.fn.valid() && frame.fn.funcID == abi.FuncID_asyncPreempt
isDebugCall := frame.fn.valid() && frame.fn.funcID == abi.FuncID_debugCallV2
if state.conservative || isAsyncPreempt || isDebugCall {
if debugScanConservative {
println("conservatively scanning function", funcname(frame.fn), "at PC", hex(frame.continpc))
Expand Down
3 changes: 2 additions & 1 deletion src/runtime/panic.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package runtime

import (
"internal/abi"
"internal/goarch"
"runtime/internal/atomic"
"runtime/internal/sys"
Expand Down Expand Up @@ -1400,5 +1401,5 @@ func isAbortPC(pc uintptr) bool {
if !f.valid() {
return false
}
return f.funcID == funcID_abort
return f.funcID == abi.FuncID_abort
}
2 changes: 1 addition & 1 deletion src/runtime/race.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ func raceSymbolizeCode(ctx *symbolizeCodeContext) {
u, uf := newInlineUnwinder(fi, pc, nil)
for ; uf.valid(); uf = u.next(uf) {
sf := u.srcFunc(uf)
if sf.funcID == funcID_wrapper {
if sf.funcID == abi.FuncIDWrapper {
// ignore wrappers
continue
}
Expand Down
7 changes: 4 additions & 3 deletions src/runtime/runtime2.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package runtime

import (
"internal/abi"
"internal/goarch"
"runtime/internal/atomic"
"runtime/internal/sys"
Expand Down Expand Up @@ -899,9 +900,9 @@ type _func struct {
pcfile uint32
pcln uint32
npcdata uint32
cuOffset uint32 // runtime.cutab offset of this function's CU
startLine int32 // line number of start of function (func keyword/TEXT directive)
funcID funcID // set for certain special runtime functions
cuOffset uint32 // runtime.cutab offset of this function's CU
startLine int32 // line number of start of function (func keyword/TEXT directive)
funcID abi.FuncID // set for certain special runtime functions
flag funcFlag
_ [1]byte // pad
nfuncdata uint8 // must be last, must end on a uint32-aligned boundary
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -663,7 +663,7 @@ func adjustframe(frame *stkframe, adjinfo *adjustinfo) {
if stackDebug >= 2 {
print(" adjusting ", funcname(f), " frame=[", hex(frame.sp), ",", hex(frame.fp), "] pc=", hex(frame.pc), " continpc=", hex(frame.continpc), "\n")
}
if f.funcID == funcID_systemstack_switch {
if f.funcID == abi.FuncID_systemstack_switch {
// A special routine at the bottom of stack of a goroutine that does a systemstack call.
// We will allow it to be copied even though we don't
// have full GC info for it (because it is written in asm).
Expand Down Expand Up @@ -1204,7 +1204,7 @@ func shrinkstack(gp *g) {
return
}
f := findfunc(gp.startpc)
if f.valid() && f.funcID == funcID_gcBgMarkWorker {
if f.valid() && f.funcID == abi.FuncID_gcBgMarkWorker {
// We're not allowed to shrink the gcBgMarkWorker
// stack (see gcBgMarkWorker for explanation).
return
Expand Down
39 changes: 4 additions & 35 deletions src/runtime/symtab.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package runtime

import (
"internal/abi"
"internal/goarch"
"runtime/internal/atomic"
"runtime/internal/sys"
Expand Down Expand Up @@ -199,14 +200,14 @@ func runtime_expandFinalInlineFrame(stk []uintptr) []uintptr {
// Treat the previous func as normal. We haven't actually checked, but
// since this pc was included in the stack, we know it shouldn't be
// elided.
calleeID := funcID_normal
calleeID := abi.FuncIDNormal

// Remove pc from stk; we'll re-add it below.
stk = stk[:len(stk)-1]

for ; uf.valid(); uf = u.next(uf) {
funcID := u.srcFunc(uf).funcID
if funcID == funcID_wrapper && elideWrapperCalling(calleeID) {
if funcID == abi.FuncIDWrapper && elideWrapperCalling(calleeID) {
// ignore wrappers
} else {
stk = append(stk, uf.pc+1)
Expand Down Expand Up @@ -334,38 +335,6 @@ const (
_PCDATA_RestartAtEntry = -5
)

// A FuncID identifies particular functions that need to be treated
// specially by the runtime.
// Note that in some situations involving plugins, there may be multiple
// copies of a particular special runtime function.
// Note: this list must match the list in cmd/internal/objabi/funcid.go.
type funcID uint8

const (
funcID_normal funcID = iota // not a special function
funcID_abort
funcID_asmcgocall
funcID_asyncPreempt
funcID_cgocallback
funcID_debugCallV2
funcID_gcBgMarkWorker
funcID_goexit
funcID_gogo
funcID_gopanic
funcID_handleAsyncEvent
funcID_mcall
funcID_morestack
funcID_mstart
funcID_panicwrap
funcID_rt0_go
funcID_runfinq
funcID_runtime_main
funcID_sigpanic
funcID_systemstack
funcID_systemstack_switch
funcID_wrapper // any autogenerated code (hash/eq algorithms, method wrappers, etc.)
)

// A FuncFlag holds bits about a function.
// This list must match the list in cmd/internal/objabi/funcid.go.
type funcFlag uint8
Expand Down Expand Up @@ -886,7 +855,7 @@ type srcFunc struct {
datap *moduledata
nameOff int32
startLine int32
funcID funcID
funcID abi.FuncID
}

func (f funcInfo) srcFunc() srcFunc {
Expand Down
Loading

0 comments on commit 9754521

Please sign in to comment.