mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00:00
cmd/compile: add ideal int constants to dwarf
The core dump reader would like a bunch of ideal int constants to be available in dwarf. Makes the go binary 0.9% bigger. Update #14517 Change-Id: I00cdfc7f53bcdc56fccba576c1d33010f03bdd95 Reviewed-on: https://go-review.googlesource.com/69270 Run-TryBot: Keith Randall <khr@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com>
This commit is contained in:
parent
4a2376ef02
commit
7830a19a4f
2 changed files with 16 additions and 4 deletions
|
|
@ -219,14 +219,15 @@ func dumpGlobal(n *Node) {
|
||||||
|
|
||||||
func dumpGlobalConst(n *Node) {
|
func dumpGlobalConst(n *Node) {
|
||||||
// only export typed constants
|
// only export typed constants
|
||||||
if n.Type == nil {
|
t := n.Type
|
||||||
|
if t == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if n.Sym.Pkg != localpkg {
|
if n.Sym.Pkg != localpkg {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// only export integer constants for now
|
// only export integer constants for now
|
||||||
switch n.Type.Etype {
|
switch t.Etype {
|
||||||
case TINT8:
|
case TINT8:
|
||||||
case TINT16:
|
case TINT16:
|
||||||
case TINT32:
|
case TINT32:
|
||||||
|
|
@ -239,10 +240,20 @@ func dumpGlobalConst(n *Node) {
|
||||||
case TUINT:
|
case TUINT:
|
||||||
case TUINTPTR:
|
case TUINTPTR:
|
||||||
// ok
|
// ok
|
||||||
|
case TIDEAL:
|
||||||
|
if !Isconst(n, CTINT) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
x := n.Val().U.(*Mpint)
|
||||||
|
if x.Cmp(minintval[TINT]) < 0 || x.Cmp(maxintval[TINT]) > 0 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Ideal integers we export as int (if they fit).
|
||||||
|
t = types.Types[TINT]
|
||||||
default:
|
default:
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
Ctxt.DwarfIntConst(myimportpath, n.Sym.Name, typesymname(n.Type), n.Int64())
|
Ctxt.DwarfIntConst(myimportpath, n.Sym.Name, typesymname(t), n.Int64())
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpglobls() {
|
func dumpglobls() {
|
||||||
|
|
|
||||||
|
|
@ -427,6 +427,7 @@ func TestGdbConst(t *testing.T) {
|
||||||
"-ex", "print main.largeConstant",
|
"-ex", "print main.largeConstant",
|
||||||
"-ex", "print main.minusOne",
|
"-ex", "print main.minusOne",
|
||||||
"-ex", "print 'runtime._MSpanInUse'",
|
"-ex", "print 'runtime._MSpanInUse'",
|
||||||
|
"-ex", "print 'runtime._PageSize'",
|
||||||
filepath.Join(dir, "a.exe"),
|
filepath.Join(dir, "a.exe"),
|
||||||
}
|
}
|
||||||
got, _ := exec.Command("gdb", args...).CombinedOutput()
|
got, _ := exec.Command("gdb", args...).CombinedOutput()
|
||||||
|
|
@ -435,7 +436,7 @@ func TestGdbConst(t *testing.T) {
|
||||||
|
|
||||||
t.Logf("output %q", sgot)
|
t.Logf("output %q", sgot)
|
||||||
|
|
||||||
if !strings.Contains(sgot, "\n$1 = 42\n$2 = 18446744073709551615\n$3 = -1\n$4 = 1 '\\001'") {
|
if !strings.Contains(sgot, "\n$1 = 42\n$2 = 18446744073709551615\n$3 = -1\n$4 = 1 '\\001'\n$5 = 8192") {
|
||||||
t.Fatalf("output mismatch")
|
t.Fatalf("output mismatch")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue