opened
lxstorm
username_0
<!-- Please answer these questions before submitting your issue. Thanks! -->

### What version of Go are you using (`go version`)?

<pre>
$ go version
go version go1.12.1 darwin/amd64
</pre>

### Does this issue reproduce with the latest release?
Yes


### What operating system and processor architecture are you using (`go env`)?

<details><summary><code>go env</code> Output</summary><br><pre>
$ go env
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/lx/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/lx/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/Cellar/go/1.12.1/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.12.1/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/7k/r2p50mb149ngfkbmdw9tdqhc0000gp/T/go-build367373739=/tmp/go-build -gno-record-gcc-switches -fno-common"
</pre></details>

### What did you do?

<!--
If possible, provide a recipe for reproducing the error.
A complete runnable program is good.
A link on play.golang.org is best.
-->
I write a demo to test the go plugin, My work directory structure is 
<pre>
|____gen
| |____src
| | |____main
| | | |____main.go
|____plugin_name.so
|____build.sh
|____main.go
</pre>
main.go
<pre>
package main

import "plugin"

func main() {
	p, err := plugin.Open("plugin_name.so")
	if err != nil {
		panic(err)
	}
	v, err := p.Lookup("V")
	if err != nil {
		panic(err)
	}
	f, err := p.Lookup("F")
	if err != nil {
		panic(err)
	}
	*v.(*int) = 7
	f.(func())()
}</pre>
gen/src/main/main.go
<pre>
package main

import "fmt"

var V int
func F() { fmt.Printf("Hello, number %d\n", V) }
</pre>
build.sh
<pre>
DIRPATH=$(dirname $0)
GOPATH=$(cd "${DIRPATH}/gen"; pwd)

export GOPATH
cd ${GOPATH}/src/main
go build -v -o plugin_name.so  -buildmode=plugin
mv plugin_name.so ${GOPATH}/..
</pre>


### What did you expect to see?
<pre>
sh ./build.sh
go run main.go
</pre>
I expect to see the main.go load the plugin successfully and print line.
### What did you see instead?
<pre>
panic: plugin.Open("plugin_name"): plugin was built with a different version of package main

goroutine 1 [running]:

main.main()
	/Users/lx/go/src/testZoom/tplugin/main.go:8 +0x38b
exit status 2
</pre>


Why the main package is a different version, howerver if I modify the build.sh to 
<pre>
go build -v -o plugin_name.so  -buildmode=plugin main.go
</pre>
Then go run main.go load so successfully. 

How can the main package be a different version and why the second solution success?
plugin different version of package main
issue
created
Kings-gee
username_1
probably cause by
https://github.com/golang/go/blob/release-branch.go1.12/src/cmd/go/internal/work/gc.go#L492
comment
created
katiehockman
username_2
/cc @ianlancetaylor
comment