[LLVMdev] [PATCH] [Embtk] [compiler-rt] ASAN: Add mips support

Abdoulaye Walsimou Gaye awg at embtoolkit.org
Wed Feb 27 13:09:05 PST 2013


This simple patch makes asan compile for mips (tested on mips32r2el).
The following test code:
int main()
{
	char *x = (char*)malloc(10 * sizeof(char*));
	free(x);
	return x[5];
}

leads to the following output at runtime:
=================================================================
==267== ERROR: AddressSanitizer: heap-use-after-free on address 0x77900fd5 at pc 0x409e1c bp 0x7fb781d8 sp 0x7fb781f4
READ of size 1 at 0x77900fd5 thread T0
0x77900fd5 is located 5 bytes inside of 40-byte region [0x77900fd0,0x77900ff8)
freed by thread T0 here:
    #0 0x409eab (/root/test+0x409eab)
    #1 0x77ccd28b (+0x928b)
previously allocated by thread T0 here:
    #0 0x40a043 (/root/test+0x40a043)
    #1 0x77ccd28b (+0x728b)
Shadow bytes around the buggy address:
  0x2ef201a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x2ef201b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x2ef201c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x2ef201d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x2ef201e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x2ef201f0: fa fa fa fa fa fa fa fa fa fa[fd]fd fd fd fd fa
  0x2ef20200: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x2ef20210: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x2ef20220: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x2ef20230: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x2ef20240: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
  Addressable:           00
  Partially addressable: 01 02 03 04 05 06 07
  Heap left redzone:     fa
  Heap righ redzone:     fb
  Freed Heap region:     fd
  Stack left redzone:    f1
  Stack mid redzone:     f2
  Stack right redzone:   f3
  Stack partial redzone: f4
  Stack after return:    f5
  Stack use after scope: f8
  Global redzone:        f9
  Global init order:     f6
  Poisoned by user:      f7
  ASan internal:         fe
==267== ABORTING

Signed-off-by: Abdoulaye Walsimou Gaye <awg at embtoolkit.org>
---
 lib/asan/asan_linux.cc |    5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/asan/asan_linux.cc b/lib/asan/asan_linux.cc
index 845493d..417ecad 100644
--- a/lib/asan/asan_linux.cc
+++ b/lib/asan/asan_linux.cc
@@ -88,6 +88,11 @@ void GetPcSpBp(void *context, uptr *pc, uptr *sp, uptr *bp) {
   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
-- 
1.7.9.5




More information about the llvm-dev mailing list