Commit 795ad07b authored by Michael Matloob's avatar Michael Matloob

cmd: generate DWARF for functions in compile instead of link.

This is a copy of golang.org/cl/22092 by Ryan Brown.

Here's his original comment:
On my machine this increases the average time for 'go build cmd/go' from
2.25s to 2.36s. I tried to measure compile and link separately but saw
no significant change.

Change-Id: If0d2b756d52a0d30d4eda526929c82794d89dd7b
Reviewed-on: https://go-review.googlesource.com/25311
Run-TryBot: Michael Matloob <matloob@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: default avatarDavid Crawshaw <crawshaw@golang.org>
parent 11e93aa2
...@@ -41,6 +41,7 @@ var bootstrapDirs = []string{ ...@@ -41,6 +41,7 @@ var bootstrapDirs = []string{
"compile/internal/s390x", "compile/internal/s390x",
"internal/bio", "internal/bio",
"internal/gcprog", "internal/gcprog",
"internal/dwarf",
"internal/obj", "internal/obj",
"internal/obj/arm", "internal/obj/arm",
"internal/obj/arm64", "internal/obj/arm64",
......
This diff is collapsed.
...@@ -2,40 +2,7 @@ ...@@ -2,40 +2,7 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
package ld package dwarf
// TODO/NICETOHAVE:
// - eliminate DW_CLS_ if not used
// - package info in compilation units
// - assign global variables and types to their packages
// - gdb uses c syntax, meaning clumsy quoting is needed for go identifiers. eg
// ptype struct '[]uint8' and qualifiers need to be quoted away
// - lexical scoping is lost, so gdb gets confused as to which 'obj.i' you mean.
// - file:line info for variables
// - make strings a typedef so prettyprinters can see the underlying string type
//
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
/*
* Emit debug_abbrevs, debug_info and debug_line sections to current
* offset in cout.
*/
/*
* Add the dwarf section names to the ELF
* s[ection]h[eader]str[ing]tab. Prerequisite for
* dwarfaddelfheaders().
*/
/*
* Add section headers pointing to the sections emitted in
* dwarfemitdebugsections.
*/
// Copyright 2010 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Cut, pasted, tr-and-awk'ed from tables in // Cut, pasted, tr-and-awk'ed from tables in
// http://dwarfstd.org/doc/Dwarf3.pdf // http://dwarfstd.org/doc/Dwarf3.pdf
......
...@@ -109,6 +109,7 @@ package obj ...@@ -109,6 +109,7 @@ package obj
import ( import (
"bufio" "bufio"
"cmd/internal/dwarf"
"cmd/internal/sys" "cmd/internal/sys"
"fmt" "fmt"
"log" "log"
...@@ -506,3 +507,94 @@ type relocByOff []Reloc ...@@ -506,3 +507,94 @@ type relocByOff []Reloc
func (x relocByOff) Len() int { return len(x) } func (x relocByOff) Len() int { return len(x) }
func (x relocByOff) Less(i, j int) bool { return x[i].Off < x[j].Off } func (x relocByOff) Less(i, j int) bool { return x[i].Off < x[j].Off }
func (x relocByOff) Swap(i, j int) { x[i], x[j] = x[j], x[i] } func (x relocByOff) Swap(i, j int) { x[i], x[j] = x[j], x[i] }
// implement dwarf.Context
type dwCtxt struct{ *Link }
func (c dwCtxt) PtrSize() int {
return c.Arch.PtrSize
}
func (c dwCtxt) AddInt(s dwarf.Sym, size int, i int64) {
ls := s.(*LSym)
ls.WriteInt(c.Link, ls.Size, size, i)
}
func (c dwCtxt) AddBytes(s dwarf.Sym, b []byte) {
ls := s.(*LSym)
ls.WriteBytes(c.Link, ls.Size, b)
}
func (c dwCtxt) AddString(s dwarf.Sym, v string) {
ls := s.(*LSym)
ls.WriteString(c.Link, ls.Size, len(v), v)
ls.WriteInt(c.Link, ls.Size, 1, 0)
}
func (c dwCtxt) SymValue(s dwarf.Sym) int64 {
return 0
}
func (c dwCtxt) AddAddress(s dwarf.Sym, data interface{}, value int64) {
rsym := data.(*LSym)
ls := s.(*LSym)
size := c.PtrSize()
ls.WriteAddr(c.Link, ls.Size, size, rsym, value)
}
func (c dwCtxt) AddSectionOffset(s dwarf.Sym, size int, t interface{}, ofs int64) {
ls := s.(*LSym)
rsym := t.(*LSym)
ls.WriteAddr(c.Link, ls.Size, size, rsym, ofs)
r := &ls.R[len(ls.R)-1]
r.Type = R_DWARFREF
}
func gendwarf(ctxt *Link, text []*LSym) []*LSym {
dctxt := dwCtxt{ctxt}
var dw []*LSym
for _, s := range text {
dsym := Linklookup(ctxt, dwarf.InfoPrefix+s.Name, int(s.Version))
if dsym.Size != 0 {
continue
}
dw = append(dw, dsym)
dsym.Type = SDWARFINFO
dsym.Dupok = s.Dupok
var vars dwarf.Var
var abbrev int
var offs int32
for a := s.Autom; a != nil; a = a.Link {
switch a.Name {
case NAME_AUTO:
abbrev = dwarf.DW_ABRV_AUTO
offs = a.Aoffset
if ctxt.FixedFrameSize() == 0 {
offs -= int32(ctxt.Arch.PtrSize)
}
if Framepointer_enabled(Getgoos(), Getgoarch()) {
offs -= int32(ctxt.Arch.PtrSize)
}
case NAME_PARAM:
abbrev = dwarf.DW_ABRV_PARAM
offs = a.Aoffset + int32(ctxt.FixedFrameSize())
default:
continue
}
typename := dwarf.InfoPrefix + a.Gotype.Name[len("type."):]
dwvar := &dwarf.Var{
Name: a.Asym.Name,
Abbrev: abbrev,
Offset: int32(offs),
Type: Linklookup(ctxt, typename, 0),
}
dws := &vars.Link
for ; *dws != nil; dws = &(*dws).Link {
if offs <= (*dws).Offset {
break
}
}
dwvar.Link = *dws
*dws = dwvar
}
dwarf.PutFunc(dctxt, dsym, s.Name, s.Version == 0, s, s.Size, vars.Link)
}
return dw
}
...@@ -209,6 +209,7 @@ func flushplist(ctxt *Link, freeProgs bool) { ...@@ -209,6 +209,7 @@ func flushplist(ctxt *Link, freeProgs bool) {
// Add to running list in ctxt. // Add to running list in ctxt.
ctxt.Text = append(ctxt.Text, text...) ctxt.Text = append(ctxt.Text, text...)
ctxt.Data = append(ctxt.Data, gendwarf(ctxt, text)...)
ctxt.Plist = nil ctxt.Plist = nil
ctxt.Plast = nil ctxt.Plast = nil
ctxt.Curp = nil ctxt.Curp = nil
......
...@@ -342,8 +342,14 @@ func relocsym(s *LSym) { ...@@ -342,8 +342,14 @@ func relocsym(s *LSym) {
if r.Sym != nil && (r.Sym.Type&(obj.SMASK|obj.SHIDDEN) == 0 || r.Sym.Type&obj.SMASK == obj.SXREF) { if r.Sym != nil && (r.Sym.Type&(obj.SMASK|obj.SHIDDEN) == 0 || r.Sym.Type&obj.SMASK == obj.SXREF) {
// When putting the runtime but not main into a shared library // When putting the runtime but not main into a shared library
// these symbols are undefined and that's OK. // these symbols are undefined and that's OK.
if Buildmode == BuildmodeShared && (r.Sym.Name == "main.main" || r.Sym.Name == "main.init") { if Buildmode == BuildmodeShared {
if r.Sym.Name == "main.main" || r.Sym.Name == "main.init" {
r.Sym.Type = obj.SDYNIMPORT r.Sym.Type = obj.SDYNIMPORT
} else if strings.HasPrefix(r.Sym.Name, "go.info.") {
// Skip go.info symbols. They are only needed to communicate
// DWARF info between the compiler and linker.
continue
}
} else { } else {
Diag("%s: not defined", r.Sym.Name) Diag("%s: not defined", r.Sym.Name)
continue continue
......
This diff is collapsed.
...@@ -111,6 +111,7 @@ import ( ...@@ -111,6 +111,7 @@ import (
"bufio" "bufio"
"bytes" "bytes"
"cmd/internal/bio" "cmd/internal/bio"
"cmd/internal/dwarf"
"cmd/internal/obj" "cmd/internal/obj"
"crypto/sha1" "crypto/sha1"
"encoding/base64" "encoding/base64"
...@@ -401,6 +402,37 @@ overwrite: ...@@ -401,6 +402,37 @@ overwrite:
r.ctxt.Textp = append(r.ctxt.Textp, s) r.ctxt.Textp = append(r.ctxt.Textp, s)
} }
} }
if s.Type == obj.SDWARFINFO {
r.patchDWARFName(s)
}
}
func (r *objReader) patchDWARFName(s *LSym) {
// This is kind of ugly. Really the package name should not
// even be included here.
if s.Size < 1 || s.P[0] != dwarf.DW_ABRV_FUNCTION {
return
}
e := bytes.IndexByte(s.P, 0)
if e == -1 {
return
}
p := bytes.Index(s.P[:e], emptyPkg)
if p == -1 {
return
}
pkgprefix := []byte(r.pkg + ".")
patched := bytes.Replace(s.P[:e], emptyPkg, pkgprefix, -1)
s.P = append(patched, s.P[e:]...)
delta := int64(len(s.P)) - s.Size
s.Size = int64(len(s.P))
for i := range s.R {
r := &s.R[i]
if r.Off > int32(e) {
r.Off += int32(delta)
}
}
} }
func (r *objReader) readFull(b []byte) { func (r *objReader) readFull(b []byte) {
......
...@@ -269,6 +269,8 @@ func Asmplan9sym() { ...@@ -269,6 +269,8 @@ func Asmplan9sym() {
var symt *LSym var symt *LSym
var encbuf [10]byte
func Wputb(w uint16) { Cwrite(Append16b(encbuf[:0], w)) } func Wputb(w uint16) { Cwrite(Append16b(encbuf[:0], w)) }
func Lputb(l uint32) { Cwrite(Append32b(encbuf[:0], l)) } func Lputb(l uint32) { Cwrite(Append32b(encbuf[:0], l)) }
func Vputb(v uint64) { Cwrite(Append64b(encbuf[:0], v)) } func Vputb(v uint64) { Cwrite(Append64b(encbuf[:0], v)) }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment