[compiler-rt] [llvm] [HWASan][Fuchsia] Have Fuchsia use a dynamic shadow start #180880 (PR #180881)

via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 10 20:29:55 PST 2026


https://github.com/PiJoules created https://github.com/llvm/llvm-project/pull/180881

The dynamic shadow global is still set to zero, but this will change in the future.

>From e29c79179193f82b9bd0e95005b5263b00e4d8da Mon Sep 17 00:00:00 2001
From: Leonard Chan <leonardchan at google.com>
Date: Tue, 10 Feb 2026 20:29:16 -0800
Subject: [PATCH] [HWASan][Fuchsia] Have Fuchsia use a dynamic shadow start
 #180880

The dynamic shadow global is still set to zero, but this will change in the future.
---
 compiler-rt/lib/hwasan/hwasan_fuchsia.cpp                | 9 +++++++--
 compiler-rt/lib/hwasan/hwasan_mapping.h                  | 4 +---
 .../Transforms/Instrumentation/HWAddressSanitizer.cpp    | 2 +-
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp b/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
index 647211bf199e1..3f1d59061ef13 100644
--- a/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
+++ b/compiler-rt/lib/hwasan/hwasan_fuchsia.cpp
@@ -46,12 +46,17 @@ bool InitShadow() {
   __sanitizer::InitShadowBounds();
   CHECK_NE(__sanitizer::ShadowBounds.shadow_limit, 0);
 
+  __hwasan_shadow_memory_dynamic_address = 0;
+
   // These variables are used by MemIsShadow for asserting we have a correct
   // shadow address. On Fuchsia, we only have one region of shadow, so the
   // bounds of Low shadow can be zero while High shadow represents the true
   // bounds. Note that these are inclusive ranges.
-  kLowShadowStart = 0;
-  kLowShadowEnd = 0;
+  uintptr_t LowMemEnd = __hwasan_shadow_memory_dynamic_address
+                            ? __hwasan_shadow_memory_dynamic_address - 1
+                            : 0;
+  kLowShadowStart = __hwasan_shadow_memory_dynamic_address;
+  kLowShadowEnd = MemToShadow(LowMemEnd);
   kHighShadowStart = __sanitizer::ShadowBounds.shadow_base;
   kHighShadowEnd = __sanitizer::ShadowBounds.shadow_limit - 1;
 
diff --git a/compiler-rt/lib/hwasan/hwasan_mapping.h b/compiler-rt/lib/hwasan/hwasan_mapping.h
index 79a143632f6ab..eddc65b8d37f3 100644
--- a/compiler-rt/lib/hwasan/hwasan_mapping.h
+++ b/compiler-rt/lib/hwasan/hwasan_mapping.h
@@ -48,9 +48,7 @@ extern uptr kHighShadowEnd;
 extern uptr kHighMemStart;
 extern uptr kHighMemEnd;
 
-inline uptr GetShadowOffset() {
-  return SANITIZER_FUCHSIA ? 0 : __hwasan_shadow_memory_dynamic_address;
-}
+inline uptr GetShadowOffset() { return __hwasan_shadow_memory_dynamic_address; }
 inline uptr MemToShadow(uptr untagged_addr) {
   return (untagged_addr >> kShadowScale) + GetShadowOffset();
 }
diff --git a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
index f7f82842989ef..495b289fee54a 100644
--- a/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/HWAddressSanitizer.cpp
@@ -1900,7 +1900,7 @@ void HWAddressSanitizer::ShadowMapping::init(Triple &TargetTriple,
   if (TargetTriple.isOSFuchsia()) {
     // Fuchsia is always PIE, which means that the beginning of the address
     // space is always available.
-    SetFixed(0);
+    Kind = OffsetKind::kGlobal;
   } else if (CompileKernel || InstrumentWithCalls) {
     SetFixed(0);
     WithFrameRecord = false;



More information about the llvm-commits mailing list