Skip to content

catfile: Ensure structs are properly aligned in memory for 32-bit CPUs (14.5)

This backports !4139 (merged) to the 14-5-stable branch.

In GitLab 14.5, the use of atomic.LoadInt64 caused a panic: unaligned 64-bit atomic operation on a Raspberry Pi2 platform. While we don't officially support 32-bit processors, we have been supporting armfh builds for years now.

From https://pkg.go.dev/sync/atomic#pkg-note-BUG: On ARM, 386, and 32-bit MIPS, it is the caller's responsibility to arrange for 64-bit alignment of 64-bit words accessed atomically. The first word in a variable or in an allocated struct, array, or slice can be relied upon to be 64-bit aligned.

We can fix this problem by listing the int64 and int32 atomic fields in order to ensure they are properly aligned. This does not change the overall size of the structure.

For example, with Object:

Before: https://go.dev/play/p/MCk9TnxhkCY (80 bytes) After: https://go.dev/play/p/83jdBOP-wpA (80 bytes)

Relates to #3938 (closed)

Edited by Stan Hu

Merge request reports