[llvm-commits] [compiler-rt] r145691 - in /compiler-rt/trunk/lib/asan: asan_allocator.cc asan_interceptors.cc asan_internal.h asan_mac.cc asan_poisoning.cc asan_rtl.cc

Kostya Serebryany kcc at google.com
Fri Dec 2 10:42:04 PST 2011


Author: kcc
Date: Fri Dec  2 12:42:04 2011
New Revision: 145691

URL: http://llvm.org/viewvc/llvm-project?rev=145691&view=rev
Log:
[asan] minimize the use of STL. One bit is still left.

Modified:
    compiler-rt/trunk/lib/asan/asan_allocator.cc
    compiler-rt/trunk/lib/asan/asan_interceptors.cc
    compiler-rt/trunk/lib/asan/asan_internal.h
    compiler-rt/trunk/lib/asan/asan_mac.cc
    compiler-rt/trunk/lib/asan/asan_poisoning.cc
    compiler-rt/trunk/lib/asan/asan_rtl.cc

Modified: compiler-rt/trunk/lib/asan/asan_allocator.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_allocator.cc?rev=145691&r1=145690&r2=145691&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_allocator.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_allocator.cc Fri Dec  2 12:42:04 2011
@@ -39,7 +39,6 @@
 #include <stdint.h>
 #include <string.h>
 #include <unistd.h>
-#include <algorithm>
 
 namespace __asan {
 
@@ -506,7 +505,7 @@
     size_t size = SizeClassToSize(size_class);
     CHECK(IsPowerOfTwo(kMinMmapSize));
     CHECK(size < kMinMmapSize || (size % kMinMmapSize) == 0);
-    size_t mmap_size = std::max(size, kMinMmapSize);
+    size_t mmap_size = Max(size, kMinMmapSize);
     size_t n_chunks = mmap_size / size;
     CHECK(n_chunks * size == mmap_size);
     if (size < kPageSize) {
@@ -643,7 +642,6 @@
     AsanChunk **fl = &t->malloc_storage().free_lists_[size_class];
     if (!*fl) {
       size_t n_new_chunks = kMaxSizeForThreadLocalFreeList / size_to_allocate;
-      // n_new_chunks = std::min((size_t)32, n_new_chunks);
       *fl = malloc_info.AllocateChunks(size_class, n_new_chunks);
       if (FLAG_stats) {
         thread_stats.malloc_small_slow++;
@@ -749,7 +747,7 @@
   AsanChunk *m = PtrToChunk((uintptr_t)old_ptr);
   CHECK(m->chunk_state == CHUNK_ALLOCATED);
   size_t old_size = m->used_size;
-  size_t memcpy_size = std::min(new_size, old_size);
+  size_t memcpy_size = Min(new_size, old_size);
   uint8_t *new_ptr = Allocate(0, new_size, stack);
   if (new_ptr) {
     real_memcpy(new_ptr, old_ptr, memcpy_size);
@@ -1034,7 +1032,7 @@
 // just return "size".
 size_t __asan_get_estimated_allocated_size(size_t size) {
   if (size == 0) return 1;
-  return std::min(size, kMaxAllowedMallocSize);
+  return Min(size, kMaxAllowedMallocSize);
 }
 
 bool __asan_get_ownership(const void *p) {

Modified: compiler-rt/trunk/lib/asan/asan_interceptors.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_interceptors.cc?rev=145691&r1=145690&r2=145691&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_interceptors.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_interceptors.cc Fri Dec  2 12:42:04 2011
@@ -20,7 +20,6 @@
 #include "asan_stack.h"
 #include "asan_stats.h"
 
-#include <algorithm>
 #include <dlfcn.h>
 #include <string.h>
 
@@ -276,15 +275,15 @@
     c2 = (unsigned char)s2[i];
     if (c1 != c2 || c1 == '\0') break;
   }
-  ASAN_READ_RANGE(s1, std::min(i + 1, size));
-  ASAN_READ_RANGE(s2, std::min(i + 1, size));
+  ASAN_READ_RANGE(s1, Min(i + 1, size));
+  ASAN_READ_RANGE(s2, Min(i + 1, size));
   return CharCmp(c1, c2);
 }
 
 char *WRAP(strncpy)(char *to, const char *from, size_t size) {
   ensure_asan_inited();
   if (FLAG_replace_str) {
-    size_t from_size = std::min(size, internal_strnlen(from, size) + 1);
+    size_t from_size = Min(size, internal_strnlen(from, size) + 1);
     CHECK_RANGES_OVERLAP(to, from, from_size);
     ASAN_READ_RANGE(from, from_size);
     ASAN_WRITE_RANGE(to, size);
@@ -297,7 +296,7 @@
   ensure_asan_inited();
   size_t length = real_strnlen(s, maxlen);
   if (FLAG_replace_str) {
-    ASAN_READ_RANGE(s, std::min(length + 1, maxlen));
+    ASAN_READ_RANGE(s, Min(length + 1, maxlen));
   }
   return length;
 }

Modified: compiler-rt/trunk/lib/asan/asan_internal.h
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_internal.h?rev=145691&r1=145690&r2=145691&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_internal.h (original)
+++ compiler-rt/trunk/lib/asan/asan_internal.h Fri Dec  2 12:42:04 2011
@@ -72,6 +72,10 @@
 void Printf(const char *format, ...);
 void Report(const char *format, ...);
 
+// Don't use std::min and std::max, to minimize dependency on libstdc++.
+template<class T> T Min(T a, T b) { return a < b ? a : b; }
+template<class T> T Max(T a, T b) { return a > b ? a : b; }
+
 // asan_poisoning.cc
 // Poisons the shadow memory for "size" bytes starting from "addr".
 void PoisonShadow(uintptr_t addr, size_t size, uint8_t value);

Modified: compiler-rt/trunk/lib/asan/asan_mac.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_mac.cc?rev=145691&r1=145690&r2=145691&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_mac.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_mac.cc Fri Dec  2 12:42:04 2011
@@ -21,8 +21,6 @@
 #include "asan_thread.h"
 #include "asan_thread_registry.h"
 
-#include <algorithm>
-
 #include <sys/mman.h>
 #include <unistd.h>
 

Modified: compiler-rt/trunk/lib/asan/asan_poisoning.cc
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/asan/asan_poisoning.cc?rev=145691&r1=145690&r2=145691&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_poisoning.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_poisoning.cc Fri Dec  2 12:42:04 2011
@@ -17,8 +17,6 @@
 #include "asan_internal.h"
 #include "asan_mapping.h"
 
-#include <algorithm>
-
 namespace __asan {
 
 void PoisonShadow(uintptr_t addr, size_t size, uint8_t value) {
@@ -92,7 +90,7 @@
     // No need to re-poison memory if it is poisoned already.
     if (value > 0 && value <= end.offset) {
       if (beg.offset > 0) {
-        *beg.chunk = std::min(value, beg.offset);
+        *beg.chunk = Min(value, beg.offset);
       } else {
         *beg.chunk = kAsanUserPoisonedMemoryMagic;
       }
@@ -105,7 +103,7 @@
     if (beg.value == 0) {
       *beg.chunk = beg.offset;
     } else {
-      *beg.chunk = std::min(beg.value, beg.offset);
+      *beg.chunk = Min(beg.value, beg.offset);
     }
     beg.chunk++;
   }
@@ -132,7 +130,7 @@
     // We unpoison memory bytes up to enbytes up to end.offset if it is not
     // unpoisoned already.
     if (value != 0) {
-      *beg.chunk = std::max(value, end.offset);
+      *beg.chunk = Max(value, end.offset);
     }
     return;
   }
@@ -143,7 +141,7 @@
   }
   real_memset(beg.chunk, 0, end.chunk - beg.chunk);
   if (end.offset > 0 && end.value != 0) {
-    *end.chunk = std::max(end.value, end.offset);
+    *end.chunk = Max(end.value, end.offset);
   }
 }
 

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=145691&r1=145690&r2=145691&view=diff
==============================================================================
--- compiler-rt/trunk/lib/asan/asan_rtl.cc (original)
+++ compiler-rt/trunk/lib/asan/asan_rtl.cc Fri Dec  2 12:42:04 2011
@@ -25,8 +25,7 @@
 #include "asan_thread.h"
 #include "asan_thread_registry.h"
 
-#include <algorithm>
-#include <map>
+#include <new>
 #include <dlfcn.h>
 #include <execinfo.h>
 #include <fcntl.h>
@@ -192,7 +191,7 @@
   CHECK(name_end);
   buf[0] = 0;
   strncat(buf, frame_descr,
-          std::min(kBufSize, static_cast<intptr_t>(name_end - frame_descr)));
+          Min(kBufSize, static_cast<intptr_t>(name_end - frame_descr)));
   Printf("Address %p is located at offset %ld "
          "in frame <%s> of T%d's stack:\n",
          addr, offset, buf, t->tid());
@@ -215,7 +214,7 @@
     }
     p++;
     buf[0] = 0;
-    strncat(buf, p, std::min(kBufSize, len));
+    strncat(buf, p, Min(kBufSize, len));
     p += len;
     Printf("    [%ld, %ld) '%s'\n", beg, beg + size, buf);
   }





More information about the llvm-commits mailing list