Skip to content

Feature request: atomic builtins #5842

Open
@danielsn

Description

@danielsn

CBMC currently has support for the gcc atomic builtins. However, these are added by the C front end, and hence there is no irep to directly target. It would be great to have support for these as first class ireps

Activity

added
awsBugs or features of importance to AWS CBMC users
on Feb 19, 2021
hannes-steffenhagen-diffblue

hannes-steffenhagen-diffblue commented on Feb 19, 2021

@hannes-steffenhagen-diffblue
Contributor

@danielsn Could you please elaborate? Which builtins do you want and how exactly would you like to "target" them?

danielsn

danielsn commented on Feb 26, 2021

@danielsn
ContributorAuthor

I'm trying to support intrinsics like https://doc.rust-lang.org/std/intrinsics/fn.atomic_cxchg.html - these vary over both the type, and the memory model. CBMC has facilities that generate builtins that do exactly this, but its done on the C front end, and there is hence no backend model to target. If instead we had a set of Ireps that handled these in the backend, it would make them available to all language front-ends.

martin-cs

martin-cs commented on Feb 27, 2021

@martin-cs
Collaborator

ansi-c/library/intrin.c contain a number of models of this form. I think having them implemented as library functions using atomic and fence avoids having too many irept's with complex semantics and interactions. You should be able to link against this kind of library even if you are using an alternative front-end. The Ada front-end links against them for example.

danielsn

danielsn commented on Mar 1, 2021

@danielsn
ContributorAuthor

That appears to be for the windows builtin intrinsics, which don't handle the different memory ordering models. I know CBMC supports the gcc intrinsics, which do, but I believe that is done on demand and I can't actually find a c file to link against. Is there one?

tautschnig

tautschnig commented on Mar 1, 2021

@tautschnig
Collaborator

ansi-c/library/intrin.c contain a number of models of this form. I think having them implemented as library functions using atomic and fence avoids having too many irept's with complex semantics and interactions. You should be able to link against this kind of library even if you are using an alternative front-end. The Ada front-end links against them for example.

@martin-cs Would you mind pointing us towards where in https://github.com/diffblue/gnat2goto this is being done to better understand current best practice?

hannes-steffenhagen-diffblue

hannes-steffenhagen-diffblue commented on Mar 1, 2021

@hannes-steffenhagen-diffblue
Contributor

Linking against the builtin-library happens automatically (see here), you just need to reference the functions in your goto binary. @danielsn I don't really understand your other point, what exactly were you trying to do / why does what @martin-cs suggested not work for you?

FWIW for now concurrency support is broken enough that I don't think you'll be able to write a rust program that won't be rejected, I'm not sure how much energy it's worth spending on getting these completely right until that's fixed.

danielsn

danielsn commented on Mar 1, 2021

@danielsn
ContributorAuthor

The rust builtins differentiate between different memory ordering constraints, as do the gcc builtins https://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html My understanding is that the CBMC implementation of these gcc builtins does model the memory ordering, but is not exposed in the backend.

The Windows builtins you linked against don't. So we can get the same basic behaviour (interlocked op), but without memory ordering. But if the concurrency solver is broken anyway, this may all be moot.

martin-cs

martin-cs commented on Mar 5, 2021

@martin-cs
Collaborator
feliperodri

feliperodri commented on Oct 6, 2022

@feliperodri
Collaborator

@danielsn is this still an issue?

added
KaniBugs or features of importance to Kani Rust Verifier
on Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

KaniBugs or features of importance to Kani Rust VerifierawsBugs or features of importance to AWS CBMC usersfeature request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

    Development

    No branches or pull requests

      Participants

      @tautschnig@feliperodri@danielsn@martin-cs@hannes-steffenhagen-diffblue

      Issue actions

        Feature request: atomic builtins · Issue #5842 · diffblue/cbmc