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: -buildmode=shared fails to initialize some global data #61973

Closed
ianlancetaylor opened this issue Aug 12, 2023 · 2 comments
Closed
Assignees
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. release-blocker
Milestone

Comments

@ianlancetaylor
Copy link
Contributor

Running these commands with tip fails:

> go install -buildmode=shared std
> go build -linkshared hello.go
> ./hello
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x7fad99183f93]

goroutine 1 [running]:
os.(*File).write(...)
	/home/iant/go/src/os/file_posix.go:46
os.(*File).Write(0x0, {0xc000014120?, 0xd, 0x7fad9908a565?})
	/home/iant/go/src/os/file.go:183 +0x53
fmt.Fprintln({0x565428daeb48, 0x0}, {0xc000366720, 0x1, 0x1})
	/home/iant/go/src/fmt/print.go:305 +0x6f
fmt.Println(...)
	/home/iant/go/src/fmt/print.go:314

A similar failure occurs if I add

func init() {
	if os.Stdout == nil {
		panic("os.Stdout is nil")
	}
}

to cmd/cgo/internal/testshared/testdata/depBase/dep.go. With that addition, the panic occurs running go test cmd/cgo/internal/testshared.

It appears that at least in some cases global variables are not being initialized when using -buildmode=shared.

@ianlancetaylor ianlancetaylor added NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. compiler/runtime Issues related to the Go compiler and/or runtime. labels Aug 12, 2023
@ianlancetaylor ianlancetaylor added this to the Go1.22 milestone Aug 12, 2023
@mknyszek
Copy link
Contributor

mknyszek commented Aug 16, 2023

In triage, Ian said this is a relatively new failure. Go 1.20 seems to work.

@gopherbot
Copy link

Change https://go.dev/cl/520375 mentions this issue: cmd/link: initialize packages in shared build mode

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. release-blocker
Projects
None yet
Development

No branches or pull requests

5 participants
@mknyszek @ianlancetaylor @gopherbot @cherrymui and others