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

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

Conversation

arichardson
Copy link
Member

@arichardson arichardson commented Aug 27, 2024

The interceptor types are supposed to match size_t (and the non-Windows
ssize_t) exactly, but on 32-bit Windows size_t uses unsigned int
whereas SIZE_T is unsigned long. The current definition results in
uptr not matching uintptr_t since we otherwise get typedef
redefinition errors. Work around this by using a #define instead of
a typedef when defining SIZE_T.

It would probably be cleaner to stop using these uppercase types, but
that is a rather invasive change and this one is the minimal change to
allow uptr to match uintptr_t on Windows.

To ensure this compiles on Windows, we also remove the interceptor.h
defines of uptr (that do not always match __sanitizer::uptr) and rely
on __sanitizer::uptr instead. The interceptor types most likely predate
those other types so clean up the unnecessary definition while here.

This also reverts commit 18e06e3 and
commit bb27dd8.

Created using spr 1.3.6-beta.1
@llvmbot
Copy link
Collaborator

llvmbot commented Aug 27, 2024

@llvm/pr-subscribers-compiler-rt-sanitizer

Author: Alexander Richardson (arichardson)

Changes

The interceptor types are supposed to match size_t (and the non-Windows
ssize_t) exactly, but on 32-bit Windows size_t uses unsigned int
whereas SIZE_T is unsigned long. The current definition results in
uptr not matching uintptr_t since we otherwise get typedef
redefinition errors. Work around this by using a #define instead of
a typedef when defining SIZE_T.

It would probably be cleaner to stop using these uppercase types, but
that is a rather invasive change and this one is the minimal change to
allow uptr to match uintptr_t on Windows.

This also reverts commit 18e06e3.


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

3 Files Affected:

  • (modified) compiler-rt/lib/interception/interception.h (+8-2)
  • (modified) compiler-rt/lib/interception/interception_type_test.cpp (+14-6)
  • (modified) compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h (+1-1)
diff --git a/compiler-rt/lib/interception/interception.h b/compiler-rt/lib/interception/interception.h
index 38c152952e3232..c061752231c64e 100644
--- a/compiler-rt/lib/interception/interception.h
+++ b/compiler-rt/lib/interception/interception.h
@@ -25,8 +25,14 @@
 
 // These typedefs should be used only in the interceptor definitions to replace
 // the standard system types (e.g. SSIZE_T instead of ssize_t)
-typedef __sanitizer::uptr    SIZE_T;
-typedef __sanitizer::sptr    SSIZE_T;
+// On Windows the system headers (basetsd.h) provide a conflicting definition
+// of SIZE_T/SSIZE_T that do not match the real size_t/ssize_t for 32-bit
+// systems (using long instead of the expected int). Work around the typedef
+// redefinition by #defining SIZE_T instead of using a typedef.
+// TODO: We should be using __sanitizer::usize (and a new ssize) instead of
+// these new macros as long as we ensure they match the real system definitions.
+#define SIZE_T __sanitizer::usize
+#define SSIZE_T __sanitizer::sptr
 typedef __sanitizer::sptr    PTRDIFF_T;
 typedef __sanitizer::s64     INTMAX_T;
 typedef __sanitizer::u64     UINTMAX_T;
diff --git a/compiler-rt/lib/interception/interception_type_test.cpp b/compiler-rt/lib/interception/interception_type_test.cpp
index 7c3de82a1e869c..ccf555c7b1bc20 100644
--- a/compiler-rt/lib/interception/interception_type_test.cpp
+++ b/compiler-rt/lib/interception/interception_type_test.cpp
@@ -12,17 +12,26 @@
 //===----------------------------------------------------------------------===//
 
 #include "interception.h"
+#include "sanitizer_common/sanitizer_type_traits.h"
 
-#if SANITIZER_LINUX || SANITIZER_APPLE
-
+#if __has_include(<sys/types.h>)
 #include <sys/types.h>
+#endif
 #include <stddef.h>
 #include <stdint.h>
 
-COMPILER_CHECK(sizeof(::SIZE_T) == sizeof(size_t));
-COMPILER_CHECK(sizeof(::SSIZE_T) == sizeof(ssize_t));
-COMPILER_CHECK(sizeof(::PTRDIFF_T) == sizeof(ptrdiff_t));
+COMPILER_CHECK((__sanitizer::is_same<__sanitizer::uptr, ::uintptr_t>::value));
+COMPILER_CHECK((__sanitizer::is_same<__sanitizer::sptr, ::intptr_t>::value));
+COMPILER_CHECK((__sanitizer::is_same<__sanitizer::usize, ::size_t>::value));
+COMPILER_CHECK((__sanitizer::is_same<::PTRDIFF_T, ::ptrdiff_t>::value));
+COMPILER_CHECK((__sanitizer::is_same<::SIZE_T, ::size_t>::value));
+#if !SANITIZER_WINDOWS
+// No ssize_t on Windows.
+COMPILER_CHECK((__sanitizer::is_same<::SSIZE_T, ::ssize_t>::value));
+#endif
+// TODO: These are not actually the same type on Linux (long vs long long)
 COMPILER_CHECK(sizeof(::INTMAX_T) == sizeof(intmax_t));
+COMPILER_CHECK(sizeof(::UINTMAX_T) == sizeof(uintmax_t));
 
 #  if SANITIZER_GLIBC || SANITIZER_ANDROID
 COMPILER_CHECK(sizeof(::OFF64_T) == sizeof(off64_t));
@@ -36,4 +45,3 @@ COMPILER_CHECK(sizeof(::OFF64_T) == sizeof(off64_t));
 COMPILER_CHECK(sizeof(::OFF_T) == sizeof(off_t));
 # endif
 
-#endif
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
index 1607436e476e52..26089948c3e2d0 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
@@ -143,7 +143,7 @@ namespace __sanitizer {
 typedef unsigned long long uptr;
 typedef signed long long sptr;
 #else
-#  if (SANITIZER_WORDSIZE == 64) || SANITIZER_APPLE || SANITIZER_WINDOWS
+#  if (SANITIZER_WORDSIZE == 64) || SANITIZER_APPLE
 typedef unsigned long uptr;
 typedef signed long sptr;
 #  else

Created using spr 1.3.6-beta.1

#if SANITIZER_LINUX || SANITIZER_APPLE
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is unrelated, but IMO we should check these static asserts everywhere possible.

Copy link

github-actions bot commented Aug 27, 2024

✅ With the latest revision this PR passed the C/C++ code formatter.

Created using spr 1.3.6-beta.1
Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 *)'

@arichardson
Copy link
Member Author

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 *)'

Thanks for testing this - I will try to rework it to fix the problem.

Created using spr 1.3.6-beta.1
@arichardson
Copy link
Member Author

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

Created using spr 1.3.6-beta.1
@mstorsjo
Copy link
Member

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

Indeed, this version does build successfully with MSVC, and it does get past the earlier quoted errors when building for mingw targets, but for mingw x86_64 (and MSVC x86_64 too), it fails on other issues due to some of the other, new static asserts you've added here:

/home/martin/code/llvm-mingw/llvm-project/compiler-rt/lib/interception/interception_type_test.cpp:44:16: error: static assertion failed due to requirement 'sizeof(unsigned long long) == sizeof(long)': 
   44 | COMPILER_CHECK(sizeof(::OFF_T) == sizeof(off_t));
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/martin/code/llvm-mingw/llvm-project/compiler-rt/lib/interception/../sanitizer_common/sanitizer_internal_defs.h:357:44: note: expanded from macro 'COMPILER_CHECK'
  357 | #define COMPILER_CHECK(pred) static_assert(pred, "")
      |                                            ^~~~
/home/martin/code/llvm-mingw/llvm-project/compiler-rt/lib/interception/interception_type_test.cpp:44:32: note: expression evaluates to '8 == 4'
   44 | COMPILER_CHECK(sizeof(::OFF_T) == sizeof(off_t));
      |                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
