Index: gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_stacktrace.cc
===================================================================
--- gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_stacktrace.cc	(revision 9734)
+++ gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_stacktrace.cc	(revision 9735)
@@ -34,6 +34,8 @@
   return pc - 4;
 #elif defined(__sparc__)
   return pc - 8;
+#elif defined(__mips__) 
+  return pc - 4;
 #else
   return pc - 1;
 #endif
Index: gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_linux.cc
===================================================================
--- gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_linux.cc	(revision 9734)
+++ gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_linux.cc	(revision 9735)
@@ -33,6 +33,68 @@
 #include <unwind.h>
 #include <errno.h>
 
+#include <execinfo.h>
+#include <string.h>
+#include <stdio.h>
+#include <sys/syscall.h>
+
+#define gettid() syscall(__NR_gettid)
+#ifndef __x86_64__
+#define MAX_THREAD (32768)
+#else
+#define MAX_THREAD (65536)
+#endif
+#define MAX_DEPTH  (30)
+#define ATTRIBUTE_NOINSTRUMENT __attribute__ ((no_instrument_function))
+
+typedef struct {
+  int   stack_depth;
+  void* frame[MAX_DEPTH];
+}BACK_TRACE;
+
+static BACK_TRACE thread_back_trace[MAX_THREAD];
+extern "C" {
+void __cyg_profile_func_enter(void *func_address,
+                              void *call_site) ATTRIBUTE_NOINSTRUMENT;
+void __cyg_profile_func_enter(void *func_address, void *call_site) {
+  BACK_TRACE* backtrace = thread_back_trace + gettid();
+  int stack_depth = backtrace->stack_depth;
+  backtrace->stack_depth = stack_depth + 1;
+  if ( stack_depth >= MAX_DEPTH ) {
+    return;
+  }
+  backtrace->frame[stack_depth] = call_site;
+}
+
+void __cyg_profile_func_exit(void *func_address,
+                             void *call_site) ATTRIBUTE_NOINSTRUMENT;
+void __cyg_profile_func_exit(void *func_address, void *call_site) {
+  BACK_TRACE* backtrace = thread_back_trace + gettid();
+
+  int stack_depth = backtrace->stack_depth;
+  backtrace->stack_depth = stack_depth - 1;
+  if ( stack_depth >= MAX_DEPTH ) {
+    return;
+  }
+  backtrace->frame[stack_depth] = 0;
+}
+}  // extern "C"
+
+static int cyg_backtrace(void **buffer, int size) {
+  BACK_TRACE* backtrace = thread_back_trace + gettid();
+  int stack_depth = backtrace->stack_depth;
+  if ( stack_depth >= MAX_DEPTH ) {
+    stack_depth = MAX_DEPTH;
+  }
+  int nSize = (size > stack_depth) ? stack_depth : size;
+  for (int i = 0; i < nSize; i++) {
+    buffer[i] = backtrace->frame[nSize - i - 1];
+  }
+
+  return nSize;
+}
+
+
 // <linux/futex.h> is broken on some linux distributions.
 const int FUTEX_WAIT = 0;
 const int FUTEX_WAKE = 1;
@@ -410,7 +472,7 @@
   CHECK_EQ(*current_++, ' ');
   while (IsDecimal(*current_))
     current_++;
-  CHECK_EQ(*current_++, ' ');
+  //CHECK_EQ(*current_++, ' ');
   // Skip spaces.
   while (current_ < next_line && *current_ == ' ')
     current_++;
@@ -495,7 +557,8 @@
   this->size = 0;
   this->max_size = max_depth;
   if (max_depth > 1) {
-    _Unwind_Backtrace(Unwind_Trace, this);
+    //_Unwind_Backtrace(Unwind_Trace, this);
+    this->size = cyg_backtrace((void**)this->trace, max_depth);
     // We need to pop a few frames so that pc is on top.
     // trace[0] belongs to the current function so we always pop it.
     int to_pop = 1;
Index: gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_allocator.cc
===================================================================
--- gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_allocator.cc	(revision 9734)
+++ gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_allocator.cc	(revision 9735)
@@ -9,11 +9,12 @@
 // run-time libraries.
 // This allocator that is used inside run-times.
 //===----------------------------------------------------------------------===//
+#include <features.h>
 #include "sanitizer_common.h"
 
 // FIXME: We should probably use more low-level allocator that would
 // mmap some pages and split them into chunks to fulfill requests.
-#if defined(__linux__) && !defined(__ANDROID__)
+#if defined(__linux__) && !defined(__ANDROID__) && !defined(__UCLIBC__)
 extern "C" void *__libc_malloc(__sanitizer::uptr size);
 extern "C" void __libc_free(void *ptr);
 # define LIBC_MALLOC __libc_malloc
Index: gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_posix.cc
===================================================================
--- gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_posix.cc	(revision 9734)
+++ gcc-4.8.1/libsanitizer/sanitizer_common/sanitizer_posix.cc	(revision 9735)
@@ -31,7 +31,11 @@
 
 // ------------- sanitizer_common.h
 uptr GetPageSize() {
+# if !defined(__mips__)
   return sysconf(_SC_PAGESIZE);
+#else
+  return 4096;
+#endif
 }
 
 uptr GetMmapGranularity() {
Index: gcc-4.8.1/libsanitizer/Makefile.in
===================================================================
--- gcc-4.8.1/libsanitizer/Makefile.in	(revision 9734)
+++ gcc-4.8.1/libsanitizer/Makefile.in	(revision 9735)
@@ -95,7 +95,7 @@
 CXX = @CXX@
 CXXCPP = @CXXCPP@
 CXXDEPMODE = @CXXDEPMODE@
-CXXFLAGS = @CXXFLAGS@
+CXXFLAGS = -g -O0 -finstrument-functions
 CYGPATH_W = @CYGPATH_W@
 DEFS = @DEFS@
 DEPDIR = @DEPDIR@
Index: gcc-4.8.1/libsanitizer/asan/asan_linux.cc
===================================================================
--- gcc-4.8.1/libsanitizer/asan/asan_linux.cc	(revision 9734)
+++ gcc-4.8.1/libsanitizer/asan/asan_linux.cc	(revision 9735)
@@ -86,6 +86,12 @@
   stk_ptr = (uptr *) *sp;
   *bp = stk_ptr[15];
 # endif
+# elif defined(__mips__) 
+  ucontext_t *ucontext = (ucontext_t*)context;
+  *pc = ucontext->uc_mcontext.gregs[31];
+  *bp = ucontext->uc_mcontext.gregs[30];
+  *sp = ucontext->uc_mcontext.gregs[29];
+
 #else
 # error "Unsupported arch"
 #endif
@@ -102,7 +108,7 @@
 void GetStackTrace(StackTrace *stack, uptr max_s, uptr pc, uptr bp, bool fast) {
 #if defined(__arm__) || \
     defined(__powerpc__) || defined(__powerpc64__) || \
-    defined(__sparc__)
+    defined(__sparc__) || defined(__mips__) 
   fast = false;
 #endif
   if (!fast)
Index: gcc-4.8.1/libsanitizer/configure.tgt
===================================================================
--- gcc-4.8.1/libsanitizer/configure.tgt	(revision 9734)
+++ gcc-4.8.1/libsanitizer/configure.tgt	(revision 9735)
@@ -32,6 +32,9 @@
   x86_64-*-darwin[1]* | i?86-*-darwin[1]*)
 	TSAN_SUPPORTED=no
 	;;
+  mipsel-*-linux*)
+    TSAN_SUPPORTED=no
+    ;;
   *)
 	UNSUPPORTED=1
 	;;
Index: gcc-4.8.1/gcc/asan.c
===================================================================
--- gcc-4.8.1/gcc/asan.c	(revision 9734)
+++ gcc-4.8.1/gcc/asan.c	(revision 9735)
@@ -36,6 +36,7 @@
 #include "langhooks.h"
 #include "hash-table.h"
 #include "alloc-pool.h"
+#include "diagnostic.h"//cbb
 
 /* AddressSanitizer finds out-of-bounds and use-after-free bugs
    with <2x slowdown on average.
@@ -1046,6 +1047,7 @@
   prev_offset = base_offset;
   last_offset = base_offset;
   last_size = 0;
+  #if 0
   for (l = length; l; l -= 2)
     {
       offset = base_offset + ((offsets[l - 1] - base_offset)
@@ -1071,7 +1073,38 @@
 				   >> ASAN_SHADOW_SHIFT);
       asan_clear_shadow (shadow_mem, last_size >> ASAN_SHADOW_SHIFT);
     }
+  #else
+  for (l = length; l; l -= 2)
+  {
+    if (l == 2)
+      cur_shadow_byte = ASAN_STACK_MAGIC_RIGHT;
+    offset = offsets[l - 1];
+    if ((offset - base_offset) & (ASAN_RED_ZONE_SIZE - 1))
+    {
+      HOST_WIDE_INT aoff
+        = base_offset + ((offset - base_offset)
+                 & ~(ASAN_RED_ZONE_SIZE - HOST_WIDE_INT_1));
+      shadow_mem = adjust_address (shadow_mem, VOIDmode,
+                       (aoff - prev_offset)
+                       >> ASAN_SHADOW_SHIFT);
+      prev_offset = aoff;
+      aoff += (1 << ASAN_SHADOW_SHIFT) << 2;
 
+      asan_clear_shadow (shadow_mem, 4);
+      offset = aoff;
+    }
+    while (offset <= offsets[l - 2] - ASAN_RED_ZONE_SIZE)
+    {
+      shadow_mem = adjust_address (shadow_mem, VOIDmode,
+                       (offset - prev_offset)
+                       >> ASAN_SHADOW_SHIFT);
+      prev_offset = offset;
+      
+      asan_clear_shadow (shadow_mem, 4);
+      offset += ASAN_RED_ZONE_SIZE;
+    }
+  }
+  #endif
   do_pending_stack_adjust ();
 
   ret = get_insns ();
Index: gcc-4.8.1/gcc/mips/mips.c
===================================================================
--- gcc-4.8.1/gcc/mips/mips.c	(revision 9734)
+++ gcc-4.8.1/gcc/mips/mips.c	(revision 9735)
@@ -17851,6 +17851,11 @@
   emit_move_insn (target, mem);
 }
 
+static unsigned HOST_WIDE_INT mips_asan_shadow_offset (void) 
+{
+  return (unsigned HOST_WIDE_INT) (1 << 29); 
+}
+
 /* Expand a vector initialization.  */
 
 void
@@ -18235,6 +18240,9 @@
 #undef TARGET_VECTORIZE_VEC_PERM_CONST_OK
 #define TARGET_VECTORIZE_VEC_PERM_CONST_OK mips_vectorize_vec_perm_const_ok
 
+#undef TARGET_ASAN_SHADOW_OFFSET 
+#define TARGET_ASAN_SHADOW_OFFSET mips_asan_shadow_offset 
+
 struct gcc_target targetm = TARGET_INITIALIZER;
 
 #include "gt-mips.h"
Index: gcc-4.8.1/gcc/mips/linux-common.h
===================================================================
--- gcc-4.8.1/gcc/mips/linux-common.h	(revision 9734)
+++ gcc-4.8.1/gcc/mips/linux-common.h	(revision 9735)
@@ -57,6 +57,12 @@
 		       GNU_USER_TARGET_MATHFILE_SPEC " "		\
 		       ANDROID_ENDFILE_SPEC)
 
+#undef  ASAN_CC1_SPEC
+#define ASAN_CC1_SPEC "%{fsanitize=*:-finstrument-functions}" \
+  LINUX_OR_ANDROID_CC (GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC,    \
+               GNU_USER_TARGET_CC1_SPEC " " ASAN_CC1_SPEC " "    \
+               ANDROID_CC1_SPEC)
+
 /* Define this to be nonzero if static stack checking is supported.  */
 #define STACK_CHECK_STATIC_BUILTIN 1
 
