[compiler-rt] [llvm] [ASan][Fuchsia] Have Fuchsia use a dynamic shadow start (PR #180880)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 10 20:27:43 PST 2026
https://github.com/PiJoules created https://github.com/llvm/llvm-project/pull/180880
The dynamic shadow global is still set to zero, but this will change in the future.
>From b008eb388410b11048b077abf87cb7e5941b051b Mon Sep 17 00:00:00 2001
From: Leonard Chan <leonardchan at google.com>
Date: Tue, 10 Feb 2026 20:26:19 -0800
Subject: [PATCH] [ASan][Fuchsia] Have Fuchsia use a dynamic shadow start
The dynamic shadow global is still set to zero, but this will change in
the future.
---
compiler-rt/lib/asan/CMakeLists.txt | 4 +++-
compiler-rt/lib/asan/asan_fuchsia.cpp | 10 ++++------
compiler-rt/lib/asan/asan_mapping.h | 2 +-
.../Transforms/Instrumentation/AddressSanitizer.cpp | 7 ++++---
4 files changed, 12 insertions(+), 11 deletions(-)
diff --git a/compiler-rt/lib/asan/CMakeLists.txt b/compiler-rt/lib/asan/CMakeLists.txt
index 232bb2574a778..4db12ea93270d 100644
--- a/compiler-rt/lib/asan/CMakeLists.txt
+++ b/compiler-rt/lib/asan/CMakeLists.txt
@@ -61,7 +61,9 @@ set(ASAN_STATIC_SOURCES
asan_rtl_static.cpp
)
-if ("x86_64" IN_LIST ASAN_SUPPORTED_ARCH AND NOT WIN32 AND NOT APPLE)
+# TODO: These particular 64-bit targets use a dynamic shadow, so we should
+# probably have a cmake variable for this.
+if ("x86_64" IN_LIST ASAN_SUPPORTED_ARCH AND NOT WIN32 AND NOT APPLE AND NOT FUCHSIA)
list(APPEND ASAN_STATIC_SOURCES
asan_rtl_x86_64.S
)
diff --git a/compiler-rt/lib/asan/asan_fuchsia.cpp b/compiler-rt/lib/asan/asan_fuchsia.cpp
index a9e5dad91b973..52fcd789e168f 100644
--- a/compiler-rt/lib/asan/asan_fuchsia.cpp
+++ b/compiler-rt/lib/asan/asan_fuchsia.cpp
@@ -40,18 +40,16 @@ void InitializeShadowMemory() {
if (Verbosity())
PrintAddressSpaceLayout();
- // Make sure SHADOW_OFFSET doesn't use __asan_shadow_memory_dynamic_address.
- __asan_shadow_memory_dynamic_address = kDefaultShadowSentinel;
- DCHECK(kLowShadowBeg != kDefaultShadowSentinel);
- __asan_shadow_memory_dynamic_address = kLowShadowBeg;
+ // Shadow on Fuchsia starts as zero for now.
+ __asan_shadow_memory_dynamic_address = 0;
CHECK_EQ(kShadowGapEnd, kHighShadowBeg - 1);
CHECK_EQ(kHighMemEnd, __sanitizer::ShadowBounds.memory_limit - 1);
CHECK_EQ(kHighMemBeg, __sanitizer::ShadowBounds.shadow_limit);
CHECK_EQ(kHighShadowBeg, __sanitizer::ShadowBounds.shadow_base);
CHECK_EQ(kShadowGapEnd, __sanitizer::ShadowBounds.shadow_base - 1);
- CHECK_EQ(kLowShadowEnd, 0);
- CHECK_EQ(kLowShadowBeg, 0);
+ CHECK_EQ(kLowShadowEnd, MEM_TO_SHADOW(kLowMemEnd));
+ CHECK_EQ(kLowShadowBeg, __asan_shadow_memory_dynamic_address);
}
void AsanApplyToGlobals(globals_op_fptr op, const void *needle) {
diff --git a/compiler-rt/lib/asan/asan_mapping.h b/compiler-rt/lib/asan/asan_mapping.h
index 338324686a31d..e1be633a99bd6 100644
--- a/compiler-rt/lib/asan/asan_mapping.h
+++ b/compiler-rt/lib/asan/asan_mapping.h
@@ -175,7 +175,7 @@
#define ASAN_SHADOW_SCALE 3
#if SANITIZER_FUCHSIA
-# define ASAN_SHADOW_OFFSET_CONST (0)
+# define ASAN_SHADOW_OFFSET_DYNAMIC
#elif SANITIZER_WORDSIZE == 32
# if SANITIZER_ANDROID
# define ASAN_SHADOW_OFFSET_DYNAMIC
diff --git a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
index 2d4c4c9b057c6..4f495b4814d92 100644
--- a/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
+++ b/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp
@@ -549,9 +549,10 @@ static ShadowMapping getShadowMapping(const Triple &TargetTriple, int LongSize,
} else { // LongSize == 64
// Fuchsia is always PIE, which means that the beginning of the address
// space is always available.
- if (IsFuchsia)
- Mapping.Offset = 0;
- else if (IsPPC64)
+ if (IsFuchsia) {
+ // kDynamicShadowSentinel tells instrumentation to use the dynamic shadow.
+ Mapping.Offset = kDynamicShadowSentinel;
+ } else if (IsPPC64)
Mapping.Offset = kPPC64_ShadowOffset64;
else if (IsSystemZ)
Mapping.Offset = kSystemZ_ShadowOffset64;
More information about the llvm-commits
mailing list