Skip to content

Commit

Permalink
cmd, runtime: mark assembly routines in FuncFlags
Browse files Browse the repository at this point in the history
There's no good way to ascertain at runtime whether
a function was implemented in assembly.
The existing workaround doesn't play nicely
with some upcoming linker changes.

This change introduces an explicit marker for routines
implemented in assembly.

This change doesn't use the new bit anywhere,
it only introduces it.

Change-Id: I4051dc0afc15b260724a04b9d18aeeb94911bb29
Reviewed-on: https://go-review.googlesource.com/c/go/+/353671
Trust: Josh Bleecher Snyder <[email protected]>
Run-TryBot: Josh Bleecher Snyder <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
  • Loading branch information
josharian committed Oct 4, 2021
1 parent 7ee4c16 commit 752cc07
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/cmd/internal/obj/objfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -772,6 +772,9 @@ func (ctxt *Link) writeSymDebugNamed(s *LSym, name string) {
if s.Func() != nil && s.Func().FuncFlag&objabi.FuncFlag_TOPFRAME != 0 {
fmt.Fprintf(ctxt.Bso, "topframe ")
}
if s.Func() != nil && s.Func().FuncFlag&objabi.FuncFlag_ASM != 0 {
fmt.Fprintf(ctxt.Bso, "asm ")
}
fmt.Fprintf(ctxt.Bso, "size=%d", s.Size)
if s.Type == objabi.STEXT {
fn := s.Func()
Expand Down
7 changes: 5 additions & 2 deletions src/cmd/internal/obj/plist.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int) {
}
name := strings.Replace(s.Name, "\"\"", ctxt.Pkgpath, -1)
s.Func().FuncID = objabi.GetFuncID(name, flag&WRAPPER != 0 || flag&ABIWRAPPER != 0)
s.Func().FuncFlag = toFuncFlag(flag)
s.Func().FuncFlag = ctxt.toFuncFlag(flag)
s.Set(AttrOnList, true)
s.Set(AttrDuplicateOK, flag&DUPOK != 0)
s.Set(AttrNoSplit, flag&NOSPLIT != 0)
Expand All @@ -172,11 +172,14 @@ func (ctxt *Link) InitTextSym(s *LSym, flag int) {
ctxt.dwarfSym(s)
}

func toFuncFlag(flag int) objabi.FuncFlag {
func (ctxt *Link) toFuncFlag(flag int) objabi.FuncFlag {
var out objabi.FuncFlag
if flag&TOPFRAME != 0 {
out |= objabi.FuncFlag_TOPFRAME
}
if ctxt.IsAsm {
out |= objabi.FuncFlag_ASM
}
return out
}

Expand Down
1 change: 1 addition & 0 deletions src/cmd/internal/objabi/funcid.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type FuncFlag uint8
const (
FuncFlag_TOPFRAME = 1 << iota
FuncFlag_SPWRITE
FuncFlag_ASM
)

// A FuncID identifies particular functions that need to be treated
Expand Down
3 changes: 3 additions & 0 deletions src/runtime/symtab.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ const (
// to be an incomplete unwinding of the stack. In certain contexts
// (in particular garbage collector stack scans) that is a fatal error.
funcFlag_SPWRITE

// ASM indicates that a function was implemented in assembly.
funcFlag_ASM
)

// pcHeader holds data used by the pclntab lookups.
Expand Down

0 comments on commit 752cc07

Please sign in to comment.