mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/asm, cmd/link, runtime: introduce FuncInfo flag bits
The runtime traceback code has its own definition of which functions mark the top frame of a stack, separate from the TOPFRAME bits that exist in the assembly and are passed along in DWARF information. It's error-prone and redundant to have two different sources of truth. This CL provides the actual TOPFRAME bits to the runtime, so that the runtime can use those bits instead of reinventing its own category. This CL also adds a new bit, SPWRITE, which marks functions that write directly to SP (anything but adding and subtracting constants). Such functions must stop a traceback, because the traceback has no way to rederive the SP on entry. Again, the runtime has its own definition which is mostly correct, but also missing some functions. During ordinary goroutine context switches, such functions do not appear on the stack, so the incompleteness in the runtime usually doesn't matter. But profiling signals can arrive at any moment, and the runtime may crash during traceback if it attempts to unwind an SP-writing frame and gets out-of-sync with the actual stack. The runtime contains code to try to detect likely candidates but again it is incomplete. Deriving the SPWRITE bit automatically from the actual assembly code provides the complete truth, and passing it to the runtime lets the runtime use it. This CL is part of a stack adding windows/arm64 support (#36439), intended to land in the Go 1.17 cycle. This CL is, however, not windows/arm64-specific. It is cleanup meant to make the port (and future ports) easier. Change-Id: I227f53b23ac5b3dabfcc5e8ee3f00df4e113cf58 Reviewed-on: https://go-review.googlesource.com/c/go/+/288800 Trust: Russ Cox <rsc@golang.org> Trust: Jason A. Donenfeld <Jason@zx2c4.com> Reviewed-by: Cherry Zhang <cherryyz@google.com> Reviewed-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
parent
aa0388f2ed
commit
4dd77bdc91
24 changed files with 209 additions and 101 deletions
|
|
@ -454,6 +454,7 @@ type FuncInfo struct {
|
|||
Locals int32
|
||||
Align int32
|
||||
FuncID objabi.FuncID
|
||||
FuncFlag objabi.FuncFlag
|
||||
Text *Prog
|
||||
Autot map[*LSym]struct{}
|
||||
Pcln Pcln
|
||||
|
|
@ -619,10 +620,6 @@ const (
|
|||
// target of an inline during compilation
|
||||
AttrWasInlined
|
||||
|
||||
// TopFrame means that this function is an entry point and unwinders should not
|
||||
// keep unwinding beyond this frame.
|
||||
AttrTopFrame
|
||||
|
||||
// Indexed indicates this symbol has been assigned with an index (when using the
|
||||
// new object file format).
|
||||
AttrIndexed
|
||||
|
|
@ -663,7 +660,6 @@ func (a *Attribute) NeedCtxt() bool { return a.load()&AttrNeedCtxt !=
|
|||
func (a *Attribute) NoFrame() bool { return a.load()&AttrNoFrame != 0 }
|
||||
func (a *Attribute) Static() bool { return a.load()&AttrStatic != 0 }
|
||||
func (a *Attribute) WasInlined() bool { return a.load()&AttrWasInlined != 0 }
|
||||
func (a *Attribute) TopFrame() bool { return a.load()&AttrTopFrame != 0 }
|
||||
func (a *Attribute) Indexed() bool { return a.load()&AttrIndexed != 0 }
|
||||
func (a *Attribute) UsedInIface() bool { return a.load()&AttrUsedInIface != 0 }
|
||||
func (a *Attribute) ContentAddressable() bool { return a.load()&AttrContentAddressable != 0 }
|
||||
|
|
@ -713,14 +709,13 @@ var textAttrStrings = [...]struct {
|
|||
{bit: AttrNoFrame, s: "NOFRAME"},
|
||||
{bit: AttrStatic, s: "STATIC"},
|
||||
{bit: AttrWasInlined, s: ""},
|
||||
{bit: AttrTopFrame, s: "TOPFRAME"},
|
||||
{bit: AttrIndexed, s: ""},
|
||||
{bit: AttrContentAddressable, s: ""},
|
||||
{bit: AttrABIWrapper, s: "ABIWRAPPER"},
|
||||
}
|
||||
|
||||
// TextAttrString formats a for printing in as part of a TEXT prog.
|
||||
func (a Attribute) TextAttrString() string {
|
||||
// String formats a for printing in as part of a TEXT prog.
|
||||
func (a Attribute) String() string {
|
||||
var s string
|
||||
for _, x := range textAttrStrings {
|
||||
if a&x.bit != 0 {
|
||||
|
|
@ -746,6 +741,18 @@ func (a Attribute) TextAttrString() string {
|
|||
return s
|
||||
}
|
||||
|
||||
// TextAttrString formats the symbol attributes for printing in as part of a TEXT prog.
|
||||
func (s *LSym) TextAttrString() string {
|
||||
attr := s.Attribute.String()
|
||||
if s.Func().FuncFlag&objabi.FuncFlag_TOPFRAME != 0 {
|
||||
if attr != "" {
|
||||
attr += "|"
|
||||
}
|
||||
attr += "TOPFRAME"
|
||||
}
|
||||
return attr
|
||||
}
|
||||
|
||||
func (s *LSym) String() string {
|
||||
return s.Name
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue