diff --git a/src/cmd/compile/internal/gc/main.go b/src/cmd/compile/internal/gc/main.go
index bb28ef01a1d30d833dc6b042efd013b747f7c708..4417e70616cb5f8dd95348e18a28e0d3ea679a5e 100644
--- a/src/cmd/compile/internal/gc/main.go
+++ b/src/cmd/compile/internal/gc/main.go
@@ -285,6 +285,8 @@ func Main(archInit func(*Arch)) {
 
 	objabi.Flagparse(usage)
 
+	Ctxt.Pkgpath = myimportpath
+
 	for _, f := range strings.Split(spectre, ",") {
 		f = strings.TrimSpace(f)
 		switch f {
@@ -789,7 +791,6 @@ func Main(archInit func(*Arch)) {
 	// Write object data to disk.
 	timings.Start("be", "dumpobj")
 	dumpdata()
-	Ctxt.Pkgpath = myimportpath
 	Ctxt.NumberSyms()
 	dumpobj()
 	if asmhdr != "" {
diff --git a/src/cmd/dist/build.go b/src/cmd/dist/build.go
index 9e2b4f33b866b9b10a6326cd342a3a50822695b2..a817e6fcd7dbfdf832e815a8c15aa9b49bf9ed92 100644
--- a/src/cmd/dist/build.go
+++ b/src/cmd/dist/build.go
@@ -824,6 +824,7 @@ func runInstall(pkg string, ch chan struct{}) {
 		"-D", "GOOS_" + goos,
 		"-D", "GOARCH_" + goarch,
 		"-D", "GOOS_GOARCH_" + goos + "_" + goarch,
+		"-p", pkg,
 	}
 	if goarch == "mips" || goarch == "mipsle" {
 		// Define GOMIPS_value from gomips.