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: nil pointer panic during compile for openbsd/mips64 #58240

Closed
calmh opened this issue Feb 2, 2023 · 8 comments
Closed

cmd/link: nil pointer panic during compile for openbsd/mips64 #58240

calmh opened this issue Feb 2, 2023 · 8 comments
Assignees
Labels
arch-mips compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-OpenBSD
Milestone

Comments

@calmh
Copy link
Contributor

calmh commented Feb 2, 2023

Noticed this on Go 1.19.5, after updating a few dependencies to support Go 1.20.

% docker run -it --rm golang:1.19.5
root@d0d4ee0380ce:/go# go version
go version go1.19.5 linux/arm64
(issue also happens on linux/amd64)
root@d0d4ee0380ce:/go# git clone -b linkercrash https://github.com/calmh/syncthing.git
(repo clones)
root@d0d4ee0380ce:/go# cd syncthing/
root@d0d4ee0380ce:/go/syncthing# GOOS=openbsd GOARCH=mips64 go build ./cmd/stdiscosrv/
(build happens)
# github.com/syncthing/syncthing/cmd/stdiscosrv
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x15447c]

goroutine 1 [running]:
cmd/link/internal/ld.dynrelocsym(0x40000bc000, 0x2510c?)
	/usr/local/go/src/cmd/link/internal/ld/data.go:853 +0x28c
cmd/link/internal/ld.(*dodataState).dynreloc(0x40006b1b00, 0x40000bc000)
	/usr/local/go/src/cmd/link/internal/ld/data.go:871 +0x8c
cmd/link/internal/ld.(*Link).dodata(0x40000bc000, {0x4002380000, 0x4b89f, 0x4b89f})
	/usr/local/go/src/cmd/link/internal/ld/data.go:1498 +0x384
cmd/link/internal/ld.Main(_, {0x8, 0x20, 0x1, 0x1d, 0x1f, 0x0, {0x0, 0x0}, {0x271699, ...}, ...})
	/usr/local/go/src/cmd/link/internal/ld/main.go:336 +0x12f8
main.main()
	/usr/local/go/src/cmd/link/main.go:72 +0xe98
root@d0d4ee0380ce:/go/syncthing#
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Feb 2, 2023
@mknyszek
Copy link
Contributor

mknyszek commented Feb 2, 2023

CC @golang/compiler

@mknyszek
Copy link
Contributor

mknyszek commented Feb 2, 2023

CC @golang/mips @golang/openbsd

@mknyszek mknyszek added this to the Backlog milestone Feb 2, 2023
@mknyszek mknyszek added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. help wanted labels Feb 2, 2023
@cuonglm
Copy link
Member

cuonglm commented Feb 9, 2023

The CL https://go-review.googlesource.com/c/go/+/233523 introduces this behavior cc @thanm

Pre-CL, that would be a fatal error.

@thanm thanm self-assigned this Feb 9, 2023
@thanm
Copy link
Contributor

thanm commented Feb 9, 2023

I'll take a look.

@thanm
Copy link
Contributor

thanm commented Feb 9, 2023

@calmh looks like this is actually expected behavior given the current state of openbsd + mips64.

What is happening here is that the code in the golang.org/x/sys repo has moved forward with switching OpenBSD to use libc as opposed to directly syscall invocation.

