-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
sync/atomic: addUint64 panics on ARM with unaligned pointers #23345
Comments
I think this case is already covered by the Bugs section of the package documentation:
|
Closing as duplicate of #599. |
to avoid: #11891 |
This will hopefully fix a segfault under 32bit platforms caused by unaligned access to 64bit values. golang/go#23345
writeIndex is written to atomically, which means it must be 64-bit aligned on 32-bit 386 and ARM platforms. When the buffer slice is above it, it becomes unaligned and segfaults on the call to atomic.AddUint64(). See golang/go#23345
I have the same issue with go 1.11 when running on linux, arm7, but the function atomic.StoreUint64. |
Alignment issues with 64 bit fields in the struct causes 32 bit builds of desync to not work (panic in sync/atomic package). Re-arranging the members of the struct fixes this problem Based on suggestions found at golang/go#599 and golang/go#23345.
Go doesn't always guarantee 64-bit alignment of 64-bit integer, which leads to crashes when atomic operations are used on them on certain platforms (e.g. ARM). This problem is described here: https://golang.org/pkg/sync/atomic/#pkg-note-BUG By putting these fields first, proper alignment will be guaranteed. golang/go#599 golang/go#23345
atomic.addUint64() panics if the pointer to its argument is not 64byte aligned.
it panics with:
reproduce
Hardware
I tested in on physical arm5/7 hardware. the arm5 code was executed on both targets, with equal results.
arm5:
uname -a Linux tuxnet 2.6.31-626-g602af1c #131 PREEMPT Sat Jan 22 00:08:11 CET 2011 armv5tejl GNU/Linux
arm7:
uname -a Linux rasp3 4.9.59-v7+ #1047 SMP Sun Oct 29 12:19:23 GMT 2017 armv7l GNU/Linux
compile options
This panics for:
This works for:
so the behaviour is somewhat undefined, but became worse with 1.9.2.
Workaround
assure the atomic variabbles are aligned. E.g. putting
bar
first eliminates the issuetype X struct {
bar uint64
foo int8
}
This seems to be connected to #599.
What version of Go are you using (
go version
)?1.7.1, 1.9.2
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?GOOS=linux GOARCH=arm GOARM=5
GOOS=linux GOARCH=arm GOARM=7
The text was updated successfully, but these errors were encountered: