Index: lib/asan/asan_mapping.h =================================================================== --- lib/asan/asan_mapping.h +++ lib/asan/asan_mapping.h @@ -125,6 +125,7 @@ // || `[0x00000000, 0x2fffffff]` || LowMem || static const u64 kDefaultShadowScale = 3; +static const u64 kDefaultShadowSentinel = ~(uptr)0; static const u64 kDefaultShadowOffset32 = 1ULL << 29; // 0x20000000 static const u64 kDefaultShadowOffset64 = 1ULL << 44; static const u64 kDefaultShort64bitShadowOffset = 0x7FFF8000; // < 2G. Index: lib/asan/asan_rtl.cc =================================================================== --- lib/asan/asan_rtl.cc +++ lib/asan/asan_rtl.cc @@ -416,6 +416,9 @@ CHECK(!asan_init_is_running && "ASan init calls itself!"); asan_init_is_running = true; + // Set the shadow memory address to uninitialized. + __asan_shadow_memory_dynamic_address = kDefaultShadowSentinel; + CacheBinaryName(); // Initialize flags. This must be done early, because most of the @@ -461,9 +464,14 @@ ReplaceSystemMalloc(); - __asan_shadow_memory_dynamic_address = 0; uptr shadow_start = kLowShadowBeg; - if (shadow_start == 0) { + // Detect if a dynamic shadow address must used and find a available location + // when necessary. + if (shadow_start == kDefaultShadowSentinel) { + __asan_shadow_memory_dynamic_address = 0; + shadow_start = kLowShadowBeg; + CHECK_EQ(0, shadow_start); + uptr granularity = GetMmapGranularity(); uptr alignment = 8 * granularity; uptr left_padding = granularity; @@ -473,6 +481,7 @@ CHECK_NE((uptr)0, shadow_start); CHECK(IsAligned(shadow_start, alignment)); } + // Update the shadow memory address (potentially) used by instrumentation. __asan_shadow_memory_dynamic_address = shadow_start; if (kLowShadowBeg)