]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/internal/gc: directly produce importpath of package being compiled
authorMichael Hudson-Doyle <michael.hudson@canonical.com>
Thu, 19 Mar 2015 10:05:34 +0000 (23:05 +1300)
committerIan Lance Taylor <iant@golang.org>
Tue, 31 Mar 2015 20:31:55 +0000 (20:31 +0000)
Relying on an importing package being linked at the same time as the
imported package does not work in the shared library world.

This also lets us remove some obscure code from the linker.

Change-Id: I57cd5447b42a1a6129b02951d44efffb10cf64be
Reviewed-on: https://go-review.googlesource.com/7797
Reviewed-by: Russ Cox <rsc@golang.org>
src/cmd/internal/gc/reflect.go
src/cmd/internal/ld/lib.go

index 943b1f561e402563f5dcec9dc3c0fc900f69584c..35984f10464263de1df6225335be76a6d3f24dc7 100644 (file)
@@ -472,12 +472,25 @@ func dimportpath(p *Pkg) {
                return
        }
 
+       // If we are compiling the runtime package, there are two runtime packages around
+       // -- localpkg and Runtimepkg.  We don't want to produce import path symbols for
+       // both of them, so just produce one for localpkg.
+       if myimportpath == "runtime" && p == Runtimepkg {
+               return
+       }
+
        if dimportpath_gopkg == nil {
                dimportpath_gopkg = mkpkg("go")
                dimportpath_gopkg.Name = "go"
        }
 
-       nam := "importpath." + p.Prefix + "."
+       var nam string
+       if p == localpkg {
+               // Note: myimportpath != "", or else dgopkgpath won't call dimportpath.
+               nam = "importpath." + pathtoprefix(myimportpath) + "."
+       } else {
+               nam = "importpath." + p.Prefix + "."
+       }
 
        n := Nod(ONAME, nil, nil)
        n.Sym = Pkglookup(nam, dimportpath_gopkg)
@@ -495,10 +508,11 @@ func dgopkgpath(s *Sym, ot int, pkg *Pkg) int {
                return dgostringptr(s, ot, "")
        }
 
-       // Emit reference to go.importpath.""., which 6l will
-       // rewrite using the correct import path.  Every package
-       // that imports this one directly defines the symbol.
-       if pkg == localpkg {
+       if pkg == localpkg && myimportpath == "" {
+               // If we don't know the full path of the package being compiled (i.e. -p
+               // was not passed on the compiler command line), emit reference to
+               // go.importpath.""., which 6l will rewrite using the correct import path.
+               // Every package that imports this one directly defines the symbol.
                var ns *Sym
 
                if ns == nil {
index 48fd8bc9562225d84924c16472e99ca47faacf4d..b3317d67e176ddcf56537021c2f64711691d9cab 100644 (file)
@@ -379,24 +379,6 @@ func loadlib() {
                if i < len(Ctxt.Library) {
                        objfile(Ctxt.Library[i].File, Ctxt.Library[i].Pkg)
                }
-
-               // Pretend that we really imported the package.
-               s := Linklookup(Ctxt, "go.importpath.runtime/cgo.", 0)
-
-               s.Type = SDATA
-               s.Dupok = 1
-               s.Reachable = true
-
-               // Provided by the code that imports the package.
-               // Since we are simulating the import, we have to provide this string.
-               cgostrsym := "go.string.\"runtime/cgo\""
-
-               if Linkrlookup(Ctxt, cgostrsym, 0) == nil {
-                       s := Linklookup(Ctxt, cgostrsym, 0)
-                       s.Type = SRODATA
-                       s.Reachable = true
-                       addstrdata(cgostrsym, "runtime/cgo")
-               }
        }
 
        if Linkmode == LinkInternal {