Skip to content

[Interpreter] localloc does not guarantee platform stack alignment #125657

Closed

Description

@radekdoulik

FrameDataAllocator::Alloc() in src/coreclr/vm/interpframeallocator.cpp aligns localloc buffer sizes to sizeof(void*) (4 bytes on WASM, 8 bytes on 64-bit platforms):

size = ALIGN_UP(size, sizeof(void*));

The JIT guarantees localloc returns pointers aligned to STACK_ALIGN (16 bytes on most platforms including WASM — see src/coreclr/jit/targetwasm.h), but the interpreter does not honor this. The fragment backing memory comes from raw malloc() with no explicit alignment, and subsequent bump allocations within a fragment are only pointer-size aligned.

This causes the ShowLocallocAlignment regression test to fail on WASM (and would fail on any platform using the interpreter) because stackalloc returns 8-byte aligned addresses instead of the expected 16-byte alignment.

Repro

Run JIT/Regression/Dev11/External/dev11_239804/ShowLocallocAlignment on a platform using the CoreCLR interpreter (e.g. WASM).

Expected

Localloc returns a 16-byte aligned pointer (matching STACK_ALIGN).

Actual

Localloc returns a pointer aligned only to sizeof(void*).

Suggested fix

Change the alignment in FrameDataAllocator::Alloc() to use INTERP_STACK_ALIGNMENT (16) instead of sizeof(void*), and ensure the returned pointer (not just the size) is aligned.

Activity

  1. added
    untriaged
    on Mar 17, 2026
  2. dotnet-policy-service commented on Mar 17, 2026

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @BrzVlad, @janvorli, @kg
    See info in area-owners.md if you want to be subscribed.

  3. added this to the Future milestone on Mar 17, 2026
  4. removed
    untriaged
    on Mar 17, 2026
  5. radekdoulik commented on Mar 17, 2026

    @radekdoulik
    MemberAuthor

    @janvorli @BrzVlad should we align FrameDataAllocator::Alloc() to INTERP_STACK_ALIGNMENT?

  6. BrzVlad commented on Mar 18, 2026

    @BrzVlad
    Member

    Sounds good. We could use AlignedAllocate here as well.

  7. added a commit that references this issue on Mar 31, 2026
    2f94e9d
  8. added a commit that references this issue on Mar 31, 2026
    5a15402
  9. locked and limited conversation to collaborators on May 1, 2026
  10. added a commit that references this issue on Jul 15, 2026
    ebbbf03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions