Skip to content

Commit 49d52fe

Browse files
committed
Read runtime constants from DWARF, now that they will
be available in go1.10+.
1 parent dbeef03 commit 49d52fe

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

gocore/dwarf.go

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,9 @@ func (p *Program) typeObject(a core.Address, t *Type, r reader, add func(core.Ad
655655
// readRuntimeConstants populates the p.rtConstants map.
656656
func (p *Program) readRuntimeConstants() {
657657
p.rtConstants = map[string]int64{}
658-
// TODO: It would be ideal if we could glean this info from DWARF.
659-
// But we don't package up constants in DWARF right now. See issue #14517.
660-
// For now, we'll hard code them. As we get more Go versions, each entry
661-
// might need to condition on Go version, and maybe arch.
658+
659+
// Hardcoded values for Go 1.8 & 1.9.
660+
// (Go did not have constants in DWARF before 1.10.)
662661
m := p.rtConstants
663662
m["_MSpanDead"] = 0
664663
m["_MSpanInUse"] = 1
@@ -679,6 +678,25 @@ func (p *Program) readRuntimeConstants() {
679678
m["kindDirectIface"] = 1 << 5
680679
m["_PageSize"] = 1 << 13
681680
m["_KindSpecialFinalizer"] = 1
681+
682+
// From 1.10, these constants are recorded in DWARF records.
683+
d, _ := p.proc.DWARF()
684+
r := d.Reader()
685+
for e, err := r.Next(); e != nil && err == nil; e, err = r.Next() {
686+
if e.Tag != dwarf.TagConstant {
687+
continue
688+
}
689+
name := e.AttrField(dwarf.AttrName).Val.(string)
690+
if !strings.HasPrefix(name, "runtime.") {
691+
continue
692+
}
693+
name = name[8:]
694+
c := e.AttrField(dwarf.AttrConstValue)
695+
if c == nil {
696+
continue
697+
}
698+
p.rtConstants[name] = c.Val.(int64)
699+
}
682700
}
683701

684702
const (

0 commit comments

Comments
 (0)