[compiler-rt] [compiler-rt] Work around incompatible Windows definitions of (S)SIZE_T (PR #106311)

Alexander Richardson via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 28 21:52:37 PDT 2024


arichardson wrote:

> Unfortunately, this doesn't work.
> 
> From the mingw build:
> 
> ```
> In file included from /home/martin/code/llvm-mingw/llvm-project/compiler-rt/lib/interception/interception_win.cpp:132:
> In file included from /home/martin/clang-trunk/i686-w64-mingw32/include/windows.h:69:
> In file included from /home/martin/clang-trunk/i686-w64-mingw32/include/windef.h:9:
> In file included from /home/martin/clang-trunk/i686-w64-mingw32/include/minwindef.h:163:
> In file included from /home/martin/clang-trunk/i686-w64-mingw32/include/winnt.h:150:
> /home/martin/clang-trunk/i686-w64-mingw32/include/basetsd.h:147:39: error: typedef declarator cannot be qualified
>   147 |   __MINGW_EXTENSION typedef ULONG_PTR SIZE_T,*PSIZE_T;
>       |                                       ^~~~~~
> /home/martin/code/llvm-mingw/llvm-project/compiler-rt/lib/interception/interception.h:34:29: note: expanded from macro 'SIZE_T'
>    34 | #define SIZE_T __sanitizer::usize
>       |                ~~~~~~~~~~~~~^
> ```
> 
> From the MSVC build:
> 
> ```
> C:\code\llvm-project\compiler-rt\lib\asan\asan_win.cpp(195): error C2665: '__interception::OverrideFunction': no overloaded function could convert all the argument types
> C:\code\llvm-project\compiler-rt\lib\interception\interception_win.h(31): note: could be 'bool __interception::OverrideFunction(const char *,__interception::uptr,__interception::uptr *)'
> C:\code\llvm-project\compiler-rt\lib\asan\asan_win.cpp(195): note: 'bool __interception::OverrideFunction(const char *,__interception::uptr,__interception::uptr *)': cannot convert argument 3 from '__sanitizer::uptr *' to '__interception::uptr *'
> C:\code\llvm-project\compiler-rt\lib\asan\asan_win.cpp(197): note: Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or parenthesized function-style cast
> C:\code\llvm-project\compiler-rt\lib\interception\interception_win.h(28): note: or       'bool __interception::OverrideFunction(__interception::uptr,__interception::uptr,__interception::uptr *)'
> C:\code\llvm-project\compiler-rt\lib\asan\asan_win.cpp(195): note: 'bool __interception::OverrideFunction(__interception::uptr,__interception::uptr,__interception::uptr *)': cannot convert argument 1 from 'const char [15]' to '__interception::uptr'
> C:\code\llvm-project\compiler-rt\lib\asan\asan_win.cpp(195): note: There is no context in which this conversion is possible
> C:\code\llvm-project\compiler-rt\lib\asan\asan_win.cpp(195): note: while trying to match the argument list '(const char [15], __sanitizer::uptr, __sanitizer::uptr *)'
> ```

I tried setting up a Windows VM, but was not able to get this working today. However, I managed to reproduce these build failures with mingw packages and:
```
-DCMAKE_C_COMPILER=/usr/bin/clang
-DCMAKE_CXX_COMPILER=/usr/bin/clang++
-DCOMPILER_RT_INCLUDE_TESTS=ON
-DCOMPILER_RT_DEBUG=OFF
-DCOMPILER_RT_BUILD_PROFILE=ON
-DCOMPILER_RT_BUILD_XRAY=OFF
-DCOMPILER_RT_BUILD_SANITIZERS=ON
-DCOMPILER_RT_BUILD_LIBFUZZER=OFF
-DCOMPILER_RT_BUILD_GWP_ASAN=ON
-DCOMPILER_RT_BUILD_ORC=OFF
-DCOMPILER_RT_BUILD_MEMPROF=ON
-DCOMPILER_RT_BUILD_CRT=OFF
-DCOMPILER_RT_BUILD_BUILTINS=ON
-DLLVM_CMAKE_DIR=../../build/upstream-llvm-project-build
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=ON
-DCMAKE_C_COMPILER_TARGET=i686-w64-windows-gnu
-DCMAKE_CXX_COMPILER_TARGET=i686-w64-windows-gnu
-DCMAKE_SYSTEM_NAME=Windows
-DCOMPILER_RT_CAN_EXECUTE_TESTS=ON
-DCMAKE_CROSSCOMPILING_EMULATOR=/usr/bin/wine
-DCMAKE_EXE_LINKER_FLAGS_INIT=-L/usr/lib/gcc/i686-w64-mingw32/13-win32/
-DCMAKE_SHARED_LINKER_FLAGS_INIT=-L/usr/lib/gcc/i686-w64-mingw32/13-win32/
```

I can't successfully build the libraries since I get linker errors, but I've confirmed that the latest version of this patch fixes the compilation errors reported by @mstorsjo

https://github.com/llvm/llvm-project/pull/106311


More information about the llvm-commits mailing list