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: inaccurate compiler error on duplicate wasmexport symbol #68982

Open
johanbrandhorst opened this issue Aug 21, 2024 · 3 comments
Open
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@johanbrandhorst
Copy link
Member

Go version

tip

Output of go env in your module/workspace:

GO111MODULE=''
GOARCH='arm64'
GOBIN=''
GOCACHE='/home/johan/.cache/go-build'
GOENV='/home/johan/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='arm64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/johan/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/johan/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/johan/src/tip/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/johan/src/tip/go/pkg/tool/linux_arm64'
GOVCS=''
GOVERSION='devel go1.24-24fd1a043d Tue Aug 20 23:11:53 2024  0000'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/johan/.config/go/telemetry'
GCCGO='gccgo'
GOARM64='v8.0'
AR='ar'
CC='gcc'
CXX='g  '
CGO_ENABLED='0'
GOMOD='/home/johan/src/tip/go/test/wasmexport/go.mod'
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 -fno-caret-diagnostics -Qunused-arguments -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build2688758080=/tmp/go-build -gno-record-gcc-switches'

What did you do?

I created a package that exported two identical symbols (in the same package) using the go:wasmexport compiler directive.

package main

//go:wasmexport A
func A() int64 {
	return 10
}

//go:wasmexport A
func B() int64 {
	return 10
}

func main() {
}

What did you see happen?

I saw a compiler error:

$ GOARCH=wasm GOOS=wasip1 go build -buildmode=c-shared -o x.wasm main.go
main.go:5:2: <autogenerated>:1: symbol A redeclared
        <unknown line number>: other declaration of symbol A

What did you expect to see?

The error message should be able to point to the line number of both symbols:

$ GOARCH=wasm GOOS=wasip1 go build -buildmode=c-shared -o x.wasm main.go
main.go:5:2: <autogenerated>:1: symbol A redeclared
        main.go:10:2: other declaration of symbol A

It is also notable that main.go:5 is the location of the return, not the compiler directive.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Aug 21, 2024
@johanbrandhorst
Copy link
Member Author

CC @golang/wasm

@mknyszek mknyszek modified the milestones: Go1.23.1, Go1.24 Aug 21, 2024
@mknyszek mknyszek added the NeedsFix The path to resolution is known, but the work has not been done. label Aug 21, 2024
@cuonglm
Copy link
Member

cuonglm commented Aug 26, 2024

It seems to me this is unfortunate.

  • The main.go:5:2 part of error message is the current position in the source code, not part of the error message emited by obj.Link.InitTextSym.
  • We are creating export wrapper functions, that's why we see <autogenerated>:1.

Could we simply use the wrapped function position for wrapper ones instead of auto generated? cc @cherrymui

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. NeedsFix The path to resolution is known, but the work has not been done.
Projects
Development

No branches or pull requests

6 participants