Abdoulaye Walsimou Gaye
2013-Feb-27 21:09 UTC
[LLVMdev] [PATCH] [Embtk] [compiler-rt] ASAN: Add mips support
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
Dmitri Gribenko
2013-Feb-27 21:16 UTC
[LLVMdev] [PATCH] [Embtk] [compiler-rt] ASAN: Add mips support
On Wed, Feb 27, 2013 at 11:09 PM, Abdoulaye Walsimou Gaye <awg at embtoolkit.org> wrote:> 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]; > }It would help to enable compiler-rt tests on mips builders to ensure we don't regress. Dmitri -- main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/
Kostya Serebryany
2013-Feb-28 05:12 UTC
[LLVMdev] [PATCH] [Embtk] [compiler-rt] ASAN: Add mips support
Nice patch, thanks! Enabling the tests on mips builders is a good idea too; it could go separately. --kcc On Thu, Feb 28, 2013 at 1:16 AM, Dmitri Gribenko <gribozavr at gmail.com>wrote:> On Wed, Feb 27, 2013 at 11:09 PM, Abdoulaye Walsimou Gaye > <awg at embtoolkit.org> wrote: > > 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]; > > } > > It would help to enable compiler-rt tests on mips builders to ensure > we don't regress. > > Dmitri > > -- > main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if > (j){printf("%d\n",i);}}} /*Dmitri Gribenko <gribozavr at gmail.com>*/ > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20130228/fb1e9e3b/attachment.html>
Apparently Analagous Threads
- [LLVMdev] [PATCH] [Embtk] [compiler-rt] ASAN: Add mips support
- [LLVMdev] Running cross compiled binaries for ARM on gem5
- [LLVMdev] Running cross compiled binaries for ARM on gem5
- [LLVMdev] ARM c++ exceptions handling not working with clang/llvm-3.2?
- [LLVMdev] ARM c++ exceptions handling not working with clang/llvm-3.2?