cmd/compile: output DWARF lexical blocks for local variables

Change compiler and linker to emit DWARF lexical blocks in debug_info.
Version of debug_info is updated from DWARF v.2 to DWARF v.3 since version 2
does not allow lexical blocks with discontinuous ranges.

Second attempt at https://go-review.googlesource.com/#/c/29591/

Remaining open problems:
- scope information is removed from inlined functions
- variables in debug_info do not have DW_AT_start_scope attributes so a
variable will shadow other variables with the same name as soon as its
containing scope begins, before its declaration.

Updates golang/go#12899, golang/go#6913

Change-Id: I0e260a45b564d14a87b88974eb16c5387cb410a5
Reviewed-on: https://go-review.googlesource.com/36879
Run-TryBot: Matthew Dempsky <mdempsky@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Alessandro Arzilli 2017-03-07 18:59:14 +01:00 committed by Matthew Dempsky
parent 7165bcc6ba
commit c8b889cc48
21 changed files with 890 additions and 110 deletions

View file

@ -570,9 +570,18 @@ func relocsym(ctxt *Link, s *Symbol) {
}
case obj.R_DWARFREF:
if r.Sym.Sect == nil {
sectName := ""
vaddr := int64(0)
if r.Sym.Sect != nil {
sectName = r.Sym.Sect.Name
vaddr = int64(r.Sym.Sect.Vaddr)
} else if r.Sym.Type == obj.SDWARFRANGE {
sectName = ".debug_ranges"
vaddr = 0
} else {
Errorf(s, "missing DWARF section for relocation target %s", r.Sym.Name)
}
if Linkmode == LinkExternal {
r.Done = 0
// PE code emits IMAGE_REL_I386_SECREL and IMAGE_REL_AMD64_SECREL
@ -584,8 +593,9 @@ func relocsym(ctxt *Link, s *Symbol) {
r.Type = obj.R_ADDR
}
r.Xsym = ctxt.Syms.ROLookup(r.Sym.Sect.Name, 0)
r.Xadd = r.Add + Symaddr(r.Sym) - int64(r.Sym.Sect.Vaddr)
r.Xsym = ctxt.Syms.ROLookup(sectName, 0)
r.Xadd = r.Add + Symaddr(r.Sym) - vaddr
o = r.Xadd
rs = r.Xsym
if Iself && SysArch.Family == sys.AMD64 {
@ -593,7 +603,7 @@ func relocsym(ctxt *Link, s *Symbol) {
}
break
}
o = Symaddr(r.Sym) + r.Add - int64(r.Sym.Sect.Vaddr)
o = Symaddr(r.Sym) + r.Add - vaddr
case obj.R_WEAKADDROFF:
if !r.Sym.Attr.Reachable() {
@ -1822,6 +1832,7 @@ func (ctxt *Link) dodata() {
if s.Type != obj.SDWARFSECT {
break
}
sect = addsection(&Segdwarf, s.Name, 04)
sect.Align = 1
datsize = Rnd(datsize, int64(sect.Align))