-
Notifications
You must be signed in to change notification settings - Fork 18k
cmd/link: seg fault in shared buildmode from main package with exported variable #22566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I can't recreate this. What happens if you omit |
Yes, I have run
Since you can't reproduce, I will try this again with a clean environment and post back. |
I just verified that I get the same result on a clean environment. Here is a Dockerfile I used:
|
I can reproduce it on linux/amd64. The seg fault is from reading This seems to happen only when
|
#16632 is the same problem. |
This only happens when the package name is "main", which seems to cause the toolchain to believe that it is building in plugin mode, and start to generate a lot more stuff than it would otherwise. The relocation that is missing a section is in go.plugin.tabs SRODATA size=8 0x0000 00 00 00 00 00 00 00 00 ........ rel 0+4 t=5 type..namedata.Bar.+0 rel 4+4 t=5 type.*int+0 If the package was something other than "main", the compiler proceeds in shared mode, and there is no relocation:
|
I think both this and #16632 can be solved by moving basic types and import paths from the runtime package into the main package. Edit: I realize that in general it's hard to tell whether a package will be the main package at compile time. |
My understanding is that this only happens when using |
Obsoleted by #47788 |
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (
go version
)?go version go1.9.2 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/brice/go"
GORACE=""
GOROOT="/usr/local/go-1.9.2"
GOTOOLDIR="/usr/local/go-1.9.2/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build769375432=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
What did you do?
Create a simple source file:
Build it with buildmode shared:
What did you expect to see?
I expected it to build a shared library.
What did you see instead?
The linker crashes with a set fault:
Note: If the global variable is not exported (rename it to
bar
), then it builds as expected.The text was updated successfully, but these errors were encountered: