Skip to content

Fix alignment issues with double-wide atomics on i386 #102

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

Merged
merged 5 commits into from
Sep 22, 2023

Conversation

lorentey
Copy link
Member

@lorentey lorentey commented Sep 22, 2023

The SysV ABI defined uint64_t with 4 byte alignment on i386 — so we can’t just assume that the integer types will have the right alignment for atomics out of the box.

Emulate the original _Atomic<Width>Storage types from the old C shims even in native atomics configuration, so that they can carry a custom @_alignment attribute.

Change things up so that these storage types define atomic operations taking and returning themselves, rather than some standard scalar type. This gets things a little closer in spirit to what we're planning to do in the stdlib, and it really cuts down the size of the gyb output for the native definitions.

Resolves #99.

Checklist

  • I've read the Contribution Guidelines
  • My contributions are licensed under the Swift license.
  • I've followed the coding style of the rest of the project.
  • I've added tests covering all new code paths my change adds to the project (if appropriate).
  • I've verified that my change does not break any existing tests.
  • I've updated the documentation if necessary.

…atforms

We used to use Int64 on 32-bit architectures, but the inconsistency is bothering me. (Even ignoring alignment issues on SysV-derived ABIs on i386.)
… types

The SysV ABI defined uint64_t with 4 byte alignment on i386 — so we can’t just assume that the integer types will have the right alignment by default for atomics.

Emulate the original `_Atomic<Width>Storage` types in the C shims even in native atomics configuration, so that they can carry a custom `@_alignment` attribute.
@lorentey lorentey requested review from glessard and Azoy September 22, 2023 07:49
@lorentey lorentey added this to the 1.2.0 milestone Sep 22, 2023
@lorentey
Copy link
Member Author

@swift-ci test

@lorentey lorentey mentioned this pull request Sep 22, 2023
36 tasks
@lorentey lorentey merged commit 8e18576 into apple:main Sep 22, 2023
@lorentey lorentey deleted the fix-alignment-issues branch September 22, 2023 18:16
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.

Double-wide atomics have alignment issues on i386 with SysV ABI
2 participants