From 87a9cbaed1d6a6c7759d20279436914bb15343f0 Mon Sep 17 00:00:00 2001 From: Brian Cain Date: Fri, 24 Apr 2026 09:59:04 -0500 Subject: [PATCH] [compiler-rt][TySan] Add Hexagon target support (#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. --- .../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 2a6cbac76d50..761e26ce3e7d 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 96049c8d1c9a..c4d9b8fa3a74 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