Skip to content
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

cmd/link: segfault given a text section named after a type #18715

Closed
pwaller opened this issue Jan 19, 2017 · 6 comments

Comments

Projects
None yet
5 participants
@pwaller
Copy link
Contributor

commented Jan 19, 2017

Go1.8-rc1

Go env output

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/pwaller/.local"
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build905941285=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"

The following code crashes the linker. Granted, it is incorrect, but I encountered this by accident in a medium sized code base and it was difficult to figure out what was going wrong.

The linker crashes given this main.go and main.s.

main.go

package main

type FooType struct{}

type T1 struct{}

func (t1 *T1) MakeFoo() *FooType { return nil }

func main() {
	var t1 *T1
	_ = t1.MakeFoo
}

main.s

TEXT ·FooType(SB),0,$0

Output

# github.com/pwaller/crash/go-1.8rc1-linker
go.info.*github.com/pwaller/crash/go-1.8rc1-linker/pkg.FooType: unreachable sym in relocation: go.info.github.com/pwaller/crash/go-1.8rc1-linker/pkg.FooType
go.info.*github.com/pwaller/crash/go-1.8rc1-linker/pkg.FooType: missing DWARF section for relocation target go.info.github.com/pwaller/crash/go-1.8rc1-linker/pkg.FooType
go.info.github.com/pwaller/crash/go-1.8rc1-linker/pkg.FooType: unreachable symbol in symaddr
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x52941e]

goroutine 1 [running]:
cmd/link/internal/ld.relocsym(0xc4204ee000, 0xc42050ce80)
	/usr/local/go/src/cmd/link/internal/ld/data.go:589 +0x26ae
cmd/link/internal/ld.(*Link).reloc(0xc4204ee000)
	/usr/local/go/src/cmd/link/internal/ld/data.go:739 +0x128
cmd/link/internal/ld.Main()
	/usr/local/go/src/cmd/link/internal/ld/main.go:207 +0x949
main.main()
	/usr/local/go/src/cmd/link/main.go:58 +0xdb

@bradfitz bradfitz added this to the Go1.9 milestone Jan 19, 2017

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 19, 2017

Is this a regression from Go 1.7?

@pwaller

This comment has been minimized.

Copy link
Contributor Author

commented Jan 19, 2017

It appears so, I just tested with go 1.7 and this did not crash. It did not give any warning either.

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 20, 2017

@ianlancetaylor, thoughts?

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jan 20, 2017

It's unfortunate that the linker crashes, but I don't see any way to turn this code into a correct program. I think that we should fix the linker to report an error message and not crash, but we can do that for 1.9.

@ianlancetaylor ianlancetaylor modified the milestones: Go1.9, Go1.8Maybe Jan 20, 2017

@bradfitz bradfitz modified the milestones: Go1.10, Go1.9 Jun 7, 2017

@bradfitz bradfitz added the help wanted label Jun 7, 2017

@bradfitz bradfitz added the NeedsFix label Jun 7, 2017

@jessfraz

This comment has been minimized.

Copy link
Contributor

commented Jul 17, 2017

this doesnt crash the linker anymore on tip

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 17, 2017

@jessfraz Thanks, closing.

@golang golang locked and limited conversation to collaborators Jul 17, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.