diff options
| author | Austin Clements <austin@google.com> | 2023-04-17 16:50:00 -0400 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2023-04-21 19:28:49 +0000 |
| commit | 7843ca83e7c8229f4fdca22949428a2418f45138 (patch) | |
| tree | af287142e7909423c1e4ea9873c21b15f60aa06b /src/runtime | |
| parent | 2668a190baa302a1fd7e22285cdb343af67530ad (diff) | |
| download | go-7843ca83e7c8229f4fdca22949428a2418f45138.tar.xz | |
internal/abi, runtime, cmd: merge PCDATA_* and FUNCDATA_* consts into internal/abi
We also rename the constants related to unsafe-points: currently, they
follow the same naming scheme as the PCDATA table indexes, but are not
PCDATA table indexes.
For #59670.
Change-Id: I06529fecfae535be5fe7d9ac56c886b9106c74fd
Reviewed-on: https://go-review.googlesource.com/c/go/+/485497
Run-TryBot: Austin Clements <austin@google.com>
Reviewed-by: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Austin Clements <austin@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Diffstat (limited to 'src/runtime')
| -rw-r--r-- | src/runtime/debugcall.go | 9 | ||||
| -rw-r--r-- | src/runtime/funcdata.h | 2 | ||||
| -rw-r--r-- | src/runtime/heapdump.go | 7 | ||||
| -rw-r--r-- | src/runtime/panic.go | 2 | ||||
| -rw-r--r-- | src/runtime/preempt.go | 10 | ||||
| -rw-r--r-- | src/runtime/stkframe.go | 12 | ||||
| -rw-r--r-- | src/runtime/symtab.go | 39 | ||||
| -rw-r--r-- | src/runtime/symtabinl.go | 4 | ||||
| -rw-r--r-- | src/runtime/trace.go | 2 | ||||
| -rw-r--r-- | src/runtime/traceback.go | 6 |
10 files changed, 29 insertions, 64 deletions
diff --git a/src/runtime/debugcall.go b/src/runtime/debugcall.go index a4393b121a..fb96b41a3a 100644 --- a/src/runtime/debugcall.go +++ b/src/runtime/debugcall.go @@ -6,7 +6,10 @@ package runtime -import "unsafe" +import ( + "internal/abi" + "unsafe" +) const ( debugCallSystemStack = "executing on Go runtime stack" @@ -80,8 +83,8 @@ func debugCallCheck(pc uintptr) string { if pc != f.entry() { pc-- } - up := pcdatavalue(f, _PCDATA_UnsafePoint, pc, nil) - if up != _PCDATA_UnsafePointSafe { + up := pcdatavalue(f, abi.PCDATA_UnsafePoint, pc, nil) + if up != abi.UnsafePointSafe { // Not at a safe point. ret = debugCallUnsafePoint } diff --git a/src/runtime/funcdata.h b/src/runtime/funcdata.h index 2e2bb30446..edc0316fb0 100644 --- a/src/runtime/funcdata.h +++ b/src/runtime/funcdata.h @@ -6,7 +6,7 @@ // in Go binaries. It is included by assembly sources, so it must // be written using #defines. // -// These must agree with symtab.go and ../cmd/internal/objabi/funcdata.go. +// These must agree with internal/abi/symtab.go. #define PCDATA_UnsafePoint 0 #define PCDATA_StackMapIndex 1 diff --git a/src/runtime/heapdump.go b/src/runtime/heapdump.go index 59e28ae9aa..74107a2095 100644 --- a/src/runtime/heapdump.go +++ b/src/runtime/heapdump.go @@ -12,6 +12,7 @@ package runtime import ( + "internal/abi" "internal/goarch" "unsafe" ) @@ -257,7 +258,7 @@ func dumpframe(s *stkframe, child *childInfo) { pcdata := int32(-1) // Use the entry map at function entry if pc != f.entry() { pc-- - pcdata = pcdatavalue(f, _PCDATA_StackMapIndex, pc, nil) + pcdata = pcdatavalue(f, abi.PCDATA_StackMapIndex, pc, nil) } if pcdata == -1 { // We do not have a valid pcdata value but there might be a @@ -265,7 +266,7 @@ func dumpframe(s *stkframe, child *childInfo) { // at the function prologue, assume so and hope for the best. pcdata = 0 } - stkmap := (*stackmap)(funcdata(f, _FUNCDATA_LocalsPointerMaps)) + stkmap := (*stackmap)(funcdata(f, abi.FUNCDATA_LocalsPointerMaps)) var bv bitvector if stkmap != nil && stkmap.n > 0 { @@ -326,7 +327,7 @@ func dumpframe(s *stkframe, child *childInfo) { child.arglen = s.argBytes() child.sp = (*uint8)(unsafe.Pointer(s.sp)) child.depth++ - stkmap = (*stackmap)(funcdata(f, _FUNCDATA_ArgsPointerMaps)) + stkmap = (*stackmap)(funcdata(f, abi.FUNCDATA_ArgsPointerMaps)) if stkmap != nil { child.args = stackmapdata(stkmap, pcdata) } else { diff --git a/src/runtime/panic.go b/src/runtime/panic.go index a68f34f767..cefab56902 100644 --- a/src/runtime/panic.go +++ b/src/runtime/panic.go @@ -654,7 +654,7 @@ func addOneOpenDeferFrame(gp *g, pc uintptr, sp unsafe.Pointer) { continue } f := frame.fn - fd := funcdata(f, _FUNCDATA_OpenCodedDeferInfo) + fd := funcdata(f, abi.FUNCDATA_OpenCodedDeferInfo) if fd == nil { continue } diff --git a/src/runtime/preempt.go b/src/runtime/preempt.go index 751268ee8f..a575fbcf11 100644 --- a/src/runtime/preempt.go +++ b/src/runtime/preempt.go @@ -396,14 +396,14 @@ func isAsyncSafePoint(gp *g, pc, sp, lr uintptr) (bool, uintptr) { // use the LR for unwinding, which will be bad. return false, 0 } - up, startpc := pcdatavalue2(f, _PCDATA_UnsafePoint, pc) - if up == _PCDATA_UnsafePointUnsafe { + up, startpc := pcdatavalue2(f, abi.PCDATA_UnsafePoint, pc) + if up == abi.UnsafePointUnsafe { // Unsafe-point marked by compiler. This includes // atomic sequences (e.g., write barrier) and nosplit // functions (except at calls). return false, 0 } - if fd := funcdata(f, _FUNCDATA_LocalsPointerMaps); fd == nil || f.flag&abi.FuncFlagAsm != 0 { + if fd := funcdata(f, abi.FUNCDATA_LocalsPointerMaps); fd == nil || f.flag&abi.FuncFlagAsm != 0 { // This is assembly code. Don't assume it's well-formed. // TODO: Empirically we still need the fd == nil check. Why? // @@ -432,14 +432,14 @@ func isAsyncSafePoint(gp *g, pc, sp, lr uintptr) (bool, uintptr) { return false, 0 } switch up { - case _PCDATA_Restart1, _PCDATA_Restart2: + case abi.UnsafePointRestart1, abi.UnsafePointRestart2: // Restartable instruction sequence. Back off PC to // the start PC. if startpc == 0 || startpc > pc || pc-startpc > 20 { throw("bad restart PC") } return true, startpc - case _PCDATA_RestartAtEntry: + case abi.UnsafePointRestartAtEntry: // Restart from the function entry at resumption. return true, f.entry() } diff --git a/src/runtime/stkframe.go b/src/runtime/stkframe.go index 3ecf3a828c..9c8f4be453 100644 --- a/src/runtime/stkframe.go +++ b/src/runtime/stkframe.go @@ -70,7 +70,7 @@ type reflectMethodValue struct { // argBytes returns the argument frame size for a call to frame.fn. func (frame *stkframe) argBytes() uintptr { - if frame.fn.args != _ArgsSizeUnknown { + if frame.fn.args != abi.ArgsSizeUnknown { return uintptr(frame.fn.args) } // This is an uncommon and complicated case. Fall back to fully @@ -93,7 +93,7 @@ func (frame *stkframe) argBytes() uintptr { // function stack object, which the caller must synthesize. func (frame *stkframe) argMapInternal() (argMap bitvector, hasReflectStackObj bool) { f := frame.fn - if f.args != _ArgsSizeUnknown { + if f.args != abi.ArgsSizeUnknown { argMap.n = f.args / goarch.PtrSize return } @@ -169,7 +169,7 @@ func (frame *stkframe) getStackMap(cache *pcvalueCache, debug bool) (locals, arg // the first instruction of the function changes the // stack map. targetpc-- - pcdata = pcdatavalue(f, _PCDATA_StackMapIndex, targetpc, cache) + pcdata = pcdatavalue(f, abi.PCDATA_StackMapIndex, targetpc, cache) } if pcdata == -1 { // We do not have a valid pcdata value but there might be a @@ -189,7 +189,7 @@ func (frame *stkframe) getStackMap(cache *pcvalueCache, debug bool) (locals, arg } if size > minsize { stackid := pcdata - stkmap := (*stackmap)(funcdata(f, _FUNCDATA_LocalsPointerMaps)) + stkmap := (*stackmap)(funcdata(f, abi.FUNCDATA_LocalsPointerMaps)) if stkmap == nil || stkmap.n <= 0 { print("runtime: frame ", funcname(f), " untyped locals ", hex(frame.varp-size), "+", hex(size), "\n") throw("missing stackmap") @@ -216,7 +216,7 @@ func (frame *stkframe) getStackMap(cache *pcvalueCache, debug bool) (locals, arg if args.n > 0 && args.bytedata == nil { // Non-empty argument frame, but not a special map. // Fetch the argument map at pcdata. - stackmap := (*stackmap)(funcdata(f, _FUNCDATA_ArgsPointerMaps)) + stackmap := (*stackmap)(funcdata(f, abi.FUNCDATA_ArgsPointerMaps)) if stackmap == nil || stackmap.n <= 0 { print("runtime: frame ", funcname(f), " untyped args ", hex(frame.argp), "+", hex(args.n*goarch.PtrSize), "\n") throw("missing stackmap") @@ -242,7 +242,7 @@ func (frame *stkframe) getStackMap(cache *pcvalueCache, debug bool) (locals, arg // This offset matches the assembly code on amd64 and arm64. objs = methodValueCallFrameObjs[:] } else { - p := funcdata(f, _FUNCDATA_StackObjects) + p := funcdata(f, abi.FUNCDATA_StackObjects) if p != nil { n := *(*uintptr)(p) p = add(p, goarch.PtrSize) diff --git a/src/runtime/symtab.go b/src/runtime/symtab.go index 82c6c9af54..b11854c943 100644 --- a/src/runtime/symtab.go +++ b/src/runtime/symtab.go @@ -296,45 +296,6 @@ func (f *_func) funcInfo() funcInfo { return funcInfo{f, mod} } -// PCDATA and FUNCDATA table indexes. -// -// See funcdata.h and ../cmd/internal/objabi/funcdata.go. -const ( - _PCDATA_UnsafePoint = 0 - _PCDATA_StackMapIndex = 1 - _PCDATA_InlTreeIndex = 2 - _PCDATA_ArgLiveIndex = 3 - - _FUNCDATA_ArgsPointerMaps = 0 - _FUNCDATA_LocalsPointerMaps = 1 - _FUNCDATA_StackObjects = 2 - _FUNCDATA_InlTree = 3 - _FUNCDATA_OpenCodedDeferInfo = 4 - _FUNCDATA_ArgInfo = 5 - _FUNCDATA_ArgLiveInfo = 6 - _FUNCDATA_WrapInfo = 7 - - _ArgsSizeUnknown = -0x80000000 -) - -const ( - // PCDATA_UnsafePoint values. - _PCDATA_UnsafePointSafe = -1 // Safe for async preemption - _PCDATA_UnsafePointUnsafe = -2 // Unsafe for async preemption - - // _PCDATA_Restart1(2) apply on a sequence of instructions, within - // which if an async preemption happens, we should back off the PC - // to the start of the sequence when resume. - // We need two so we can distinguish the start/end of the sequence - // in case that two sequences are next to each other. - _PCDATA_Restart1 = -3 - _PCDATA_Restart2 = -4 - - // Like _PCDATA_RestartAtEntry, but back to function entry if async - // preempted. - _PCDATA_RestartAtEntry = -5 -) - // pcHeader holds data used by the pclntab lookups. type pcHeader struct { magic uint32 // 0xFFFFFFF1 diff --git a/src/runtime/symtabinl.go b/src/runtime/symtabinl.go index e9cd535a17..2bb1c4bc6a 100644 --- a/src/runtime/symtabinl.go +++ b/src/runtime/symtabinl.go @@ -53,7 +53,7 @@ type inlineFrame struct { // only ever used for symbolic debugging. If things go really wrong, it'll just // fall back to the outermost frame. func newInlineUnwinder(f funcInfo, pc uintptr, cache *pcvalueCache) (inlineUnwinder, inlineFrame) { - inldata := funcdata(f, _FUNCDATA_InlTree) + inldata := funcdata(f, abi.FUNCDATA_InlTree) if inldata == nil { return inlineUnwinder{f: f}, inlineFrame{pc: pc, index: -1} } @@ -67,7 +67,7 @@ func (u *inlineUnwinder) resolveInternal(pc uintptr) inlineFrame { pc: pc, // Conveniently, this returns -1 if there's an error, which is the same // value we use for the outermost frame. - index: pcdatavalue1(u.f, _PCDATA_InlTreeIndex, pc, u.cache, false), + index: pcdatavalue1(u.f, abi.PCDATA_InlTreeIndex, pc, u.cache, false), } } diff --git a/src/runtime/trace.go b/src/runtime/trace.go index 2528c18274..c382068e2f 100644 --- a/src/runtime/trace.go +++ b/src/runtime/trace.go @@ -1701,7 +1701,7 @@ func startPCforTrace(pc uintptr) uintptr { if !f.valid() { return pc // may happen for locked g in extra M since its pc is 0. } - w := funcdata(f, _FUNCDATA_WrapInfo) + w := funcdata(f, abi.FUNCDATA_WrapInfo) if w == nil { return pc // not a wrapper } diff --git a/src/runtime/traceback.go b/src/runtime/traceback.go index aac19dc980..d55c6d7aa5 100644 --- a/src/runtime/traceback.go +++ b/src/runtime/traceback.go @@ -664,13 +664,13 @@ func printArgs(f funcInfo, argp unsafe.Pointer, pc uintptr) { maxLen = (maxDepth*3+2)*limit + 1 // max length of _FUNCDATA_ArgInfo (see the compiler side for reasoning) ) - p := (*[maxLen]uint8)(funcdata(f, _FUNCDATA_ArgInfo)) + p := (*[maxLen]uint8)(funcdata(f, abi.FUNCDATA_ArgInfo)) if p == nil { return } - liveInfo := funcdata(f, _FUNCDATA_ArgLiveInfo) - liveIdx := pcdatavalue(f, _PCDATA_ArgLiveIndex, pc, nil) + liveInfo := funcdata(f, abi.FUNCDATA_ArgLiveInfo) + liveIdx := pcdatavalue(f, abi.PCDATA_ArgLiveIndex, pc, nil) startOffset := uint8(0xff) // smallest offset that needs liveness info (slots with a lower offset is always live) if liveInfo != nil { startOffset = *(*uint8)(liveInfo) |
