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 & windows build should use longjmp #3809

Open
calvin2021y opened this issue Sep 20, 2024 · 3 comments
Open

clang & windows build should use longjmp #3809

calvin2021y opened this issue Sep 20, 2024 · 3 comments

Comments

@calvin2021y
Copy link

windows clang use setjmp like posix, the current implement only work for msvc.

I guess for mingw , BH_PLATFORM_WINDOWS also should be disabled.

#if defined(__clang__) || defined(__GNUC__)
    #define os_thread_local_attribute __thread
#elif defined(_MSC_VER)
    #define os_thread_local_attribute __declspec(thread)
#else
    #error "Unknown compiler, unable to define os_thread_local_attribute"
#endif
@calvin2021y
Copy link
Author

https://github.com/mstorsjo/llvm-mingw is great to cross build windows app.

@calvin2021y
Copy link
Author

calvin2021y commented Sep 20, 2024

diff --git a/core/shared/platform/windows/shared_platform.cmake b/core/shared/platform/windows/shared_platform.cmake
index 502a8a2e..0b402a06 100644
--- a/core/shared/platform/windows/shared_platform.cmake
+++ b/core/shared/platform/windows/shared_platform.cmake
@@ -3,7 +3,10 @@
 
 set (PLATFORM_SHARED_DIR ${CMAKE_CURRENT_LIST_DIR})
 
-add_definitions(-DBH_PLATFORM_WINDOWS)
+if(NOT MINGW)
+  add_definitions(-DBH_PLATFORM_WINDOWS)
+endif()
+
 add_definitions(-DHAVE_STRUCT_TIMESPEC)
 add_definitions(-D_WINSOCK_DEPRECATED_NO_WARNINGS)
diff --git a/core/shared/platform/windows/platform_internal.h b/core/shared/platform/windows/platform_internal.h
index 8bb77e7c..564f6931 100644
--- a/core/shared/platform/windows/platform_internal.h
+++ b/core/shared/platform/windows/platform_internal.h
@@ -39,8 +39,10 @@ extern "C" {
 #endif

 #ifndef BH_PLATFORM_WINDOWS
+#if defined(_MSC_VER)
 #define BH_PLATFORM_WINDOWS
 #endif
+#endif

 #ifdef _MSC_VER
 #ifndef PATH_MAX
@@ -92,7 +94,13 @@ os_mem_commit(void *ptr, size_t size, int flags);
 void
 os_mem_decommit(void *ptr, size_t size);

-#define os_thread_local_attribute __declspec(thread)
+#if defined(__clang__) || defined(__GNUC__)
+    #define os_thread_local_attribute __thread
+#elif defined(_MSC_VER)
+    #define os_thread_local_attribute __declspec(thread)
+#else
+    #error "Unknown compiler, unable to define os_thread_local_attribute"
+#endif

 #define strncasecmp _strnicmp
 #define strcasecmp _stricmp
@@ -174,7 +182,7 @@ typedef windows_dir_stream *os_dir_stream;
 #if WASM_ENABLE_UVWASI != 1
 typedef HANDLE os_raw_file_handle;
 #else
-typedef uint32_t os_raw_file_handle;
+typedef int32_t os_raw_file_handle;
 #endif

 #define bh_socket_t windows_handle *

with this patch and some adjust I am able to build.

without AOT it work as expect, with AOT it crashed.

@calvin2021y
Copy link
Author

=================================================================
==10248==ERROR: AddressSanitizer: access-violation on unknown address 0x126a940b0004 (pc 0x7ffee8ad46f8 bp 0x00e9ec1ab550 sp 0x00e9ec1ab4c8 T0)
==10248==The signal is caused by a WRITE memory access.                                                                                        
    #0 0x7ffee8ad46f7 in memset+0x77 (C:\Windows\SYSTEM32\ntdll.dll+0x1800a46f7)                                                               
    #1 0x7ffe8ed92cc0 in _asan_memset+0x90 (C:\Users\admin\libclang_rt.asan_dynamic-x86_64.dll+0x180042cc0)                                    
    #2 0x7ff79b1a2df6  (C:\Users\admin\tests_wamr.exe+0x140212df6)  gc_init_internal
    #3 0x7ff79b1a398d  (C:\Users\admin\tests_wamr.exe+0x14021398d)  gc_init_with_struct_and_pool
    #4 0x7ff79b12718c  (C:\Users\admin\tests_wamr.exe+0x14019718c)  mem_allocator_create_with_struct_and_pool                                                  
    #5 0x7ff79b0c6d6b  (C:\Users\admin\tests_wamr.exe+0x140136d6b)  memory_instantiate                                                           
    #6 0x7ff79b0bc7ec  (C:\Users\admin\tests_wamr.exe+0x14012c7ec)  memories_instantiate                                         
    #7 0x7ff79b0b9a3c  (C:\Users\admin\tests_wamr.exe+0x140129a3c)  aot_instantiate                                                                       
    #8 0x7ff79b008b21  (C:\Users\admin\tests_wamr.exe+0x140078b21)  wasm_runtime_instantiate_internal                                                     
    #9 0x7ff79b008bb3  (C:\Users\admin\tests_wamr.exe+0x140078bb3)  wasm_runtime_instantiate                                                                      
    #10 0x7ff79afea2b7  (C:\Users\admin\tests_wamr.exe+0x14005a2b7)                                                                        
    #11 0x7ff79af91310  (C:\Users\admin\tests_wamr.exe+0x140001310)                                                                        
    #12 0x7ff79af91365  (C:\Users\admin\tests_wamr.exe+0x140001365)                                                                        
    #13 0x7ffee8237373 in BaseThreadInitThunk+0x13 (C:\Windows\System32\KERNEL32.DLL+0x180017373)                                              
    #14 0x7ffee8a7cc90 in RtlUserThreadStart+0x20 (C:\Windows\SYSTEM32\ntdll.dll+0x18004cc90)                                                  
                                                                                                                                               
AddressSanitizer can not provide additional info.                                                                                              
SUMMARY: AddressSanitizer: access-violation (C:\Windows\SYSTEM32\ntdll.dll+0x1800a46f7) in memset+0x77                                         
==10248==ABORTING 

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

1 participant