-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[Mono] Consider switching to C11 #90404
Comments
/cc @jkoritzinsky |
MSVC doesn't support C11, only C17. |
Yes it does - https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/. There is no support for optional features and there are bugs around atomics, but it has support. |
In libraries, we are using C11 for couple of years: runtime/eng/native/configurecompiler.cmake Lines 10 to 11 in 376e235
and e.g. its 'Generic Selection' feature.:
VCR handles it just fine. Only these features are not supported: https://devblogs.microsoft.com/cppblog/c11-and-c17-standard-support-arriving-in-msvc/#whats-not which we don't use in libs. |
The atomics in C11 is recent and experimental, announced at https://devblogs.microsoft.com/cppblog/c11-atomics-in-visual-studio-2022-version-17-5-preview-2/. |
Hi, I'm on the C++ libraries team and I'm the one who wrote the library support for c11 atomics and threads. We actually thought of providing gcc style atomic intrinsics that could work in c99 mode, but because of how our C++ atomics are designed MSVC really, really needs that new C11 threads will probably work fine in C99 mode, with the possible exception of the new All the C11 threads stuff is new, and distinct from C++ threads. The ABI is also somewhat better protected than for C++ threads, so layouts and implementation are subject to change (in ABI compatible ways). |
oh, I should say that C11 threads is just implemented in terms of windows threading functions ( Note that this does mean |
It's currently being actively worked on (both front-end and back-end teams) - we can talk about .NET taking a dependency on this support in our sync meetings. |
Thinking about runtime/src/mono/mono/utils/checked-build.c Lines 207 to 221 in cd4a253
So I think at best we will end up redefining |
Change the mono build to require C11 (with gnu extensions on gcc/clang platforms). * Change `g_static_assert` to be `_Static_assert` or `static_assert` as apropriate. * Change `_DN_STATIC_ASSERT` to be `static_assert` * Add static asserts in `jiterp.c` when it casts between `T*` and `atomic_T*` * Add C11 guidance to the mono coding guide doc Contributes to #90404 --- * Bump mono to -std=gnu99; use static_assert * don't fall back to runtime checks for g_static_assert * fix static assert that wasn't a constant expression * use static_assert in shared containers * bump C standard in offsets-tool.py * use _Static_assert before C23 Dont' include assert.h in glib.h because some of our older 3P code includes assert.h on its own and there are conflicts * use CMAKE_C_STANDARD and related properties * jiterp: static_assert that atomic ops are (less likely) to go wrong Not every C implementation guarantees that atomic operations on arbitrary types are lock free. So for example, casting between atomic_ushort* and uint16_t* might not actually be ok to do. We can't assert that they're inter-castable, but at least assert that they're the same size and that atomic_ushort is always lock-free. There might still be restrictions (for example atomic_ushort might have to be aligned differently) but this should at least catch obvious data corruption. * Add C11 guidance to the Mono coding guide * jiterp: long is 32-bits on wasm; use llong
This initial work has been completed. Mono now requires a C11 compiler - and we use Some platforms now opt into using C11 atomics for the We are not using c11 atomics for MSVC builds yet, but we could switching. Created #91748 for follow-up work. We are using "strong" not "weak" atomics. Created #91747 for follow-up work. |
@lambdageek what is the status of this? |
We're done. #91808 was good. |
Currently Mono is supposed to use C99. As a result, we're relying on platform or compiler intrinsics for some functionality that has been added to the standard since then such as
stdatomic.h
.We should consider upgrading Mono to a more recent language standard.
This came up as part of #88279, for example.
Some concrete things we could take advantage of:
stdatomic.h
for atomic reads/writes, CAS, etc_Alignas
_Noreturn
Some reasons we might not want to do it:
mono-aot-cross
running on Win32 and also Mono on non-Windows Win32 platformsThe text was updated successfully, but these errors were encountered: