-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[compiler-rt] Simplify definition of uptr #106155
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] Simplify definition of uptr #106155
Conversation
Created using spr 1.3.6-beta.1
@llvm/pr-subscribers-compiler-rt-sanitizer Author: Alexander Richardson (arichardson) ChangesWe can rely on the compiler-provided macro UINTPTR_TYPE for all This means we no longer need to explicitly handle new architectures Fixes: #101998 Full diff: https://github.com/llvm/llvm-project/pull/106155.diff 1 Files Affected:
diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
index 3af47c2e2ff7a7..f8f03454ea169a 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
@@ -138,19 +138,19 @@
// in a portable way by the language itself.
namespace __sanitizer {
-#if defined(_WIN64)
+#if defined(__UINTPTR_TYPE__)
+typedef __UINTPTR_TYPE__ uptr;
+typedef __INTPTR_TYPE__ sptr;
+#elif defined(_WIN64)
// 64-bit Windows uses LLP64 data model.
typedef unsigned long long uptr;
typedef signed long long sptr;
-#else
-# if (SANITIZER_WORDSIZE == 64) || SANITIZER_APPLE || SANITIZER_WINDOWS
-typedef unsigned long uptr;
-typedef signed long sptr;
-# else
+#elif defined(_WIN32)
typedef unsigned int uptr;
typedef signed int sptr;
-# endif
-#endif // defined(_WIN64)
+#else
+# error Unsupported compiler, missing __UINTPTR_TYPE__
+#endif // defined(__UINTPTR_TYPE__)
#if defined(__x86_64__)
// Since x32 uses ILP32 data model in 64-bit hardware mode, we must use
// 64-bit pointer to unwind stack frame.
|
This change also breaks i686 mingw builds in the same way as #106135
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Marking as request changes, to set the status for clarity.)
Created using spr 1.3.6-beta.1 [skip ci]
Created using spr 1.3.6-beta.1
I've rebased this on top of #106311 which should hopefully fix the Windows issues you were seeing. |
Created using spr 1.3.6-beta.1 [skip ci]
✅ With the latest revision this PR passed the C/C++ code formatter. |
Created using spr 1.3.6-beta.1 [skip ci]
Created using spr 1.3.6-beta.1 [skip ci]
@mstorsjo I confirmed that llvm-mingw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this looks reasonable, and as you've tested that it works with llvm-mingw, I guess it works. I haven't tested building it with MSVC though.
this has uncovered some nasty macro redefinitions in Linux headers which affects Android asan builds: https://crbug.com/365812505. can we revert this for now? |
Oh that is rather nasty - it sounds like Clang has the wrong UINTPTR_TYPE for Android arm32? And I guess changing that could have surprising effects? I am surprised you did not get a compiler error, the compiler-rt/lib/interception/interception_type_test.cpp file should have failed to compile (unless it happens that in that file asm/types.h is included first and redefines UINTPTR_TYPE. I wonder if the workaround would be something like the following
Or alternatively just adding
|
I'll send out a PR that hardcodes |
After llvm#106155, Android arm32 asan builds stopped working with missing definition linker errors. This is due to inconsistent definitions of `uptr` of either `unsigned long` or `unsigned int` even between TUs in compiler-rt. This is caused by Linux arm32 headers redefining __UINTPTR_TYPE__ (see arch/arm/include/uapi/asm/types.h in the Linux kernel repo), meaning include order/whether or not the Linux header is included changes compiler-rt symbol mangling. As a workaround, this hardcodes `uptr`/`sptr` in compiler-rt to `unsigned int`/`int` on Linux arm32, matching clang/gcc.
Is that still simpler than what we had before this PR then? |
Even if it's slightly more verbose, the advantage of the new definition is that uptr now precisely matches the type of uintptr_t rather than just being the same size. |
Except on Linux/arm, while previously things were fairly similar across platforms. |
After #106155, Android arm32 asan builds stopped working with missing definition linker errors. This is due to inconsistent definitions of `uptr` of either `unsigned long` or `unsigned int` even between TUs in compiler-rt. This is caused by Linux arm32 headers redefining `__UINTPTR_TYPE__` (see `arch/arm/include/uapi/asm/types.h` in the Linux kernel repo), meaning include order/whether or not the Linux header is included changes compiler-rt symbol mangling. As a workaround, this hardcodes `uptr`/`sptr` in compiler-rt to `unsigned int`/`int` on Linux arm32, matching clang/gcc.
We can rely on the compiler-provided macro UINTPTR_TYPE for all
non-MSVC compilers. I verified via https://godbolt.org/z/MW9KMjv5f that
this works for MSVC as well as GCC 4.5 Clang 3.0, so that should cover
all supported compilers.
This means we no longer need to explicitly handle new architectures
and as an added bonus also adds support for architectures where
unsigned long long
cannot be used to hold pointers (e.g. CHERI).