Comment #3 on issue 380 by [email protected]: link error when LDFLAGS
has -Wl,--no-undefined
https://code.google.com/p/address-sanitizer/issues/detail?id=380
For ubuntu GCC, it works when
"g++-4.9 -shared -fPIC libtest.cpp -o libtest.so -fsanitize=address -lasan".
And for my build toolchain(mips gcc 4.9), it works when
"mipsel-linux-g++ -shared -fPIC libtest.cpp -o libtest.so
-fsanitize=address -fstack-protector".
"-lasan" flag isn't needed at all.
I guess maybe the asan build for ubuntu-toolchain-r doesn't add "-lasan"
for "-fsanitize=address" by default.
For clang, maybe the problem is that the clang only compile asan static
libraries, like
/usr/lib/llvm-3.6/lib/clang/3.6.0/lib/linux/libclang_rt.asan_cxx-x86_64.a
/usr/lib/llvm-3.6/lib/clang/3.6.0/lib/linux/libclang_rt.asan-x86_64.a
As https://code.google.com/p/address-sanitizer/wiki/AsanAsDso says, "Until
recently, ASAN runtime in Clang on Linux was offered only in the form of
static library (e.g. libclang_rt.asan-x86_64.a). This has recently been
changed and you can now ask for shared runtime (aka ASAN-DSO) by cmaking
with -DCOMPILER_RT_BUILD_SHARED_ASAN=ON (and then compiling your code with
-fsanitize=address -shared-libasan)."
I find the link flag "-Wl,--no-undefined" which used by Android is nice,
which can avoid libraries developers forgeting to write the dependent
libraries of the library in the Makefile or CMakeLists.txt. So, I hope
there is a way to use both flags.
My solution is the following:
(1)For GCC, I use "-Wl,--no-undefined" and "-fsanitize=address" both, if
the linker fails, add "-lasan" for linker flag.
(2)For Clang Ubuntu, I use "-Wl,--no-undefined" by default.
If "-fsanitize=address" is set, turn off the flag "-Wl,--no-undefined".
(3)For Android NDK, since both static and shared libraries are built for
asan, both flags work fine, which I have approved for NDK r10d clang3.5.
--
You received this message because this project is configured to send all
issue notifications to this address.
You may adjust your notification preferences at:
https://code.google.com/hosting/settings
--
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 [email protected].
For more options, visit https://groups.google.com/d/optout.