Hi Park, *Following are the steps for building LLVM and compiler-rt for target MIPS (Host=x86, Target=MIPS):*
1. Install prerequisites with "sudo apt-get install cmake ninja-build gcc-5-mipsel-linux-gnu g++-5-mipsel-linux-gnu gcc-5-multilib-mipsel-linux-gnu g++-5-multilib-mipsel-linux-gnu binutils-mipsel-linux-gnu libgcc1-mipsel-cross libstdc++6-mipsel-cross" 2. Checkout llvm. 3. Checkout clang in /llvm/tools/ 4. Build LLVM cross compiler which targets MIPS. 1. Run "cmake -G Ninja ../llvm -DCMAKE_INSTALL_PREFIX=<path-to-install-dir> -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=<install-dir> -DLLVM_DEFAULT_TARGET_TRIPLE=mipsel-linux-gnu -DLLVM_TARGET_ARCH=Mips -DLLVM_TARGETS_TO_BUILD=Mips" in a build directory. 2. Run "ninja; ninja install" 5. Checkout compiler-rt 6. Build compiler-rt in a separate build directory using the just built llvm cross compiler. 1. Run "cmake -G Ninja ../compiler-rt/ -DCMAKE_C_COMPILER=<path-to-where-llvm-was-installed>/bin/clang -DCMAKE_CXX_COMPILER=<path-to-where-llvm-was-installed>/bin/clang++ -DCMAKE_BUILD_TYPE=Release -DLLVM_CONFIG_PATH=<path-to-where-llvm-was-installed>//bin/llvm-config -DCOMPILER_RT_INSTALL_PATH=<path-to-where-llvm-was-installed>//lib/clang/4.0.0 -DCMAKE_C_FLAGS="-I/usr/mipsel-linux-gnu/include/ -Wl,-L/usr/mipsel-linux-gnu/lib/" -DCMAKE_CXX_FLAGS="-I/usr/mipsel-linux-gnu/include/ -Wl,-L/usr/mipsel-linux-gnu/lib/"" in a separate build directory. 2. Run "ninja; ninja install" You can also use the GCC cross tool chain instead of the just built LLVM cross tool chain to build the compiler-rt sources. *Running a simple test from the ASAN test suite:* $ <path-to-where-llvm-was-installed>/bin/clang -fsanitize=address -Wl,--dynamic-linker=/usr/mipsel-linux-gnu/lib/ld.so.1 use-after-free.cc $ qemu-mipsel -cpu 74Kf -E LD_LIBRARY_PATH=/usr/mipsel-linux-gnu/lib/ a.out ================================================================= ==1487==ERROR: AddressSanitizer: heap-use-after-free on address 0x74d007b5 at pc 0x0052d518 bp 0x76fff5c0 sp 0x76fff5e4 READ of size 1 at 0x74d007b5 thread T0 #0 0x52d510 (/home/slt/Tests/a.out+0x52d510) #1 0x76535bd4 (/usr/mipsel-linux-gnu/lib/libc.so.6+0x19bd4) 0x74d007b5 is located 5 bytes inside of 10-byte region [0x74d007b0,0x74d007ba) freed by thread T0 here: #0 0x4f4124 (/home/slt/Tests/a.out+0x4f4124) #1 0x52d4a8 (/home/slt/Tests/a.out+0x52d4a8) #2 0x76535bd4 (/usr/mipsel-linux-gnu/lib/libc.so.6+0x19bd4) previously allocated by thread T0 here: #0 0x4f4580 (/home/slt/Tests/a.out+0x4f4580) #1 0x52d498 (/home/slt/Tests/a.out+0x52d498) #2 0x76535bd4 (/usr/mipsel-linux-gnu/lib/libc.so.6+0x19bd4) SUMMARY: AddressSanitizer: heap-use-after-free (/home/slt/Tests/a.out+0x52d510) Shadow bytes around the buggy address: 0x194400a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x194400b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x194400c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x194400d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x194400e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa =>0x194400f0: fa fa fa fa fa fa[fd]fd fa fa fa fa fa fa fa fa 0x19440100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x19440110: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x19440120: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x19440130: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa 0x19440140: 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 Freed heap region: fd Stack left redzone: f1 Stack mid redzone: f2 Stack right redzone: f3 Stack after return: f5 Stack use after scope: f8 Global redzone: f9 Global init order: f6 Poisoned by user: f7 Container overflow: fc Array cookie: ac Intra object redzone: bb ASan internal: fe Left alloca redzone: ca Right alloca redzone: cb ==1487==ABORTING *To cross build a complete LLVM toolchain which will run on MIPS and target to MIPS **(Host=MIPS, Target=MIPS):* 1. Install prerequisites with "sudo apt-get install cmake ninja-build gcc-5-mipsel-linux-gnu g++-5-mipsel-linux-gnu gcc-5-multilib-mipsel-linux-gnu g++-5-multilib-mipsel-linux-gnu binutils-mipsel-linux-gnu libgcc1-mipsel-cross libstdc++6-mipsel-cross" 2. Checkout llvm 3. Checkout clang in /llvm/tools/ 4. Checkout compiler-rt in /llvm/projects/ 5. Run "cmake -G Ninja ../llvm -DCMAKE_INSTALL_PREFIX=<path-to-install-dir> -DCMAKE_BUILD_TYPE=Release -DCMAKE_CROSSCOMPILING=True -DLLVM_TABLEGEN=<path-to-host-bin>/llvm-tblgen -DCLANG_TABLEGEN=<path-to-host-bin>/clang-tblgen -DLLVM_HOST_TRIPLE=mipsel-linux-gnu -DLLVM_DEFAULT_TARGET_TRIPLE=mipsel-linux-gnu -DLLVM_TARGET_ARCH=Mips -DLLVM_TARGETS_TO_BUILD=Mips -DCMAKE_C_COMPILER="/usr/bin/mipsel-linux-gnu-gcc-5" -DCMAKE_CXX_COMPILER="/usr/bin/mipsel-linux-gnu-g++-5" -DCMAKE_ASM_COMPILER="/usr/bin/mipsel-linux-gnu-gcc-5" -DCMAKE_C_FLAGS="-mips32 -mabi=32" -DCMAKE_CXX_FLAGS="-mips32 -mabi=32"" in a build directory. 6. Run "ninja; ninja install" But "ninja install" does not copy the sanitizer runtime libs in the install directory. So you will have to copy them to the install directory manually. Regarding GCC's ASAN support for MIPS, as Maxim said we will have to add support for it following the steps he mentioned. Regards, Sagar On Wednesday, November 16, 2016 at 1:13:06 PM UTC+5:30, Park Kit wrote: > > Hi Sagar, > > Many thanks for a reply. Although I am seeking to have GCC cross compile > working, it would be great to know that ASAN builds for mips on clang. > > Looking forward to good news on that. > > Many thanks > Kit > > 2016년 11월 15일 화요일 오후 6시 56분 48초 UTC, sagar....@imgtec.com 님의 말: >> >> Hi Park, >> >> Sorry for the delay. >> >> In order to run ASAN on mips, we always did a native build of compiler-rt >> on a real mips hardware. We never tried the cross build of compiler-rt. >> >> However, since you need the cross build, I will give it a try and get >> back to you as soon as I get success. >> >> Regards, >> Sagar >> >> On Tuesday, November 15, 2016 at 1:59:15 PM UTC+5:30, Park Kit wrote: >>> >>> Hi all, >>> >>> Could anyone please give me some pointers to try? >>> >>> 2016년 10월 15일 토요일 오전 1시 21분 6초 UTC+1, kcc 님의 말: >>>> >>>> Sagar, Simon, >>>> Could you please consult on ASAN for MIPS? >>>> >>>> On Fri, Oct 14, 2016 at 3:04 PM, Park Kit <keite...@gmail.com> wrote: >>>> >>>>> Correction. ASN means ASAN of course. :-) >>>>> >>>>> -- >>>>> You received this message because you are subscribed to the Google >>>>> Groups "address-sanitizer" group. >>>>> To unsubscribe from this group and stop receiving emails from it, send >>>>> an email to address-saniti...@googlegroups.com. >>>>> For more options, visit https://groups.google.com/d/optout. >>>>> >>>> >>>> -- You received this message because you are subscribed to the Google Groups "address-sanitizer" group. To unsubscribe from this group and stop receiving emails from it, send an email to address-sanitizer+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.