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

fmt: segfaults (panic) on "hello world" with -linkshared #64925

Closed
stevenengler opened this issue Jan 2, 2024 · 3 comments
Closed

fmt: segfaults (panic) on "hello world" with -linkshared #64925

stevenengler opened this issue Jan 2, 2024 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@stevenengler
Copy link

Go version

go version go1.21.5 linux/amd64

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

GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/root/.cache/go-build'
GOENV='/root/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/root/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/root/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.5'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
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 -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -ffile-prefix-map=/tmp/go-build4191319309=/tmp/go-build -gno-record-gcc-switches'

What did you do?

When compiling a "hello world" example when using the -linkshared flag, the fmt.Println("hello") segfaults. The following example works on earlier versions of Go. The following are steps to reproduce:

sudo docker run -it --rm ubuntu:22.04

In the container:

apt update
apt upgrade -y
apt install -y tar curl build-essential
cd /tmp/
curl https://dl.google.com/go/go1.21.5.linux-amd64.tar.gz > go.tar.gz
tar -C /usr/local -xzf go.tar.gz
PATH=$PATH:/usr/local/go/bin
go install -buildmode=shared -linkshared std
cat <<EOF >> foo.go
package main

import (
    "fmt"
)

func main() {
    fmt.Println("hello")
}
EOF
go build -linkshared -o foo foo.go
./foo

What did you expect to see?

hello

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7f7fbe0038b3]

goroutine 1 [running]:
os.(*File).write(...)
	/usr/local/go/src/os/file_posix.go:46
os.(*File).Write(0x0, {0xc0003a6000?, 0x6, 0x7f7fbdf0f145?})
	/usr/local/go/src/os/file.go:183 +0x53
fmt.Fprintln({0x5607de781b48, 0x0}, {0xc000360f20, 0x1, 0x1})
	/usr/local/go/src/fmt/print.go:305 +0x6f
fmt.Println(...)
	/usr/local/go/src/fmt/print.go:314
@stevenengler
Copy link
Author

A workaround for the example above is to use an unnecessary os import:

import (
    _ "os"
    "fmt"
)
$ go build -linkshared -o foo foo.go
$ ./foo
hello

I don't know much about Go so I don't know if this is expected or not.

@mauri870 mauri870 added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 2, 2024
@mauri870
Copy link
Member

mauri870 commented Jan 2, 2024

/cc @golang/compiler

@seankhliao
Copy link
Member

fixed on tip / 1.22rc1

@seankhliao seankhliao closed this as not planned Won't fix, can't repro, duplicate, stale Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants