ASN for MIPS with either clang or gcc

788 views
Skip to first unread message

Park Kit

unread,
Oct 14, 2016, 5:28:06 PM10/14/16
to address-sanitizer
Hello groups,

I am new to ASN and sorry for my little knowledge around this if it's simple thing to do. I am trying to build ASN for mips target with either clang or gcc and both fails to build.

ASN says:

"The tool works on x86, ARM, MIPS (both 32- and 64-bit versions of all
architectures), PowerPC64. The supported operation systems are Linux,
Darwin (OS X and iOS Simulator), FreeBSD, Android."

So tried:

1. ASN build for x86 with clang
Followed https://github.com/google/sanitizers/wiki/AddressSanitizerHowToBuild and this builds for X86 fine and works.

2. ASN build for MIPS with clang
To build it for cross compile, built MIPS gcc and followed http://llvm.org/docs/HowToCrossCompileLLVM.html but build fails at configuration stage.

3. ASN build for x86 with gcc(4.9.2)
Used buildroot to build MIPS cross toolchain and builds fine and works.

4. ASN build for MIPS with gcc
Surely ASN in gcc do not support MIPS target when see gcc configuration so made few tweaks to set MIPS target. Configuration step works fine but build fails.

Since I don't see ASN for MIPS yet, couple of question on direction to go:

1. Is it possible to build ASN for MIPS with gcc source package if make some changes to configuration/sources to gcc or ASN?

2. Or should I have to post ASN from clang back to gcc to build it for MIPS?

Have had some search to find a solution, success story or MIPS port but no success. Could anyone who have already gone through or done that please help me to build ASN for MIPS?
Any help or advise will be greatly appreciated.

Many thanks
Kit

Park Kit

unread,
Oct 14, 2016, 6:04:49 PM10/14/16
to address-sanitizer
Correction. ASN means ASAN of course. :-)

Konstantin Serebryany

unread,
Oct 14, 2016, 8:21:06 PM10/14/16
to address-sanitizer, sagar....@imgtec.com, simon....@imgtec.com
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-sanitizer+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Park Kit

unread,
Nov 15, 2016, 3:29:15 AM11/15/16
to address-sanitizer, sagar....@imgtec.com, simon....@imgtec.com
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.

sagar....@imgtec.com

unread,
Nov 15, 2016, 1:56:48 PM11/15/16
to address-sanitizer, sagar....@imgtec.com, simon....@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

Park Kit

unread,
Nov 16, 2016, 2:43:06 AM11/16/16
to address-sanitizer, sagar....@imgtec.com, simon....@imgtec.com
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 님의 말:

Maxim Ostapenko

unread,
Nov 16, 2016, 2:55:40 AM11/16/16
to address-sanitizer, sagar....@imgtec.com, simon....@imgtec.com
Hi,

среда, 16 ноября 2016 г., 10:43:06 UTC+3 пользователь Park Kit написал:
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.


AFAIK current GCC doesn't support MIPS, but IMHO it would be quite trivial to support it now because the runtime part already supports it. All you need is:

1) Define TARGET_ASAN_SHADOW_OFFSET somewhere in gcc/config/mips/mips.c. You can see an example how to do this in gcc/config/arm/arm.c.
2) Add mips*-*-linux* (or whatever triplet you use) entry in libsanitizer/configure.tgt. This should enable libsanitizer build for MIPS.
3) If you succeed you can upstream this change though.

Hope it helps you.

-Maxim

sagar....@imgtec.com

unread,
Nov 19, 2016, 6:19:34 AM11/19/16
to address-sanitizer, sagar....@imgtec.com, simon....@imgtec.com
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

Park Kit

unread,
Nov 22, 2016, 9:48:21 AM11/22/16
to address-sanitizer, sagar....@imgtec.com, simon....@imgtec.com, chef...@gmail.com
Hi Sagar, Maxim,

Appreciated for your try and comments.

@Sagar, your steps are bit different from what I followed so will give it a try to build. This confirms at least ASAN works for cross-compile on MIPS and which is great.

@Maxim, you're right on 2) and that's what I did. Have you used the buildroot to build cross-compile GCC on MIPS or used GCC package only? What version have you used? Would you mind showing command lines to configure and to build it?

Keep you posted on further tries. Many thanks
Kit

2016년 11월 19일 토요일 오전 11시 19분 34초 UTC, sagar....@imgtec.com 님의 말:

Maxim Ostapenko

unread,
Nov 24, 2016, 2:59:59 AM11/24/16
to address-sanitizer, sagar....@imgtec.com, simon....@imgtec.com, chef...@gmail.com
Hi,

вторник, 22 ноября 2016 г., 17:48:21 UTC+3 пользователь Park Kit написал:
Hi Sagar, Maxim,

Appreciated for your try and comments.

@Sagar, your steps are bit different from what I followed so will give it a try to build. This confirms at least ASAN works for cross-compile on MIPS and which is great.

@Maxim, you're right on 2) and that's what I did. Have you used the buildroot to build cross-compile GCC on MIPS or used GCC package only? What version have you used? Would you mind showing command lines to configure and to build it?

Yes, I've used cross buildroot. It can be quite simply built manually, I've used this pretty nice instruction: http://preshing.com/20141119/how-to-build-a-gcc-cross-compiler/.
The components I used:
* current trunk GCC
* current trunk binutils 
* current trunk Linux headers
* Glibc 2.20

The only difference I've needed is a local patch for Glibc (I used 2.20) to fix build error (the patch is attached).

I'm also attaching the patch I used to enable ASan in GCC for MIPS (you can apply it on step 7).

Once you've built toolchain, you can simple test:

$ mips-linux-gcc -fsanitize=address  <gcc_tree_location>/gcc/testsuite/c-c++-common/asan/heap-overflow-1.c -fstack-protector
$ qemu-mips -L $SYSROOT -R 0 ./a.out 

=================================================================
==9453==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x42c007ba at pc 0x00400a94 bp 0x407ffca0 sp 0x407ffcc8
READ of size 1 at 0x42c007ba thread T0
    #0 0x400a8c  (/home/max/build/mips/gcc/a.out+0x400a8c)
    #1 0x40e5a36c  (/opt/cross/mips//mips-linux/lib/libc.so.6+0x1936c)

0x42c007ba is located 0 bytes to the right of 10-byte region [0x42c007b0,0x42c007ba)
allocated by thread T0 here:
    #0 0x4093fe9c  (/opt/cross/mips//mips-linux/lib/libasan.so.4+0x107e9c)
    #1 0x4009e4  (/home/max/build/mips/gcc/a.out+0x4009e4)
    #2 0x40e5a36c  (/opt/cross/mips//mips-linux/lib/libc.so.6+0x1936c)

SUMMARY: AddressSanitizer: heap-buffer-overflow (/home/max/build/mips/gcc/a.out+0x400a8c) 
Shadow bytes around the buggy address:
  0x130200a0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x130200b0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x130200c0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x130200d0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x130200e0: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
=>0x130200f0: fa fa fa fa fa fa 00[02]fa fa fa fa fa fa fa fa
  0x13020100: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x13020110: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x13020120: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x13020130: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
  0x13020140: 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
==9453==ABORTING

Note that I've added  -fstack-protector flag to avoid "cc1: warning: -fsanitize=address and -fsanitize=kernel-address are not supported for this target" error on compilation step. This is weird, but for some reason GCC folks use this flag to control FRAME_GROWS_DOWNWARD macro om MIPS.
GCC's ASan doesn't support targets with FRAME_GROWS_DOWNWARD == 0 so I just added -fstack-protector as a workaround.
gcc-asan-mips.diff
glibc-mips.diff

Park Kit

unread,
Nov 25, 2016, 11:23:43 AM11/25/16
to address-...@googlegroups.com, sagar....@imgtec.com, simon....@imgtec.com, chef...@gmail.com
Hi Maxim,