/home/martin/code/llvm-mingw/llvm-project/compiler-rt/lib/interception/../sanitizer_common/sanitizer_internal_defs.h:357:44: note: expanded from macro 'COMPILER_CHECK'
  357 | #define COMPILER_CHECK(pred) static_assert(pred, "")
      |                                            ^~~~
1 error generated.

FWIW, it should be quite easy to test the build for mingw targets, with llvm-mingw. To do that:

  1. Clone https://github.com/mstorsjo/llvm-mingw
  2. Within your llvm-mingw checkout, check out (or symlink) your llvm-project repo, so that you have llvm-mingw/llvm-project containing your compiler-rt code to be tested
  3. Grab an existing release, e.g. https://github.com/mstorsjo/llvm-mingw/releases/tag/20240820, and download a suitable package for you (e.g. an x86_64 linux build), e.g. llvm-mingw-20240820-ucrt-ubuntu-20.04-x86_64.tar.xz, and unpack that somewhere
  4. Within the llvm-mingw directory, run ./build-compiler-rt.sh --build-sanitizers <path-to-unpacked-toolchain>. That uses the toolchain from step 3, which is expected to be unpacked in <path-to-unpacked-toolchain>, building the compiler-rt code in llvm-mingw/llvm-project and installing it on top of your unpacked toolchain. This tries building it for both i686 and x86_64.

