cmd/link: make dwarf name slice index self-describing

cmd/compile/internal/dwarfgen.createComplexVar does it this way, which
has the nice property of documenting the expected prefix.

This is primarily for newtype, since defgotype checks for the prefix
immediately prior, but I changed both for consistency.

Change-Id: I49fa7c6166bdcbd19aaf91fe3dc20537080afcfc
Reviewed-on: https://go-review.googlesource.com/c/go/+/635177
Reviewed-by: Michael Knyszek <mknyszek@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Auto-Submit: Michael Pratt <mpratt@google.com>
This commit is contained in:
Michael Pratt 2024-12-13 15:05:27 -05:00 committed by Gopher Robot
parent c4f356dd86
commit 08770a5b94

View file

@ -520,7 +520,7 @@ func (d *dwctxt) defgotype(gotype loader.Sym) loader.Sym {
d.linkctxt.Errorf(gotype, "dwarf: type name doesn't start with \"type:\"") d.linkctxt.Errorf(gotype, "dwarf: type name doesn't start with \"type:\"")
return d.mustFind("<unspecified>") return d.mustFind("<unspecified>")
} }
name := sn[5:] // could also decode from Type.string name := sn[len("type:"):] // could also decode from Type.string
sdie := d.find(name) sdie := d.find(name)
if sdie != 0 { if sdie != 0 {
@ -534,7 +534,7 @@ func (d *dwctxt) defgotype(gotype loader.Sym) loader.Sym {
func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie { func (d *dwctxt) newtype(gotype loader.Sym) *dwarf.DWDie {
sn := d.ldr.SymName(gotype) sn := d.ldr.SymName(gotype)
name := sn[5:] // could also decode from Type.string name := sn[len("type:"):] // could also decode from Type.string
tdata := d.ldr.Data(gotype) tdata := d.ldr.Data(gotype)
if len(tdata) == 0 { if len(tdata) == 0 {
d.linkctxt.Errorf(gotype, "missing type") d.linkctxt.Errorf(gotype, "missing type")