Closed stapelberg closed 1 year ago
Well, this is weird:
type Types struct {
files *protoregistry.Files
extMu sync.Mutex
atomicExtFiles uint64
extensionsByMessage map[extField]protoreflect.ExtensionDescriptor
}
There’s no reason that should end up unaligned… huh, I am able to repo locally with GOARCH=386 go test
. It looks like there’s an odd number of pointers ahead of atomicExtFiles, resulting in the misallignment.
I am perplexed though, why the Golang system isn’t aligning a uint64 on a 64-bit boundary. 🤔
It looks like according to the language spec's Size and alignment guarantees:
For a variable x of struct type: unsafe.Alignof(x) is the largest of all the values unsafe.Alignof(x.f) for each field f of x, but at least 1.
So, it’s only guaranteeing the alignment of the struct
itself, not the individual fields. We could therefore safely move atomicExtFiles
to the top of the struct, in order to ensure proper alignment. It’s only ever accessed atomically, so it doesn’t need to be order after the sync.Mutex
indicating it is guarded by it.
What version of protobuf and what language are you using? Version: commit 4396dd4cd0795b750a83f9fafa6747e6c5082526 (latest at the time of writing)
What did you do?
./test.bash
I’m getting the following stack trace:
cc @neild