[compiler-rt] [compiler-rt][TySan] Add Hexagon target support (PR #191603)

Brian Cain via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 10 21:59:01 PDT 2026


https://github.com/androm3da created https://github.com/llvm/llvm-project/pull/191603

Add shadow memory mapping for Hexagon (32-bit architecture) and enable the TySan build for the Hexagon target.

Hexagon uses a 4-byte shadow entry (PtrShift=2) with the shadow region at 0x80000000-0xBFFFFFFF (1GB). A 28-bit mask (kAppMemMsk) covers 256MB of app address space; addresses differing only in bits 28-31 alias in the shadow. kAppAddr is set to 0xC0000000 to size the mmap to exactly the 1GB shadow region.

>From 3205faf9aebeb8d3c6a40480cc84f5c5e66edd31 Mon Sep 17 00:00:00 2001
From: Brian Cain <brian.cain at oss.qualcomm.com>
Date: Fri, 10 Apr 2026 21:43:36 -0700
Subject: [PATCH] [compiler-rt][TySan] Add Hexagon target support

Add shadow memory mapping for Hexagon (32-bit architecture) and enable
the TySan build for the Hexagon target.

Hexagon uses a 4-byte shadow entry (PtrShift=2) with the shadow region
at 0x80000000-0xBFFFFFFF (1GB). A 28-bit mask (kAppMemMsk) covers
256MB of app address space; addresses differing only in bits 28-31
alias in the shadow. kAppAddr is set to 0xC0000000 to size the mmap
to exactly the 1GB shadow region.
---
 .../cmake/Modules/AllSupportedArchDefs.cmake       |  2 +-
 compiler-rt/lib/tysan/tysan_platform.h             | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
index 2a6cbac76d502..761e26ce3e7d8 100644
--- a/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
+++ b/compiler-rt/cmake/Modules/AllSupportedArchDefs.cmake
@@ -102,7 +102,7 @@ else()
   set(ALL_TSAN_SUPPORTED_ARCH ${X86_64} ${MIPS64} ${ARM64} ${PPC64} ${S390X}
       ${LOONGARCH64} ${RISCV64})
 endif()
-set(ALL_TYSAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${S390X})
+set(ALL_TYSAN_SUPPORTED_ARCH ${X86_64} ${ARM64} ${S390X} ${HEXAGON})
 set(ALL_UBSAN_SUPPORTED_ARCH ${X86} ${X86_64} ${ARM32} ${ARM64} ${RISCV64}
     ${MIPS32} ${MIPS64} ${PPC64} ${S390X} ${SPARC} ${SPARCV9} ${HEXAGON}
     ${LOONGARCH64} ${AMDGPU} ${NVPTX})
diff --git a/compiler-rt/lib/tysan/tysan_platform.h b/compiler-rt/lib/tysan/tysan_platform.h
index 96049c8d1c9a2..c4d9b8fa3a744 100644
--- a/compiler-rt/lib/tysan/tysan_platform.h
+++ b/compiler-rt/lib/tysan/tysan_platform.h
@@ -52,6 +52,20 @@ struct Mapping {
   static const uptr kAppMemMsk = ~0xC00000000000ULL;
   static const uptr kPtrShift = 3;
 };
+#elif defined(__hexagon__)
+// Hexagon is a 32-bit architecture. Each shadow entry is a 4-byte pointer
+// (PtrShift=2). The shadow occupies 4x the masked app memory range.
+// With a 28-bit mask (256MB of app addresses), the shadow is 1GB at
+// 0x80000000-0xBFFFFFFF. App addresses that differ only in bits 28-31
+// will alias in the shadow; in practice this means code/heap (low addresses)
+// and stack (~0x40000000) may share shadow entries, which can cause
+// false positives in rare cases.
+struct Mapping {
+  static const uptr kShadowAddr = 0x80000000u;
+  static const uptr kAppAddr = 0xC0000000u;
+  static const uptr kAppMemMsk = ~0xF0000000u;
+  static const uptr kPtrShift = 2;
+};
 #else
 #error "TySan not supported for this platform!"
 #endif



More information about the llvm-commits mailing list