Skip to content

[release/10.0] Fix alignment of 8-byte thread statics on direct TLS path#129785

Open
github-actions[bot] wants to merge 1 commit into
release/10.0from
backport/pr-129749-to-release/10.0
Open

[release/10.0] Fix alignment of 8-byte thread statics on direct TLS path#129785
github-actions[bot] wants to merge 1 commit into
release/10.0from
backport/pr-129749-to-release/10.0

Conversation

@github-actions

@github-actions github-actions Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Backport of #129749 to release/10.0

/cc @EgorBo

Customer Impact

  • Customer reported
  • Found internally

Some TLS (ThreadStatic) fields could be allocated with 4b alignment while demanding 8b e.g. long. This may lead to DataMisalignedException in certain cases (e.g. using Interlocked on arm64, or double fields on arm32) or/and reiceve a perf penalty from misaligned access.

Regression

  • Yes
  • No

It was introduced in .NET 9.0

Testing

Validated locally that 64-bit TLS variables never get any alignment less than 64 bytes.

Risk

Low to none.

GetTLSIndexForThreadStatic computes the alignment for a thread static
placed on the direct-on-thread-local-data bump allocator. The chain of
size checks was missing an `else` before the `>= 4` case, so an 8-byte
field (long/double) first set alignment = 8 and then immediately
overwrote it with alignment = 4. The resulting offset could land on a
4-mod-8 boundary, producing a misaligned long/double.

On arm64 this causes Interlocked.Increment(ref threadStaticLong) to
throw DataMisalignedException, since the atomic lowers to ldaxr/stlxr
which fault on a misaligned address.

Fixes #129733

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@dotnet-policy-service

Copy link
Copy Markdown
Contributor

Tagging subscribers to this area: @agocke
See info in area-owners.md if you want to be subscribed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants