Skip to content

csky targets' atomic RMW is not lock-free #117306

Open

Description

In csky, LLVM always generates libcalls (llvm/llvm-project@ec2de74), and atomic implementations are provided by libatomic.

late_link_args_static: TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &["-l:libatomic.a"]),

However, as mentioned in #115577 (comment), the atomic RMW implementation provided in libatomic.a is not lock-free.

And it violates what the standard library is intended to guarantee.

https://doc.rust-lang.org/nightly/std/sync/atomic/index.html#portability

All atomic types in this module are guaranteed to be lock-free if they’re available. This means they don’t internally acquire a global mutex.

Also, mixing lock-free load/store and non-lock-free RMW can cause data races.

To fix this, we would need to do one of the following:

  • Fix libatomic to make the RMW implementation lock-free.
  • Fix LLVM to generate atomic instructions instead of libcalls.

It is not impossible to fix this on our end, but it is not very realistic as it would require writing a lot of inline assembly.

cc @Dirreke (mentioned because you are target maintainer)


@rustbot label +A-atomic +I-unsound

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

Metadata

Assignees

No one assigned

    Labels

    A-atomicArea: Atomics, barriers, and sync primitivesC-bugCategory: This is a bug.I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessO-cskyTarget: glaCSKY above covers over me~P-lowLow priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions