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/compile: go:linkname causes "internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference" #59621

Open
mandriota opened this issue Apr 13, 2023 · 6 comments
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@mandriota
Copy link

mandriota commented Apr 13, 2023

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

$ go version
go version go1.20.3 darwin/arm64

Does this issue reproduce with the latest release?

Yes, i downloaded the latest release from https://go.dev/doc/install.

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

go env Output
$ go env
GO111MODULE=""
GOARCH="arm64"
GOBIN=""
GOCACHE="/Users/mark/Library/Caches/go-build"
GOENV="/Users/mark/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="arm64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/mark/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/mark/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_arm64"
GOVCS=""
GOVERSION="go1.20.3"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch arm64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/82/wm5sqy_936zclxgk95t9wghr0000gn/T/go-build3292674194=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

https://go.dev/play/p/P2iv3ERVhbb

What did you expect to see?

A regular compiler error, not internal panic.

What did you see instead?

# command-line-arguments
./main.go:6:6: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference

Please file a bug report including a short program that triggers the error.
https://go.dev/issue/new

@mandriota mandriota changed the title go:linkname cause "internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference" go:linkname causes "internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference" Apr 13, 2023
@mengzhuo mengzhuo changed the title go:linkname causes "internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference" cmd/compile: go:linkname causes "internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference" Apr 14, 2023
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Apr 14, 2023
@dr2chase
Copy link
Contributor

@golang/compiler

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 14, 2023
@prattmic
Copy link
Member

The tip playground shows the actual stack trace:

./prog.go:6:6: internal compiler error: panic: runtime error: invalid memory address or nil pointer dereference

goroutine 1 [running]:
runtime/debug.Stack()
	/usr/local/go/src/runtime/debug/stack.go:24 +0x5e
cmd/compile/internal/base.FatalfAt({0x7ff12108?, 0x7f70?}, {0xd46d3e, 0x9}, {0xc0001234f8, 0x1, 0x1})
	/usr/local/go/src/cmd/compile/internal/base/print.go:234 +0x1d7
cmd/compile/internal/base.Fatalf(...)
	/usr/local/go/src/cmd/compile/internal/base/print.go:203
cmd/compile/internal/gc.handlePanic()
	/usr/local/go/src/cmd/compile/internal/gc/main.go:52 +0x90
panic({0xcca7a0?, 0x1356e40?})
	/usr/local/go/src/runtime/panic.go:913 +0x21f
cmd/internal/obj.(*Link).InitTextSym(0xc000158400, 0xc000414c80, 0x30?, {0x30?, 0x0?})
	/usr/local/go/src/cmd/internal/obj/plist.go:172 +0xd8
cmd/compile/internal/ir.setupTextLSym(0x7f7058b7fc68?, 0x7f707ff12108?)
	/usr/local/go/src/cmd/compile/internal/ir/abi.go:80 +0x1e7
cmd/compile/internal/ir.InitLSym(0xc000403b80, 0x1)
	/usr/local/go/src/cmd/compile/internal/ir/abi.go:32 +0x114
cmd/compile/internal/gc.prepareFunc(0xc000403b80)
	/usr/local/go/src/cmd/compile/internal/gc/compile.go:90 +0x25
cmd/compile/internal/gc.enqueueFunc(0xc000403b80)
	/usr/local/go/src/cmd/compile/internal/gc/compile.go:71 +0x307
cmd/compile/internal/gc.Main(0xd7a4e0)
	/usr/local/go/src/cmd/compile/internal/gc/main.go:363 +0x1b0a
main.main()
	/usr/local/go/src/cmd/compile/main.go:57 +0xf9

Looks like a panic trying to print a build error at https://cs.opensource.google/go/go/+/master:src/cmd/internal/obj/plist.go;l=172;drc=76ac54b50ea39bbb1389ecfed71f4f0991cb4289. I'd guess s.Func().Text is nil?

@thanm
Copy link
Contributor

thanm commented Apr 14, 2023

This is not a supported use of //go:linkname, sorry. We use //go:linkname internall within the Go runtime, it is not intended as a general-purpose means of renaming one function to another.

@thanm thanm closed this as completed Apr 14, 2023
@prattmic
Copy link
Member

I think this warrants fixing. This use of linkname isn't supported, but it shouldn't crash the compiler.

@prattmic prattmic reopened this Apr 14, 2023
@mdempsky mdempsky added this to the Backlog milestone Apr 14, 2023
@mdempsky
Copy link
Member

I agree it would be better that the compiler never crashed, but I also agree with @thanm that //go:linkname is a power-user feature and it's being used outside of its intended usage in the reported example. ICE isn't ideal, but reporting a better error here seems pretty low priority IMO.

@gopherbot
Copy link

Change https://go.dev/cl/484759 mentions this issue: cmd/compile: fallback if s.Func().Text is nil

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Development

No branches or pull requests

6 participants