Skip to content

ARM32 (and possibly some others) might take locks in Interlocked FCalls #97452

Open
@MichalPetryka

Description

@MichalPetryka

While working on #92974, I've realised that on some platforms without builtin atomics for all types, compilers might use a locking based implementation for them.
Checking the C11 defines, it seems like at least ARM32 is affected with Clang, but other platforms might be affected with GCC too.

Looking at the exact codegen, ARM32 and ARM 8.0 without atomics seem to use helper calls for Interlocked, only arm32 gives warnings about locking though.

The code should be fixed to avoid potential issues with this, I see 4 possible solutions:

  1. Make the helper calls QCalls - expensive
  2. Switch to preemptive in the FCall on affected platforms - also expensive
  3. Implement Interlocked with always expand intrinsics on affected platforms - requires JIT work (should already be handled on ARM 8.0 in .NET 9)
  4. Rewrite the unmanaged helpers in raw assembly in a way that doesn't use locks - requires VM work

Relying on the compiler to be lock free on any platform that uses helper calls for atomics seems unreliable as AFAIR those are free to implement them using locks.
cc @jkotas

Metadata

Metadata

Assignees

No one assigned

    Labels

    arch-arm32area-PAL-coreclrin-prThere is an active PR which will close this issue when it is merged

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions