[compiler-rt] r282085 - [compiler-rt] Fix Asan build on Android

Etienne Bergeron via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 21 09:32:14 PDT 2016


Author: etienneb
Date: Wed Sep 21 11:32:14 2016
New Revision: 282085

URL: http://llvm.org/viewvc/llvm-project?rev=282085&view=rev
Log:
[compiler-rt] Fix Asan build on Android

Summary:
The dynamic shadow code is not detected correctly on Android.
The android shadow seems to start at address zero.

The bug is introduced here:
  https://reviews.llvm.org/D23363

Started here: https://build.chromium.org/p/chromium.fyi/builders/ClangToTAndroidASan/builds/4029
Likely due to an asan runtime change, filed https://llvm.org/bugs/show_bug.cgi?id=30462


>From asan_mapping.h:
```
#if SANITIZER_WORDSIZE == 32
#  if SANITIZER_ANDROID
#    define SHADOW_OFFSET (0)   <<---- HERE
#  elif defined(__mips__)
```
Shadow address on android is 0.

>From asan_rtl.c:
```
  if (shadow_start == 0) {
    [...]
    shadow_start = FindAvailableMemoryRange(space_size, alignment, granularity);
  }
```
We assumed that 0 is dynamic address.

On windows, the address was determined with:
```
#  elif SANITIZER_WINDOWS64
#   define SHADOW_OFFSET __asan_shadow_memory_dynamic_address
#  else
```
and __asan_shadow_memory_dynamic_address is initially zero.

Reviewers: rnk, eugenis, vitalybuka

Subscribers: kcc, tberghammer, danalbert, kubabrecka, dberris, llvm-commits, chrisha

Differential Revision: https://reviews.llvm.org/D24768

Modified:
    compiler-rt/trunk/lib/asan/asan_mapping.h
    compiler-rt/trunk/lib/asan/asan_rtl.cc

Modified: compiler-rt/trunk/lib/asan/asan_mapping.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mapping.h?rev=282085&r1=282084&r2=282085&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mapping.h (original)
+++ compiler-rt/trunk/lib/asan/asan_mapping.h Wed Sep 21 11:32:14 2016
@@ -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.

Modified: compiler-rt/trunk/lib/asan/asan_rtl.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_rtl.cc?rev=282085&r1=282084&r2=282085&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Wed Sep 21 11:32:14 2016
@@ -461,9 +461,18 @@ static void AsanInitInternal() {
 
   ReplaceSystemMalloc();
 
-  __asan_shadow_memory_dynamic_address = 0;
+  // Set the shadow memory address to uninitialized.
+  __asan_shadow_memory_dynamic_address = kDefaultShadowSentinel;
+
   uptr shadow_start = kLowShadowBeg;
-  if (shadow_start == 0) {
+  // Detect if a dynamic shadow address must used and find a available location
+  // when necessary. When dynamic address is used, the macro |kLowShadowBeg|
+  // expands to |__asan_shadow_memory_dynamic_address| which is
+  // |kDefaultShadowSentinel|.
+  if (shadow_start == kDefaultShadowSentinel) {
+    __asan_shadow_memory_dynamic_address = 0;
+    CHECK_EQ(0, kLowShadowBeg);
+
     uptr granularity = GetMmapGranularity();
     uptr alignment = 8 * granularity;
     uptr left_padding = granularity;
@@ -473,6 +482,7 @@ static void AsanInitInternal() {
     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)




More information about the llvm-commits mailing list