Using address sanitizer with NDK

623 views
Skip to first unread message

a1

unread,
Feb 10, 2014, 5:33:17 AM2/10/14
to andro...@googlegroups.com
I was trying to compile my application (with both clang 3.3 and gcc 4.8) with address sanitizer but whatever I tried I end up with a lot of link errors like the one below:

    error: undefined reference to '__asan_report_load4'

and here is linker command line:

    arm-linux-androideabi-g++ -Wl,-soname,libpsd.so -shared --sysroot=C:/ndk/platforms/android-14/arch-arm \
        (... obj files ...) -lgcc -no-canonical-prefixes -march=armv7-a -Wl,--fix-cortex-a8 -Wl,--no-undefined \
        -Wl,-z,noexecstack -Wl,-z,relro -Wl,-z,now -Wl,--gc-sections -fsanitize=address \
        -LC:/cygwin/ndk/platforms/android-14/arch-arm/usr/lib -llog -lz -lc -lm -o ./obj/local/armeabi-v7a/libpsd.so 

I've setup sanitizer on application level with:

    APP_LDFLAGS += -fsanitize=address 
    APP_CFLAGS += -fsanitize=address  -O1 -fno-omit-frame-pointer -fno-optimize-sibling-calls 

(I've tried on per module basis as well but with no luck).

Anyone managed to compile with sanitizers enabled?

--
Bart




Anton Persson

unread,
Mar 29, 2014, 5:49:59 AM3/29/14
to android-ndk
I am trying to get address sanitizer to work as well with GCC. Did you have any luck getting it to work?

     /Anton


--
You received this message because you are subscribed to the Google Groups "android-ndk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to android-ndk...@googlegroups.com.
To post to this group, send email to andro...@googlegroups.com.
Visit this group at http://groups.google.com/group/android-ndk.
For more options, visit https://groups.google.com/groups/opt_out.

a1

unread,
Mar 29, 2014, 12:10:26 PM3/29/14
to andro...@googlegroups.com
I am trying to get address sanitizer to work as well with GCC. Did you have any luck getting it to work?

Nope, sorry, I have valgrind up and running so I settled with that and didn't waste any more time on trying to setup asan.

--
Bart

Ryan Loebs

unread,
Mar 22, 2017, 7:54:31 PM3/22/17
to android-ndk
I know this is a 3-year-old thread at this point, but for what it's worth to anybody else stumbling upon this thread: you need to add the "-g" flag to the CFLAGS/CXXFLAGS to resolve the linker errors.  The set that worked for me:

-g -fsanitize=address -fno-omit-frame-pointer
Reply all
Reply to author
Forward
0 new messages