From: Than McIntosh Date: Thu, 12 Mar 2020 15:04:36 +0000 (-0400) Subject: [dev.link] cmd/link: remove unnecessary file processing from writelines X-Git-Tag: go1.15beta1~679^2~77 X-Git-Url: http://www.git.cypherpunks.su/?a=commitdiff_plain;h=a6ae6d35e6145cd271dc3775827579d9c8f62df6;p=gostls13.git [dev.link] cmd/link: remove unnecessary file processing from writelines The linker DWARF-gen's line table writing routine contains a loop that walks all abstract function DIEs looking for files that aren't referenced in concrete function DIEs. Turns out this loop is no longer necessary, most likely because the compiler emits an explicit DWARF file table into the object file. This patch removes the offending loop. This is a prelude to some additional work that will hopefully get rid of file renumbering in writelines altogether (still WIP). Change-Id: I3b3a9acce1bae7dda878ab6de2d3436de302712e Reviewed-on: https://go-review.googlesource.com/c/go/+/223145 Run-TryBot: Than McIntosh TryBot-Result: Gobot Gobot Reviewed-by: Jeremy Faller Reviewed-by: Cherry Zhang --- diff --git a/src/cmd/link/internal/ld/dwarf.go b/src/cmd/link/internal/ld/dwarf.go index 0c31bf8c6f..8376ea82db 100644 --- a/src/cmd/link/internal/ld/dwarf.go +++ b/src/cmd/link/internal/ld/dwarf.go @@ -1211,35 +1211,6 @@ func (d *dwctxt2) writelines(unit *sym.CompilationUnit, ls loader.Sym) { } } - // Grab files for inlined functions. - // TODO: With difficulty, this could be moved into the compiler. - rslice := []loader.Reloc{} - for _, s := range unit.Textp2 { - fnSym := loader.Sym(s) - infosym, _, _, _ := d.ldr.GetFuncDwarfAuxSyms(fnSym) - drelocs := d.ldr.Relocs(infosym) - rslice = drelocs.ReadSyms(rslice) - for ri := 0; ri < len(rslice); ri++ { - r := &rslice[ri] - if r.Type != objabi.R_DWARFFILEREF { - continue - } - fname, ok := expandedFiles[r.Sym] - if !ok { - fname = expandFileSym(d.ldr, r.Sym) - expandedFiles[r.Sym] = fname - } - if _, ok := fileNums[fname]; ok { - continue - } - fileNums[fname] = len(fileNums) + 1 - d.AddString(lsDwsym, fname) - lsu.AddUint8(0) - lsu.AddUint8(0) - lsu.AddUint8(0) - } - } - // 4 zeros: the string termination + 3 fields. lsu.AddUint8(0) // terminate file_names. @@ -1247,6 +1218,7 @@ func (d *dwctxt2) writelines(unit *sym.CompilationUnit, ls loader.Sym) { // Output the state machine for each function remaining. var lastAddr int64 + rslice := []loader.Reloc{} for _, s := range unit.Textp2 { fnSym := loader.Sym(s) @@ -1318,7 +1290,8 @@ func (d *dwctxt2) writelines(unit *sym.CompilationUnit, ls loader.Sym) { fname, ok := expandedFiles[r.Sym] if !ok { - panic("bad") + fname = expandFileSym(d.ldr, r.Sym) + expandedFiles[r.Sym] = fname } idx, ok := fileNums[fname] @@ -1339,7 +1312,6 @@ func (d *dwctxt2) writelines(unit *sym.CompilationUnit, ls loader.Sym) { d.ldr.SetAttrReachable(r.Sym, true) d.ldr.SetAttrNotInSymbolTable(r.Sym, true) - r.Add = int64(idx) // record the index in r.Add, we'll apply it in the reloc phase. } else { sv := d.ldr.SymValue(r.Sym)