tsan/asan: kill STL
First, placement new from standard library conflicts with our own.
Second, we are in trouble if user uses the same function (we either get instrumented code in runtime, or non-instrumented code in user program).



git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@159738 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/sanitizer_common/sanitizer_common.cc b/lib/sanitizer_common/sanitizer_common.cc
index a2c3c3f..b3e16b4 100644
--- a/lib/sanitizer_common/sanitizer_common.cc
+++ b/lib/sanitizer_common/sanitizer_common.cc
@@ -13,10 +13,7 @@
 
 #include "sanitizer_common.h"
 #include "sanitizer_libc.h"
-
-// Should not add dependency on libstdc++,
-// since most of the stuff here is inlinable.
-#include <algorithm>
+#include <stdlib.h>
 
 namespace __sanitizer {
 
@@ -60,8 +57,19 @@
   return read_len;
 }
 
+static int comp(const void *p1, const void *p2) {
+  uptr v1 = *(uptr*)p1;
+  uptr v2 = *(uptr*)p2;
+  if (v1 < v2)
+    return -1;
+  else if (v1 > v2)
+    return 1;
+  else
+    return 0;
+}
+
 void SortArray(uptr *array, uptr size) {
-  std::sort(array, array + size);
+  qsort(array, size, sizeof(array[0]), &comp);
 }
 
 }  // namespace __sanitizer