Commit 65a649c5 authored by Cherry Zhang's avatar Cherry Zhang

[dev.link] cmd/link, cmd/internal/goobj2: adopt new DWARF compilation unit...

[dev.link] cmd/link, cmd/internal/goobj2: adopt new DWARF compilation unit logic with new object file

The dev.link branch was not sync'd with the new DWARF compilation
unit logic change on the master branch, and the new object file
format didn't support this.

This CL adds the new DWARF CU and file table support to the new
object file format. In the old object file, the DWARF file table
is a separate section. For now, we do the same with the new
object file, keeping it as a separate block.

While here, also refactor the loader code so it is easier for the
loader to carry per-object informations.

Change-Id: I4c317941fc0a5831acbc11ce8c2a8b7421471372
Reviewed-on: https://go-review.googlesource.com/c/go/+/198198Reviewed-by: default avatarAustin Clements <austin@google.com>
parent 0d7404c8
......@@ -31,6 +31,8 @@ import (
//
// PkgIndex [...]stringOff // TODO: add fingerprints
//
// DwarfFiles [...]stringOff // XXX as a separate block for now
//
// SymbolDefs [...]struct {
// Name stringOff
// ABI uint16
......@@ -126,6 +128,7 @@ const (
// Blocks
const (
BlkPkgIdx = iota
BlkDwarfFile
BlkSymdef
BlkNonpkgdef
BlkNonpkgref
......@@ -471,6 +474,24 @@ func (r *Reader) Pkglist() []string {
return s
}
func (r *Reader) NPkg() int {
return int(r.h.Offsets[BlkPkgIdx+1]-r.h.Offsets[BlkPkgIdx]) / 4
}
func (r *Reader) Pkg(i int) string {
off := r.h.Offsets[BlkPkgIdx] + uint32(i)*4
return r.StringRef(off)
}
func (r *Reader) NDwarfFile() int {
return int(r.h.Offsets[BlkDwarfFile+1]-r.h.Offsets[BlkDwarfFile]) / 4
}
func (r *Reader) DwarfFile(i int) string {
off := r.h.Offsets[BlkDwarfFile] + uint32(i)*4
return r.StringRef(off)
}
func (r *Reader) NSym() int {
symsiz := (&Sym{}).Size()
return int(r.h.Offsets[BlkSymdef+1]-r.h.Offsets[BlkSymdef]) / symsiz
......@@ -531,6 +552,11 @@ func (r *Reader) DataSize(i int) int {
return int(r.DataOff(i+1) - r.DataOff(i))
}
// Data returns the i-th symbol's data.
func (r *Reader) Data(i int) []byte {
return r.BytesAt(r.DataOff(i), r.DataSize(i))
}
// AuxDataBase returns the base offset of the aux data block.
func (r *Reader) PcdataBase() uint32 {
return r.h.Offsets[BlkPcdata]
......
......@@ -42,6 +42,12 @@ func WriteObjFile2(ctxt *Link, b *bio.Writer, pkgpath string) {
w.StringRef(pkg)
}
// DWARF file table
h.Offsets[goobj2.BlkDwarfFile] = w.Offset()
for _, f := range ctxt.PosTable.DebugLinesFileTable() {
w.StringRef(f)
}
// Symbol definitions
h.Offsets[goobj2.BlkSymdef] = w.Offset()
for _, s := range ctxt.defs {
......@@ -198,6 +204,9 @@ func (w *writer) StringTable() {
w.AddString(f)
}
})
for _, f := range w.ctxt.PosTable.DebugLinesFileTable() {
w.AddString(f)
}
}
func (w *writer) Sym(s *LSym) {
......
......@@ -403,11 +403,7 @@ func (ctxt *Link) loadlib() {
if *flagNewobj {
// Add references of externally defined symbols.
for _, lib := range ctxt.Library {
for _, r := range lib.Readers {
objfile.LoadRefs(ctxt.loader, r.Reader, lib, ctxt.Arch, ctxt.Syms, r.Version)
}
}
objfile.LoadRefs(ctxt.loader, ctxt.Arch, ctxt.Syms)
// Load cgo directives.
for _, p := range ctxt.cgodata {
......@@ -550,11 +546,7 @@ func (ctxt *Link) loadlib() {
// For now, load relocations for dead-code elimination.
if *flagNewobj {
for _, lib := range ctxt.Library {
for _, r := range lib.Readers {
objfile.LoadReloc(ctxt.loader, r.Reader, lib, r.Version, ctxt.LibraryByPkg)
}
}
objfile.LoadReloc(ctxt.loader)
}
}
......@@ -2545,11 +2537,7 @@ func dfs(lib *sym.Library, mark map[*sym.Library]markKind, order *[]*sym.Library
func (ctxt *Link) loadlibfull() {
// Load full symbol contents, resolve indexed references.
for _, lib := range ctxt.Library {
for _, r := range lib.Readers {
objfile.LoadFull(ctxt.loader, r.Reader, lib, r.Version, ctxt.LibraryByPkg)
}
}
objfile.LoadFull(ctxt.loader)
// For now, add all symbols to ctxt.Syms.
for _, s := range ctxt.loader.Syms {
......@@ -2557,6 +2545,9 @@ func (ctxt *Link) loadlibfull() {
ctxt.Syms.Add(s)
}
}
// Drop the reference.
ctxt.loader = nil
}
func (ctxt *Link) dumpsyms() {
......
This diff is collapsed.
......@@ -4,8 +4,6 @@
package sym
import "cmd/internal/goobj2"
type Library struct {
Objref string
Srcref string
......@@ -20,11 +18,6 @@ type Library struct {
Main bool
Safe bool
Units []*CompilationUnit
Readers []struct { // TODO: probably move this to Loader
Reader *goobj2.Reader
Version int
}
}
func (l Library) String() string {
......
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