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

runtime: fatal error: bulkBarrierPreWrite: unaligned arguments #28460

Closed
dominikh opened this issue Oct 29, 2018 · 3 comments

Comments

@dominikh
Copy link
Member

commented Oct 29, 2018

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

go version devel +3f3142ad99 Mon Oct 29 09:54:51 2018 +0000 linux/amd64

Does this issue reproduce with the latest release?

Does reproduce with Go 1.10.3 and 1.11.1

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

GOARCH="amd64"
GOBIN=""
GOCACHE="/home/dominikh/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/dominikh/prj/"
GOPROXY=""
GORACE=""
GOROOT="/home/dominikh/go"
GOTMPDIR=""
GOTOOLDIR="/home/dominikh/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build797732207=/tmp/go-build -gno-record-gcc-switches"

What did you do?

$ cat foo.go
package main

// #include <stdlib.h>
import "C"
import (
	"unsafe"
)

func main() {
	mem := C.calloc(1, 1024)
	*(*[2]*uint64)(unsafe.Pointer(uintptr(mem) + 1)) = [2]*uint64{}
}


$ ~/go/bin/go build foo.go
$ GODEBUG=cgocheck=2 ./foo

What did you expect to see?

No output

What did you see instead?

fatal error: bulkBarrierPreWrite: unaligned arguments

goroutine 1 [running]:
runtime.throw(0x475778, 0x28)
	/home/dominikh/go/src/runtime/panic.go:608 +0x72 fp=0xc00004a6c0 sp=0xc00004a690 pc=0x423842
runtime.bulkBarrierPreWrite(0xebe7e1, 0x0, 0x10)
	/home/dominikh/go/src/runtime/mbitmap.go:591 +0x4a4 fp=0xc00004a748 sp=0xc00004a6c0 pc=0x40fa54
runtime.typedmemclr(0x45e3e0, 0xebe7e1)
	/home/dominikh/go/src/runtime/mbarrier.go:316 +0x5b fp=0xc00004a770 sp=0xc00004a748 pc=0x40ed0b
main.main()
	/tmp/foo.go:11 +0x6d fp=0xc00004a798 sp=0xc00004a770 pc=0x4508ad
runtime.main()
	/home/dominikh/go/src/runtime/proc.go:201 +0x1ec fp=0xc00004a7e0 sp=0xc00004a798 pc=0x42518c
runtime.goexit()
	/home/dominikh/go/src/runtime/asm_amd64.s:1340 +0x1 fp=0xc00004a7e8 sp=0xc00004a7e0 pc=0x4498b1

@dominikh dominikh added this to the Go1.12 milestone Oct 29, 2018

@randall77

This comment has been minimized.

Copy link
Contributor

commented Oct 29, 2018

This has been the situation since 1.8.
Do we want to support unaligned pointer writes? It seems to be a very odd thing to want to do.
The compiler-generated code (not to mention the cgocheck stuff) won't work on architectures that don't allow unaligned writes (arm, say). Maybe that isn't a huge deal if you're already using cgo.

@dominikh

This comment has been minimized.

Copy link
Member Author

commented Oct 30, 2018

I'd be fine with calling it working as intended. It may warrant some documentation in cmd/cgo or on the wiki, since at least on x86, it's an implementation detail of the runtime.

@randall77

This comment has been minimized.

Copy link
Contributor

commented Dec 28, 2018

I'm inclined just to close this.
It's easy to fix: just use uintptr instead of *uint64::

*(*[2]uintptr)(unsafe.Pointer(uintptr(mem) + 1)) = [2]uintptr{}

There's no way you'd want to write Go pointers this way. It's also not allowed by the cgo contract.
C pointers you'd write this way you can coerce to uintptr easily enough.

I agree the error message is less than clear about what you did wrong. But this is an exceedingly rare thing to want to do, I don' think we should add complexity to fix it.

I don't see any obvious place in the wiki to put some docs. If you find a place, feel free to add it.
This issue will at least serve for people searching for the error text.

@randall77 randall77 closed this Dec 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.