diff --git a/src/native/external/libunwind/CMakeLists.txt b/src/native/external/libunwind/CMakeLists.txt index 8de31d12e32f59..33625800590c9e 100644 --- a/src/native/external/libunwind/CMakeLists.txt +++ b/src/native/external/libunwind/CMakeLists.txt @@ -74,20 +74,6 @@ if ("${CMAKE_GENERATOR}" MATCHES "^Visual Studio.*$") set(HAVE_ELF_H 1) set(HAVE_ENDIAN_H 1) - # MSVC compiler is currently missing C11 stdalign.h header - # Fake it until support is added - check_include_files(stdalign.h HAVE_STDALIGN_H) - if (NOT HAVE_STDALIGN_H) - configure_file(include/remote/win/fakestdalign.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/stdalign.h) - endif (NOT HAVE_STDALIGN_H) - - # MSVC compiler is currently missing C11 stdatomic.h header - # Fake it until support is added - check_include_files(stdatomic.h HAVE_STDATOMIC_H) - if (NOT HAVE_STDATOMIC_H) - configure_file(include/remote/win/fakestdatomic.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/stdatomic.h) - endif (NOT HAVE_STDATOMIC_H) - # MSVC compiler is currently missing C11 _Thread_local check_c_source_compiles("void main() { _Thread_local int a; }" HAVE_THREAD_LOCAL) if (NOT HAVE_THREAD_LOCAL) diff --git a/src/native/external/libunwind/include/remote/win/fakestdalign.h.in b/src/native/external/libunwind/include/remote/win/fakestdalign.h.in deleted file mode 100644 index 3baf6268c84965..00000000000000 --- a/src/native/external/libunwind/include/remote/win/fakestdalign.h.in +++ /dev/null @@ -1,9 +0,0 @@ -// This is a fake implementation of stdalign.h for when -// compiler C11 stdaliagn.h support is missing - -#ifndef FAKE_STD_ALIGN_H -#define FAKE_STD_ALIGN_H - -#define alignas(x) - -#endif // FAKE_STD_ALIGN_H diff --git a/src/native/external/libunwind/include/remote/win/fakestdatomic.h.in b/src/native/external/libunwind/include/remote/win/fakestdatomic.h.in deleted file mode 100644 index 799770e8bddca9..00000000000000 --- a/src/native/external/libunwind/include/remote/win/fakestdatomic.h.in +++ /dev/null @@ -1,36 +0,0 @@ -// This is a non-atomic fake implementation of stdatomic.h for when -// compiler C11 stdatomic support is missing and only single threaded -// operation is required - -#ifndef FAKE_STD_ATOMICS_H -#define FAKE_STD_ATOMICS_H - -#include - -#define _Atomic volatile -#define ATOMIC_FLAG_INIT 0 - -typedef uint8_t atomic_bool; -typedef uint8_t atomic_flag; - -#define atomic_compare_and_exchange_strong(x, y, z) return ((*(x) == *(y)) ? ((*(x) = z), true) : ((*(y) = *(x)),false)) - -#define atomic_fetch_add(x, y) *(x) += (y), (*(x) - (y)) - -static inline void atomic_flag_clear(volatile atomic_flag* flag) -{ - *flag = ATOMIC_FLAG_INIT; -} - -static inline atomic_bool atomic_flag_test_and_set( volatile atomic_flag* flag ) -{ - atomic_bool result = *flag; - *flag = 1; - return result; -} - -#define atomic_load(x) (*(x)) -#define atomic_store(x, y) do { *(x) = (y); } while (0) - - -#endif // FAKE_STD_ATOMICS_H diff --git a/src/native/external/libunwind_extras/CMakeLists.txt b/src/native/external/libunwind_extras/CMakeLists.txt index 8b7b708b702649..d32ce41751b481 100644 --- a/src/native/external/libunwind_extras/CMakeLists.txt +++ b/src/native/external/libunwind_extras/CMakeLists.txt @@ -126,6 +126,18 @@ if(CLR_CMAKE_HOST_WIN32) # Assume we are using default MSVC compiler add_compile_options(/permissive-) + # Enable C11 atomics so libunwind's usage + # (e.g. atomic_compare_exchange_strong in Gaddress_validator.c) compiles + # against MSVC's real header instead of a generated fake. + # /std:c11 is already implied by CMAKE_C_STANDARD=11 set in libunwind/CMakeLists.txt. + # CMAKE_C_COMPILER_ID is used instead of MSVC so that clang-cl (which sets + # MSVC=TRUE but does not accept /experimental:c11atomics) is excluded. + # The COMPILE_LANGUAGE:C generator expression scopes the flag to C sources + # so it is not passed to C++ compilation (e.g. remote-unwind.cpp). + if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") + add_compile_options($<$:/experimental:c11atomics>) + endif() + # include paths include_directories(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/tdep) include_directories(${CLR_SRC_NATIVE_DIR}/external/libunwind/include) diff --git a/src/native/external/libunwind_extras/configure.cmake b/src/native/external/libunwind_extras/configure.cmake index c95dfbefc84996..ae2c8b5ea2fbc0 100644 --- a/src/native/external/libunwind_extras/configure.cmake +++ b/src/native/external/libunwind_extras/configure.cmake @@ -7,19 +7,6 @@ if(CLR_CMAKE_HOST_WIN32) set(HAVE_ELF_H 1) set(HAVE_ENDIAN_H 1) - # MSVC compiler is currently missing C11 stdalign.h header - # Fake it until support is added - check_include_files(stdalign.h HAVE_STDALIGN_H) - if (NOT HAVE_STDALIGN_H) - configure_file(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/remote/win/fakestdalign.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/stdalign.h COPYONLY) - endif (NOT HAVE_STDALIGN_H) - - # MSVC compiler is currently missing C11 stdatomic.h header - check_c_source_compiles("#include void main() { _Atomic int a; }" HAVE_STDATOMIC_H) - if (NOT HAVE_STDATOMIC_H) - configure_file(${CLR_SRC_NATIVE_DIR}/external/libunwind/include/remote/win/fakestdatomic.h.in ${CMAKE_CURRENT_BINARY_DIR}/include/stdatomic.h COPYONLY) - endif (NOT HAVE_STDATOMIC_H) - # MSVC compiler is currently missing C11 _Thread_local check_c_source_compiles("void main() { _Thread_local int a; }" HAVE_THREAD_LOCAL) if (NOT HAVE_THREAD_LOCAL)