]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.link] cmd/internal/goobj2: separate Autolib from Pkglist in new object file
authorCherry Zhang <cherryyz@google.com>
Wed, 9 Oct 2019 14:22:02 +0000 (10:22 -0400)
committerCherry Zhang <cherryyz@google.com>
Mon, 14 Oct 2019 22:28:25 +0000 (22:28 +0000)
In CL 196030 we decided to combine the imported package list
(Autolib) and referenced package list (PkgIdx, or Pkglist).
However, in some cases the Autolib list may contain file name,
instead of package path, e.g.
https://go.googlesource.com/go/+/refs/heads/dev.link/src/cmd/compile/internal/gc/main.go#1181
And the linker needs that to locate the file. This mostly happens
with direct invocation of the compiler and linker (i.e., not
through "go build").

Instead of letting the linker make guess of the file name based
on the package path, make Autolib a separate list.

Change-Id: If195a69462d04db515346ee67cdec925f5a69e2e
Reviewed-on: https://go-review.googlesource.com/c/go/+/200157
Run-TryBot: Cherry Zhang <cherryyz@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Jeremy Faller <jeremy@golang.org>
src/cmd/internal/goobj/readnew.go
src/cmd/internal/goobj2/objfile.go
src/cmd/internal/obj/objfile2.go
src/cmd/link/internal/objfile/objfile2.go

index f33bbf73b133b28dcf1c68ca2dce2692c26132c9..6e6ec02f608cf26ebabbc4677554dee69d587998 100644 (file)
@@ -21,8 +21,9 @@ func (r *objReader) readNew() {
        }
 
        // Imports
+       r.p.Imports = rr.Autolib()
+
        pkglist := rr.Pkglist()
-       r.p.Imports = pkglist[1:] // index 0 is a dummy invalid package
 
        abiToVer := func(abi uint16) int64 {
                var vers int64
index c92b9dd9af3a06e4ff8e3e4b6e1bc872f1649322..e15dbdca69c7559fa46e9599849fc0aaee23bbb8 100644 (file)
@@ -29,7 +29,8 @@ import (
 //       Data [...]byte
 //    }
 //
-//    PkgIndex [...]stringOff // TODO: add fingerprints
+//    Autolib  [...]stringOff // imported packages (for file loading) // TODO: add fingerprints
+//    PkgIndex [...]stringOff // referenced packages by index
 //
 //    DwarfFiles [...]stringOff // XXX as a separate block for now
 //
@@ -127,7 +128,8 @@ const (
 
 // Blocks
 const (
-       BlkPkgIdx = iota
+       BlkAutolib = iota
+       BlkPkgIdx
        BlkDwarfFile
        BlkSymdef
        BlkNonpkgdef
@@ -469,6 +471,16 @@ func (r *Reader) StringRef(off uint32) string {
        return r.StringAt(r.uint32At(off))
 }
 
+func (r *Reader) Autolib() []string {
+       n := (r.h.Offsets[BlkAutolib+1] - r.h.Offsets[BlkAutolib]) / 4
+       s := make([]string, n)
+       for i := range s {
+               off := r.h.Offsets[BlkAutolib] + uint32(i)*4
+               s[i] = r.StringRef(off)
+       }
+       return s
+}
+
 func (r *Reader) Pkglist() []string {
        n := (r.h.Offsets[BlkPkgIdx+1] - r.h.Offsets[BlkPkgIdx]) / 4
        s := make([]string, n)
index 39e2a4f2248dd69d66cf189aba3aa9faeed84429..caa442c0d3802aca8f973a1d3ebb18494da441a3 100644 (file)
@@ -40,6 +40,12 @@ func WriteObjFile2(ctxt *Link, b *bio.Writer, pkgpath string) {
        // String table
        w.StringTable()
 
+       // Autolib
+       h.Offsets[goobj2.BlkAutolib] = w.Offset()
+       for _, pkg := range ctxt.Imports {
+               w.StringRef(pkg)
+       }
+
        // Package references
        h.Offsets[goobj2.BlkPkgIdx] = w.Offset()
        for _, pkg := range w.pkglist {
@@ -172,13 +178,6 @@ func (w *writer) init() {
        for pkg, i := range w.ctxt.pkgIdx {
                w.pkglist[i] = pkg
        }
-
-       // Also make sure imported packages appear in the list (even if no symbol is referenced).
-       for _, pkg := range w.ctxt.Imports {
-               if _, ok := w.ctxt.pkgIdx[pkg]; !ok {
-                       w.pkglist = append(w.pkglist, pkg)
-               }
-       }
 }
 
 func (w *writer) StringTable() {
index cc472954ab71d5c10c94924d8600987386fe8179..00c996c3413ada946cc59e0171055c48b8d98add 100644 (file)
@@ -366,11 +366,7 @@ func LoadNew(l *Loader, arch *sys.Arch, syms *sym.Symbols, f *bio.Reader, lib *s
        or := &oReader{r, unit, localSymVersion, pkgprefix}
 
        // Autolib
-       npkg := r.NPkg()
-       lib.ImportStrings = append(lib.ImportStrings, make([]string, npkg-1)...)[:len(lib.ImportStrings)]
-       for i := 1; i < npkg; i++ {
-               lib.ImportStrings = append(lib.ImportStrings, r.Pkg(i))
-       }
+       lib.ImportStrings = append(lib.ImportStrings, r.Autolib()...)
 
        // DWARF file table
        nfile := r.NDwarfFile()