[asan] Restore dead-code-elimination optimization for Fuchsia
authorVitaly Buka <vitalybuka@google.com>
Tue, 8 Aug 2017 01:01:59 +0000 (01:01 +0000)
committerVitaly Buka <vitalybuka@google.com>
Tue, 8 Aug 2017 01:01:59 +0000 (01:01 +0000)
Summary:
r310244 fixed a bug introduced by r309914 for non-Fuchsia builds.
In doing so it also reversed the intended effect of the change for
Fuchsia builds, which was to allow all the AllocateFromLocalPool
code and its variables to be optimized away entirely.

This change restores that optimization for Fuchsia builds, but
doesn't have the original change's bug because the comparison
arithmetic now takes into account the size of the elements.

Submitted on behalf of Roland McGrath.

Reviewers: vitalybuka, alekseyshl

Reviewed By: alekseyshl

Subscribers: llvm-commits, kubamracek

Tags: #sanitizers

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

llvm-svn: 310330

compiler-rt/lib/asan/asan_malloc_linux.cc

index 8222c6d..beef818 100644 (file)
@@ -32,7 +32,7 @@ static uptr alloc_memory_for_dlsym[kDlsymAllocPoolSize];
 
 static INLINE bool IsInDlsymAllocPool(const void *ptr) {
   uptr off = (uptr)ptr - (uptr)alloc_memory_for_dlsym;
-  return off < sizeof(alloc_memory_for_dlsym);
+  return off < allocated_for_dlsym * sizeof(alloc_memory_for_dlsym[0]);
 }
 
 static void *AllocateFromLocalPool(uptr size_in_bytes) {