Really appreciated for the link which works for me when follows exactly. However, I am seeing two differences from you when trying to build ASAN:

1. Used the same glibc version but no error on a machine I use.
2. When either use a libsanitizer/configure.tgt tweak or --enable-libsanitizer, "make all-gcc" doesn't build "libsanitizer".

May need to look into Makefile.in and need to figure out. Will updated on that and many thanks again.

Kit


Many thanks,
Kit
https://kitpark.slack.com/
------
Sorry for a terse reply or typo as sent from a mobile.


--
You received this message because you are subscribed to a topic in the Google Groups "address-sanitizer" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/address-sanitizer/A5iPCUDa7YM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to address-sanitizer+unsubscribe@googlegroups.com.

Maxim Ostapenko

unread,
Nov 25, 2016, 11:32:48 AM11/25/16
to Park Kit, simon....@imgtec.com, address-...@googlegroups.com, sagar....@imgtec.com


25 Ноя 2016 г. 20:23 пользователь "Park Kit" <keite...@gmail.com> написал:
>
> Hi Maxim,

Hi

>
> Really appreciated for the link which works for me when follows exactly. However, I am seeing two differences from you when trying to build ASAN:
>
> 1. Used the same glibc version but no error on a machine I use.
> 2. When either use a libsanitizer/configure.tgt tweak or --enable-libsanitizer, "make all-gcc" doesn't build "libsanitizer

Try to do "make -j12" instead of "make all-gcc". If that doesn't work, rebuild GCC from the scratch:

1) rm -rf *
2) configure ...
3) make -j12

Make sure you added 'mips-linux' entry in configure.tgt.

>> To unsubscribe from this group and all its topics, send an email to address-saniti...@googlegroups.com.

Park Kit

unread,
Nov 25, 2016, 12:41:40 PM11/25/16
to Maxim Ostapenko, simon....@imgtec.com, address-...@googlegroups.com, sagar....@imgtec.com
Hi Maxim,

Still didn't build. The problem as far as I see, is "libgcc" since it should done in later steps(according to the reference) and it fails to build but when use all-gcc target, it didn't build libgcc so not a problem in this case. But "make" tries to build libgcc and failed.

The steps I did are:

  946  2016-11-25 17:26:18 export PATH=~/asn/install-4.8.2/bin:$PATH # to add binutil to the path
  947  2016-11-25 17:26:29 rm -rf *
  949  2016-11-25 17:26:42 ../gcc-4.8.2/configure -C --prefix=/xx/asn/install-4.8.2 --target=mips-linux --enable-languages=c,c++ --disable-multilib --enable-libsanitizer
  951  2016-11-25 17:26:57 make -j12

Of course, have a tweak in configure.tgt.

From configure log, ASAN wasn't filtered out but didn't get built.

*** This configuration is not supported in the following subdirectories:
     target-libitm gnattools target-libada target-libgfortran target-libgo target-libffi target-libbacktrace target-zlib target-libjava target-libobjc target-boehm-gc
    (Any other directories should still work fine.)

BTW, what did you mean by "rebuild GCC from the scratch"? Since use a separate build directory, step 1 and 2 in your reply would suffice. Anything missed or you meant something different?

Many thanks
Kit


Many thanks,
Kit
https://kitpark.slack.com/
------
Sorry for a terse reply or typo as sent from a mobile.


>> To unsubscribe from this group and all its topics, send an email to address-sanitizer+unsubscribe@googlegroups.com.

Maxim Ostapenko

unread,
Nov 25, 2016, 1:59:50 PM11/25/16
to Park Kit, simon....@imgtec.com, address-...@googlegroups.com, sagar....@imgtec.com


25 Ноя 2016 г. 21:41 пользователь "Park Kit" <keite...@gmail.com> написал:
>
> Hi Maxim,
>


> Still didn't build. The problem as far as I see, is "libgcc" since it should done in later steps(according to the reference) and it fails to build but when use all-gcc target, it didn't build libgcc so not a problem in this case. But "make" tries to build libgcc and failed.

Ah, no, you should do all 7 steps from the reference and just after that rebuild GCC like this:

1) rm - rf *
2) configure ... (from step 3)
3) make - j12

You should not have problems with libgcc on that step (after you did all 7 steps from the reference).

>
> The steps I did are:
>
>   946  2016-11-25 17:26:18 export PATH=~/asn/install-4.8.2/bin:$PATH # to add binutil to the path
>   947  2016-11-25 17:26:29 rm -rf *
>   949  2016-11-25 17:26:42 ../gcc-4.8.2/configure -C --prefix=/xx/asn/install-4.8.2 --target=mips-linux --enable-languages=c,c++ --disable-multilib --enable-libsanitizer
>   951  2016-11-25 17:26:57 make -j12
>
> Of course, have a tweak in configure.tgt.
>
> From configure log, ASAN wasn't filtered out but didn't get built.
>
> *** This configuration is not supported in the following subdirectories:
>      target-libitm gnattools target-libada target-libgfortran target-libgo target-libffi target-libbacktrace target-zlib target-libjava target-libobjc target-boehm-gc
>     (Any other directories should still work fine.)
>
> BTW, what did you mean by "rebuild GCC from the scratch"? Since use a separate build directory, step 1 and 2 in your reply would suffice. Anything missed or you meant something different?
>

I mean you can do step 3 replacing ' make -j4 all-gcc' with 'make -j4'.

>> >> To unsubscribe from this group and all its topics, send an email to address-saniti...@googlegroups.com.

Park Kit

unread,
Nov 28, 2016, 8:31:51 AM11/28/16
to Maxim Ostapenko, simon....@imgtec.com, address-...@googlegroups.com, sagar....@imgtec.com
Hi Maxim,

You're right. Have managed to have ASAN in build step. Very appreciated for your advice up until now. However, found two things to check:

1. You said you used GCC trunk and I am trying out GCC 4.8.2. See differences between them in applying patches you sent and build error such as

../../../../gcc-4.8.2/libsanitizer/asan/asan_linux.cc:90:3: error: #error "Unsupported arch"
 # error "Unsupported arch"
   ^
But think can do "back-port" this part from the trunk or 4.9.2.

2. As advised, when done build again in step 3 to build ASAN, shall I run the rest step again to install all such as step 4-7 as the reference or do install only in step 3? Checking before doing the former, full steps afterwards.
 

Many thanks again and it's almost there although need to do more to have uclibc with gcc. :-)
Kit

Many thanks,
Kit
https://kitpark.slack.com/
------
Sorry for a terse reply or typo as sent from a mobile.


>> >> To unsubscribe from this group and all its topics, send an email to address-sanitizer+unsubscribe@googlegroups.com.

Maxim Ostapenko

unread,
Nov 28, 2016, 9:10:11 AM11/28/16
to Park Kit, simon....@imgtec.com, address-...@googlegroups.com, sagar....@imgtec.com
2016-11-28 16:31 GMT+03:00 Park Kit <keite...@gmail.com>:
Hi Maxim,

Hi,
 

You're right. Have managed to have ASAN in build step. Very appreciated for your advice up until now. However, found two things to check:

1. You said you used GCC trunk and I am trying out GCC 4.8.2. See differences between them in applying patches you sent and build error such as

../../../../gcc-4.8.2/libsanitizer/asan/asan_linux.cc:90:3: error: #error "Unsupported arch"
 # error "Unsupported arch"
   ^
But think can do "back-port" this part from the trunk or 4.9.2.

Oh, right.
 

2. As advised, when done build again in step 3 to build ASAN, shall I run the rest step again to install all such as step 4-7 as the reference or do install only in step 3? Checking before doing the former, full steps afterwards.

You need just step 3 at this point, no need to do 4-7 stuff again.

Park Kit

unread,
Nov 28, 2016, 9:38:46 AM11/28/16
to Maxim Ostapenko, simon....@imgtec.com, address-...@googlegroups.com, sagar....@imgtec.com
Hi Maxim,

Once done 3) make - j12 from step 3, run 'make install' which is different from step 2 in the reference. Have set rpath to dismiss link errors:

/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/bin/ld: warning: libpthread.so.0, needed by /home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.
8.2/../../../../mips-linux/lib/libasan.so, not found (try using -rpath or -rpath-link)
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/bin/ld: warning: libdl.so.2, needed by /home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/.
./../../../mips-linux/lib/libasan.so, not found (try using -rpath or -rpath-link)
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/bin/ld: warning: libstdc++.so.6, needed by /home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8
.2/../../../../mips-linux/lib/libasan.so, not found (try using -rpath or -rpath-link)
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/bin/ld: warning: libm.so.6, needed by /home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/..
/../../../mips-linux/lib/libasan.so, not found (try using -rpath or -rpath-link)
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `pthread_attr_getstack@GLIBC_2.2'
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `pthread_setspecific@GLIBC_2.0'
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `dlsym@GLIBC_2.0'
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `pthread_key_create@GLIBC_2.0'
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `pthread_getspecific@GLIBC_2.0'
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `pthread_getattr_np@GLIBC_2.2.3'
collect2: error: ld returned 1 exit status

However, still gets this when do:

$ ./bin/mips-linux-gcc-4.8.2 -fsanitize=address -Wl,-rpath=/home/NDS-UK/kyoupark/asn/install-4.8.2/mips-linux/lib ~/asn/x.c
/home/nds-uk/kyoupark/asn/x.c:1:0: warning: -fsanitize=address not supported for this target [enabled by default]
 #include <stdio.h>
 ^
$

Anything I have missed here?
Kit


Many thanks,
Kit
https://kitpark.slack.com/
------
Sorry for a terse reply or typo as sent from a mobile.


Maxim Ostapenko

unread,
Nov 28, 2016, 9:42:50 AM11/28/16
to Park Kit, simon....@imgtec.com, address-...@googlegroups.com, sagar....@imgtec.com
2016-11-28 17:38 GMT+03:00 Park Kit <keite...@gmail.com>:
Hi Maxim,

Once done 3) make - j12 from step 3, run 'make install' which is different from step 2 in the reference. Have set rpath to dismiss link errors:

/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/bin/ld: warning: libpthread.so.0, needed by /home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.
8.2/../../../../mips-linux/lib/libasan.so, not found (try using -rpath or -rpath-link)
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/bin/ld: warning: libdl.so.2, needed by /home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/.
./../../../mips-linux/lib/libasan.so, not found (try using -rpath or -rpath-link)
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/bin/ld: warning: libstdc++.so.6, needed by /home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8
.2/../../../../mips-linux/lib/libasan.so, not found (try using -rpath or -rpath-link)
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/bin/ld: warning: libm.so.6, needed by /home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/..
/../../../mips-linux/lib/libasan.so, not found (try using -rpath or -rpath-link)
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `pthread_attr_getstack@GLIBC_2.2'
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `pthread_setspecific@GLIBC_2.0'
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `dlsym@GLIBC_2.0'
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `pthread_key_create@GLIBC_2.0'
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `pthread_getspecific@GLIBC_2.0'
/home/NDS-UK/kyoupark/asn/install-4.8.2/bin/../lib/gcc/mips-linux/4.8.2/../../../../mips-linux/lib/libasan.so: undefined reference to `pthread_getattr_np@GLIBC_2.2.3'
collect2: error: ld returned 1 exit status

However, still gets this when do:

$ ./bin/mips-linux-gcc-4.8.2 -fsanitize=address -Wl,-rpath=/home/NDS-UK/kyoupark/asn/install-4.8.2/mips-linux/lib ~/asn/x.c
/home/nds-uk/kyoupark/asn/x.c:1:0: warning: -fsanitize=address not supported for this target [enabled by default]
 #include <stdio.h>
 ^
$

Yes, as I mentioned earlier in mail just add -fstack-protector flag:

Park Kit