The app in question has a reachable calll to golang.org/x/sys/unix.mmap, which results in the following chain of dependent functions being pulled in (this is from the linker's -dumpdep flag):

golang.org/x/sys/unix.mmap -> golang.org/x/sys/unix.libc_mmap_trampoline_addr
golang.org/x/sys/unix.libc_mmap_trampoline_addr -> libc_mmap_trampoline
libc_mmap_trampoline -> libc_mmap

where libc_mmap is of type SDYNIMPORT (meaning that at runtime its definition will be appearing in a shared library).

The problem here is that although golang.org/x/sys/unix has moved ahead, the CLs to support this in the Go linker are stalled. See the stack at https://go.dev/cl/415815 and successors.

It's unfortunate that the golang.org/x/sys/unix change was rolled out before things were ready in the Go linker realm, but it appears that's just what was decided by the OpenBSD maintainers.

I will send a CL to change things so that we get an error in this case as opposed to a crash, but until https://go.dev/cl/415815 and friends are merged, folks will see these same sorts of errors.

@thanm
Copy link
Contributor

thanm commented Feb 9, 2023

@4a6f656c FYI

@gopherbot
Copy link

Change https://go.dev/cl/466895 mentions this issue: cmd/link: improve error for missing SDYNIMPORT support on mips/mips64

johanbrandhorst pushed a commit to Pryz/go that referenced this issue Feb 12, 2023
Issue an error (instead of crashing) when encountering a symbol that
requires dynamic relocations on mips/mips64. The dynimport support is
in progress, but is not done yet, so rather than crashing, print a
message indicating that the feature is not yet implemented and exit.

Fixes golang#58240.

Change-Id: I9ad64c89e4f7b4b180964b35ad1d72d375f2df7f
Reviewed-on: https://go-review.googlesource.com/c/go/+/466895
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Joel Sing <joel@sing.id.au>
Reviewed-by: David Chase <drchase@google.com>
Run-TryBot: Than McIntosh <thanm@google.com>
pojntfx added a commit to pojntfx/hydrapp that referenced this issue Feb 24, 2023
pojntfx added a commit to pojntfx/hydrapp that referenced this issue Feb 26, 2023
@sylr
Copy link

sylr commented Apr 11, 2023

I reproduced this today with go1.20.3. Using gotip yields another error now:

go1.20.3

$ CGO_ENABLED=0 GOOS=openbsd GOARCH=mips64 go build -tags static,crossbuild -trimpath -ldflags '-s -w -X sigs.k8s.io/kustomize/api/provenance.version=v5.0.1+sylr.1 -X sigs.k8s.io/kustomize/api/provenance.gitCommit=eec6096dd087154c2222b8797f3c7aca6aeb5246 -X sigs.k8s.io/kustomize/api/provenance.buildDate=2023-04-11T09:18:43Z -extldflags ""' -o ../dist/kustomize-v5.0.1+sylr.1-openbsd-mips64
# sigs.k8s.io/kustomize/kustomize/v5
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x0 pc=0x101008748]

goroutine 1 [running]:
cmd/link/internal/ld.dynrelocsym(0x1400014c000, 0x1400051e000?)
	/opt/homebrew/Cellar/go/1.20.3/libexec/src/cmd/link/internal/ld/data.go:917 +0x288
cmd/link/internal/ld.(*dodataState).dynreloc(0x1400061a000, 0x1400014c000)
	/opt/homebrew/Cellar/go/1.20.3/libexec/src/cmd/link/internal/ld/data.go:935 +0x8c
cmd/link/internal/ld.(*Link).dodata(0x1400014c000, {0x14001980000, 0x5d87e, 0x5d87e})
	/opt/homebrew/Cellar/go/1.20.3/libexec/src/cmd/link/internal/ld/data.go:1566 +0x3b4
cmd/link/internal/ld.Main(_, {0x8, 0x20, 0x1, 0x1d, 0x1f, 0x0, {0x0, 0x0}, {0x1010c8663, ...}, ...})
	/opt/homebrew/Cellar/go/1.20.3/libexec/src/cmd/link/internal/ld/main.go:338 +0x13e4
main.main()
	/opt/homebrew/Cellar/go/1.20.3/libexec/src/cmd/link/main.go:72 +0xcb8

gotip

$ CGO_ENABLED=0 GOOS=openbsd GOARCH=mips64 gotip build -tags static,crossbuild -trimpath -ldflags '-s -w -X sigs.k8s.io/kustomize/api/provenance.version=v5.0.1+sylr.1 -X sigs.k8s.io/kustomize/api/provenance.gitCommit=eec6096dd087154c2222b8797f3c7aca6aeb5246 -X sigs.k8s.io/kustomize/api/provenance.buildDate=2023-04-11T09:18:43Z -extldflags ""' -o ../dist/kustomize-v5.0.1+sylr.1-openbsd-mips64
# sigs.k8s.io/kustomize/kustomize/v5
golang.org/x/sys/unix.ioctl: relocation target syscall.syscall not defined
golang.org/x/sys/unix.read: relocation target syscall.syscall not defined
golang.org/x/sys/unix.mmap: relocation target syscall.syscall6 not defined
golang.org/x/sys/unix.munmap: relocation target syscall.syscall not defined

Commit: sylr/kustomize@eec6096

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
arch-mips compiler/runtime Issues related to the Go compiler and/or runtime. FrozenDueToAge help wanted NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. OS-OpenBSD
Projects
None yet
Development

No branches or pull requests

6 participants