diff options
| -rw-r--r-- | compiler-rt/lib/asan/asan_allocator.cc | 8 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_interceptors.cc | 9 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_internal.h | 4 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_mac.cc | 2 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_poisoning.cc | 10 | ||||
| -rw-r--r-- | compiler-rt/lib/asan/asan_rtl.cc | 7 |
6 files changed, 18 insertions, 22 deletions
diff --git a/compiler-rt/lib/asan/asan_allocator.cc b/compiler-rt/lib/asan/asan_allocator.cc index 0ba5ca5b2cb..0cd49057616 100644 --- a/compiler-rt/lib/asan/asan_allocator.cc +++ b/compiler-rt/lib/asan/asan_allocator.cc @@ -39,7 +39,6 @@ #include <stdint.h> #include <string.h> #include <unistd.h> -#include <algorithm> namespace __asan { @@ -506,7 +505,7 @@ class MallocInfo { 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 @@ static uint8_t *Allocate(size_t alignment, size_t size, AsanStackTrace *stack) { 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 @@ static uint8_t *Reallocate(uint8_t *old_ptr, size_t new_size, 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 @@ void __asan_stack_free(size_t ptr, size_t size, size_t real_stack) { // 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) { diff --git a/compiler-rt/lib/asan/asan_interceptors.cc b/compiler-rt/lib/asan/asan_interceptors.cc index 9ad6ddaf214..64c83820b4a 100644 --- a/compiler-rt/lib/asan/asan_interceptors.cc +++ b/compiler-rt/lib/asan/asan_interceptors.cc @@ -20,7 +20,6 @@ #include "asan_stack.h" #include "asan_stats.h" -#include <algorithm> #include <dlfcn.h> #include <string.h> @@ -276,15 +275,15 @@ int WRAP(strncmp)(const char *s1, const char *s2, size_t size) { 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 @@ size_t WRAP(strnlen)(const char *s, size_t maxlen) { 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; } diff --git a/compiler-rt/lib/asan/asan_internal.h b/compiler-rt/lib/asan/asan_internal.h index 89b9e204fbb..c722feb7b42 100644 --- a/compiler-rt/lib/asan/asan_internal.h +++ b/compiler-rt/lib/asan/asan_internal.h @@ -72,6 +72,10 @@ int SNPrint(char *buffer, size_t length, const char *format, ...); 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); diff --git a/compiler-rt/lib/asan/asan_mac.cc b/compiler-rt/lib/asan/asan_mac.cc index 0084fb75955..c0e57439f15 100644 --- a/compiler-rt/lib/asan/asan_mac.cc +++ b/compiler-rt/lib/asan/asan_mac.cc @@ -21,8 +21,6 @@ #include "asan_thread.h" #include "asan_thread_registry.h" -#include <algorithm> - #include <sys/mman.h> #include <unistd.h> diff --git a/compiler-rt/lib/asan/asan_poisoning.cc b/compiler-rt/lib/asan/asan_poisoning.cc index 06811053c38..daa1ad68e46 100644 --- a/compiler-rt/lib/asan/asan_poisoning.cc +++ b/compiler-rt/lib/asan/asan_poisoning.cc @@ -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 @@ void __asan_poison_memory_region(void const volatile *addr, size_t size) { // 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 @@ void __asan_poison_memory_region(void const volatile *addr, size_t size) { 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 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size) { // 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 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size) { } 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); } } diff --git a/compiler-rt/lib/asan/asan_rtl.cc b/compiler-rt/lib/asan/asan_rtl.cc index 7fb3b92b0b0..5518641a67d 100644 --- a/compiler-rt/lib/asan/asan_rtl.cc +++ b/compiler-rt/lib/asan/asan_rtl.cc @@ -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 @@ static bool DescribeStackAddress(uintptr_t addr, uintptr_t access_size) { 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 @@ static bool DescribeStackAddress(uintptr_t addr, uintptr_t access_size) { } 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); } |

