cmd/internal/gc: directly produce importpath of package being compiled
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>
diff --git a/src/cmd/internal/gc/reflect.go b/src/cmd/internal/gc/reflect.go
index 943b1f56..35984f1 100644
--- a/src/cmd/internal/gc/reflect.go
+++ b/src/cmd/internal/gc/reflect.go
@@ -472,12 +472,25 @@
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 @@
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 {