unread,
Nov 28, 2016, 10:46:45 AM11/28/16
to address-...@googlegroups.com, simon....@imgtec.com, sagar....@imgtec.com
Ah, sorry for that since I have missed that. Will give it try and update you  on that.

Many thanks,
Kit
https://kitpark.slack.com/
------
Sorry for a terse reply or typo as sent from a mobile.


Park Kit

unread,
Dec 14, 2016, 2:24:17 AM12/14/16
to address-...@googlegroups.com, simon....@imgtec.com, sagar....@imgtec.com
Hi Maxim,

Sorry for a slow response since I took some time to check ASAN's working on a target platform. Thanks to your help, have managed to build ASAN with uclibc and builds fine. However, gets a seg fault when runs it on a target:

#1  0x2aabf414 in __pthread_initialize_minimal_internal () from /home/xxx/asan/mips-libs-from-build/libpthread.so.0
#2  0x2ab36874 in __uClibc_init () from /home/xxx/asan/mips-libs-from-build/libc.so.0

Tried different uclibc version but no luck yet. Will try more and keep you updated on that.

Many thanks and
Щастлива Коледа

Kit



Many thanks,
Kit
https://kitpark.slack.com/
------
Sorry for a terse reply or typo as sent from a mobile.


Maxim Ostapenko

unread,
Dec 14, 2016, 7:15:37 AM12/14/16
to address-...@googlegroups.com, simon....@imgtec.com, sagar....@imgtec.com
Hi,

2016-12-14 10:23 GMT+03:00 Park Kit <keite...@gmail.com>:
Hi Maxim,

Sorry for a slow response since I took some time to check ASAN's working on a target platform. Thanks to your help, have managed to build ASAN with uclibc and builds fine. However, gets a seg fault when runs it on a target:

#1  0x2aabf414 in __pthread_initialize_minimal_internal () from /home/xxx/asan/mips-libs-from-build/libpthread.so.0
#2  0x2ab36874 in __uClibc_init () from /home/xxx/asan/mips-libs-from-build/libc.so.0

Tried different uclibc version but no luck yet. Will try more and keep you updated on that.


Hm, I don't know whether anyone tried to use ASan with uclibc before (AFAIK sanitizer runtime quite tightly connected to Glibc internals). I suggest you to use Glibc. If this isn't an option for you, then... good luck!
 
Many thanks and
Щастлива Коледа

Merry Christmas! :)

-Maxim
 
To unsubscribe from this group and stop receiving emails from it, send an email to address-sanitizer+unsubscribe@googlegroups.com.

Yuri Gribov

unread,
Dec 14, 2016, 7:29:48 AM12/14/16
to address-...@googlegroups.com, simon....@imgtec.com, sagar....@imgtec.com
On Wed, Dec 14, 2016 at 12:15 PM, Maxim Ostapenko <chef...@gmail.com> wrote:
> Hi,
>
> 2016-12-14 10:23 GMT+03:00 Park Kit <keite...@gmail.com>:
>>
>> Hi Maxim,
>>
>> Sorry for a slow response since I took some time to check ASAN's working
>> on a target platform. Thanks to your help, have managed to build ASAN with
>> uclibc and builds fine. However, gets a seg fault when runs it on a target:
>>
>> #1 0x2aabf414 in __pthread_initialize_minimal_internal () from
>> /home/xxx/asan/mips-libs-from-build/libpthread.so.0
>> #2 0x2ab36874 in __uClibc_init () from
>> /home/xxx/asan/mips-libs-from-build/libc.so.0
>>
>> Tried different uclibc version but no luck yet. Will try more and keep you
>> updated on that.
>>
>
> Hm, I don't know whether anyone tried to use ASan with uclibc before (AFAIK
> sanitizer runtime quite tightly connected to Glibc internals). I suggest you
> to use Glibc. If this isn't an option for you, then... good luck!

Supporting other libcs is interesting for embedded targets but I'd not
recommend to start with this until you have Glibc working. As Max
pointed out porting to new libc may be a lot of work (especially
thread-local storage internals, etc.).
Reply all
Reply to author
Forward
0 new messages