Skip to content

fix: unaligned 64-bit atomic operation on 32-bit archs#411

Merged
klauspost merged 1 commit intominio:masterfrom
strophy:fix-32-bit
Aug 26, 2025
Merged

fix: unaligned 64-bit atomic operation on 32-bit archs#411
klauspost merged 1 commit intominio:masterfrom
strophy:fix-32-bit

Conversation

@strophy
Copy link
Contributor

@strophy strophy commented Aug 13, 2025

On 32-bit architectures (e.g. 386, ARM) TestNew was panicking with:

--- FAIL: TestNew (0.00s)
    --- FAIL: TestNew/Default (0.00s)
panic: unaligned 64-bit atomic operation [recovered, repanicked]

goroutine 7 [running]:
testing.tRunner.func1.2({0x5e1fcc20, 0x5e221028})
        testing/testing.go:1872 +0x2b5
testing.tRunner.func1()
        testing/testing.go:1875 +0x48a
panic({0x5e1fcc20, 0x5e221028})
        runtime/panic.go:783 +0x120
internal/runtime/atomic.panicUnaligned()
        internal/runtime/atomic/unaligned.go:8 +0x38
internal/runtime/atomic.Xadd64(0x5e92636c, 0x1)
        internal/runtime/atomic/atomic_386.s:127 +0x11
github.com/minio/warp/pkg/generator.(*randomSrc).Object(0x5e926300)
        github.com/minio/warp/pkg/generator/random.go:121 +0x49
github.com/minio/warp/pkg/generator.TestNew.func1(0x5e807688)
        github.com/minio/warp/pkg/generator/generator_test.go:60 +0x149
testing.tRunner(0x5e807688, 0x5e816840)
        testing/testing.go:1934 +0x164
created by testing.(*T).Run in goroutine 6
        testing/testing.go:1997 +0x55a
FAIL    github.com/minio/warp/pkg/generator     0.006s
FAIL

randomSrc.counter (uint64) was placed after fields whose alignment is 4 bytes, so on 32-bit platforms it could reside at a 4-byte offset. sync/atomic requires 64-bit values to be 8-byte aligned on 32-bit systems; the runtime detects and panics on unaligned atomic.AddUint64.

This PR switches randomSrc to use an atomic.Uint64 instead.

Copy link
Collaborator

@klauspost klauspost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@klauspost klauspost merged commit 042a9fc into minio:master Aug 26, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants