Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang RealtimeSanitizer support #76

Open
messmerd opened this issue Feb 1, 2025 · 4 comments
Open

Clang RealtimeSanitizer support #76

messmerd opened this issue Feb 1, 2025 · 4 comments

Comments

@messmerd
Copy link

messmerd commented Feb 1, 2025

The discussion in free-audio/clap#448 gave me the idea of marking real-time functions with a macro, say CLAP_REALTIME, rather than marking them as real-time in a comment.

By default, CLAP_REALTIME would be empty and do nothing (besides being documentation), but when compiled with Clang's new RealtimeSanitizer enabled in C or C++, it could provide runtime checking of CLAP API functions marked as real-time:

#if defined(__has_feature) && __has_feature(realtime_sanitizer)
#   define CLAP_REALTIME [[clang::nonblocking]]
#else
#   define CLAP_REALTIME
#endif

At least that's what I hoped we could do, but unfortunately it appears unlikely that [[clang::nonblocking]] can be applied to function pointers like those the CLAP API uses, though I haven't confirmed this yet. I was wrong, it actually is possible to use on function pointers.

Fortunately it should be possible to apply the RealtimeSanitizer here since this library uses regular functions instead of function pointers. clap-helpers is probably more fitting for this sort of thing anyway given the focus on enforcing correctness through the use of checking levels and misbehavior handlers. Putting them in the CLAP API will allow C23 programs to benefit from RtSan too.

Does this sound like a good idea?

@abique
Copy link
Contributor

abique commented Feb 1, 2025

Hi, this is very interesting.
I didn't know clang did support such a thing.

Do you want to work on a PR?

@abique
Copy link
Contributor

abique commented Feb 1, 2025

Maybe this can go in clap/private/macros.h in the clap repository?

@messmerd
Copy link
Author

messmerd commented Feb 1, 2025

@abique I just got confirmation that RtSan does actually work with function pointers too. realtime-sanitizer/rtsan#42

This is great news since it will allow us to use it in the CLAP API rather than just these clap-helpers.

I didn't know clang did support such a thing.

It hasn't actually been released yet, but it will be available in Clang 20 which should release in March.

Do you want to work on a PR?

Sure, I will work on a PR once I get the chance.

@abique
Copy link
Contributor

abique commented Feb 2, 2025

It's good to have the PR ready, so we can checkout the branch and test.
But I'll wait for clang-20 to be released to actually test it before merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants