[compiler-rt] [compiler-rt] Hardcode uptr/sptr typedefs on Linux Arm (PR #108105)

Arthur Eubanks via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 15:59:02 PDT 2024


https://github.com/aeubanks updated https://github.com/llvm/llvm-project/pull/108105

>From 637775d297364b2cdf0e67253d4d11b65b49f1cf Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Tue, 10 Sep 2024 22:14:21 +0000
Subject: [PATCH 1/2] [compiler-rt] Hardcode uptr/sptr typedefs on Linux Arm

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.
---
 compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
index f8f03454ea169a..bf15d6704b4bd8 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
@@ -139,8 +139,14 @@
 namespace __sanitizer {
 
 #if defined(__UINTPTR_TYPE__)
+#if defined(__arm__) && defined(__linux__)
+// Linux Arm headers redefine __UINTPTR_TYPE__ and disagree with clang/gcc.
+typedef unsigned int uptr;
+typedef int sptr;
+#else
 typedef __UINTPTR_TYPE__ uptr;
 typedef __INTPTR_TYPE__ sptr;
+#endif
 #elif defined(_WIN64)
 // 64-bit Windows uses LLP64 data model.
 typedef unsigned long long uptr;

>From 16512974ce1d8ea4b8614683bfda23534f887d4b Mon Sep 17 00:00:00 2001
From: Arthur Eubanks <aeubanks at google.com>
Date: Tue, 10 Sep 2024 22:58:47 +0000
Subject: [PATCH 2/2] clang-format

---
 compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
index bf15d6704b4bd8..9208b12552ff5c 100644
--- a/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
+++ b/compiler-rt/lib/sanitizer_common/sanitizer_internal_defs.h
@@ -139,14 +139,14 @@
 namespace __sanitizer {
 
 #if defined(__UINTPTR_TYPE__)
-#if defined(__arm__) && defined(__linux__)
+#  if defined(__arm__) && defined(__linux__)
 // Linux Arm headers redefine __UINTPTR_TYPE__ and disagree with clang/gcc.
 typedef unsigned int uptr;
 typedef int sptr;
-#else
+#  else
 typedef __UINTPTR_TYPE__ uptr;
 typedef __INTPTR_TYPE__ sptr;
-#endif
+#  endif
 #elif defined(_WIN64)
 // 64-bit Windows uses LLP64 data model.
 typedef unsigned long long uptr;



More information about the llvm-commits mailing list