The compiler-rt sanitizers are buildable for armv7 and aarch64 too, but the build-compiler-rt.sh script skips that for now (it's not buildable for armv7 in the 19.x release branch), but if you want to, you can rip out the code for skipping those arches in the script, in order to test building for all 4 architectures.

Created using spr 1.3.6-beta.1
@arichardson
Copy link
Member Author

arichardson commented Aug 29, 2024

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

Indeed, this version does build successfully with MSVC, and it does get past the earlier quoted errors when building for mingw targets, but for mingw x86_64 (and MSVC x86_64 too), it fails on other issues due to some of the other, new static asserts you've added here:

/home/martin/code/llvm-mingw/llvm-project/compiler-rt/lib/interception/interception_type_test.cpp:44:16: error: static assertion failed due to requirement 'sizeof(unsigned long long) == sizeof(long)': 
   44 | COMPILER_CHECK(sizeof(::OFF_T) == sizeof(off_t));
      |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/home/martin/code/llvm-mingw/llvm-project/compiler-rt/lib/interception/../sanitizer_common/sanitizer_internal_defs.h:357:44: note: expanded from macro 'COMPILER_CHECK'
  357 | #define COMPILER_CHECK(pred) static_assert(pred, "")
      |                                            ^~~~
/home/martin/code/llvm-mingw/llvm-project/compiler-rt/lib/interception/interception_type_test.cpp:44:32: note: expression evaluates to '8 == 4'
   44 | COMPILER_CHECK(sizeof(::OFF_T) == sizeof(off_t));
      |                ~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
/home/martin/code/llvm-mingw/llvm-project/compiler-rt/lib/interception/../sanitizer_common/sanitizer_internal_defs.h:357:44: note: expanded from macro 'COMPILER_CHECK'
  357 | #define COMPILER_CHECK(pred) static_assert(pred, "")
      |                                            ^~~~
1 error generated.

FWIW, it should be quite easy to test the build for mingw targets, with llvm-mingw. To do that:

  1. Clone https://github.com/mstorsjo/llvm-mingw
  2. Within your llvm-mingw checkout, check out (or symlink) your llvm-project repo, so that you have llvm-mingw/llvm-project containing your compiler-rt code to be tested
  3. Grab an existing release, e.g. https://github.com/mstorsjo/llvm-mingw/releases/tag/20240820, and download a suitable package for you (e.g. an x86_64 linux build), e.g. llvm-mingw-20240820-ucrt-ubuntu-20.04-x86_64.tar.xz, and unpack that somewhere
  4. Within the llvm-mingw directory, run ./build-compiler-rt.sh --build-sanitizers <path-to-unpacked-toolchain>. That uses the toolchain from step 3, which is expected to be unpacked in <path-to-unpacked-toolchain>, building the compiler-rt code in llvm-mingw/llvm-project and installing it on top of your unpacked toolchain. This tries building it for both i686 and x86_64.

The compiler-rt sanitizers are buildable for armv7 and aarch64 too, but the build-compiler-rt.sh script skips that for now (it's not buildable for armv7 in the 19.x release branch), but if you want to, you can rip out the code for skipping those arches in the script, in order to test building for all 4 architectures.

Thank you very much for those instructions! I have now built for Win64 and avoided the static_assert. I plan to clean up off_t handling in a separate PR.

EDIT: also checked armv7 and aarch64 and both of those also compile. So hopefully this is ready to merge.

Copy link
Member

@mstorsjo mstorsjo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, this seems to work fine now. (I don't have a strong opinion on whether this is a good way of solving it or not though.)

@arichardson arichardson merged commit ec68dc1 into main Aug 29, 2024
7 checks passed
@arichardson arichardson deleted the users/arichardson/spr/compiler-rt-work-around-incompatible-windows-definitions-of-ssize_t branch August 29, 2024 22:59
@wrotki
Copy link
Contributor

wrotki commented Sep 5, 2024

We're seeing a build failures on Mac LLVM compile like:
....
.../llvm-project/compiler-rt/lib/interception/interception_type_test.cpp:26:17: error: static assertion failed due to requirement '__sanitizer::is_same<long, int>::value':
26 | COMPILER_CHECK((__sanitizer::is_same<::PTRDIFF_T, ::ptrdiff_t>::value));
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.../llvm-project/compiler-rt/lib/interception/../sanitizer_common/sanitizer_internal_defs.h:362:44: note: expanded from macro 'COMPILER_CHECK'
362 | #define COMPILER_CHECK(pred) static_assert(pred, "")
| ^~~~
1 error generated.
....

I'm trying to reproduce it locally - but until I do and figure out why exactly it is happening in our configuration, would you consider reverting? Thanks

@wrotki wrotki self-requested a review September 5, 2024 21:56
@arichardson
Copy link
Member Author

We're seeing a build failures on Mac LLVM compile like: .... .../llvm-project/compiler-rt/lib/interception/interception_type_test.cpp:26:17: error: static assertion failed due to requirement '__sanitizer::is_same<long, int>::value': 26 | COMPILER_CHECK((__sanitizer::is_same<::PTRDIFF_T, ::ptrdiff_t>::value)); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .../llvm-project/compiler-rt/lib/interception/../sanitizer_common/sanitizer_internal_defs.h:362:44: note: expanded from macro 'COMPILER_CHECK' 362 | #define COMPILER_CHECK(pred) static_assert(pred, "") | ^~~~ 1 error generated. ....

I'm trying to reproduce it locally - but until I do and figure out why exactly it is happening in our configuration, would you consider reverting? Thanks

It sounds like on macos 32 bit ptrdiff_t is int rather than long. You could replace COMPILER_CHECK((__sanitizer::is_same<::PTRDIFF_T, ::ptrdiff_t>::value)); with the previous COMPILER_CHECK(sizeof(::PTRDIFF_T) == sizeof(ptrdiff_t));. The real fix would be to define PTRDIFF_T as int for your 32-bit configuration.

Can you tell me which target you are building for?

@arichardson
Copy link
Member Author

The other option would be

#if SANITIZER_APPLE && SANITIZER_WORDSIZE == 32
typedef int    PTRDIFF_T;
#else
typedef __sanitizer::sptr    PTRDIFF_T;
#endif

@wrotki
Copy link
Contributor

wrotki commented Sep 6, 2024

My clang command line has -arch arm64 -arch i386 -arch x86_64 , while I only see -arch arm64 -arch x86_64 in open source build, which is probably why it works there, only 64 bit.

Let me experiment with your suggestions, thanks!

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

Successfully merging this pull request may close these issues.

5 participants