Closed nope8 closed 2 months ago
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6.0.0 ./main
Still can not print memory error: $ g++ -c -fPIC test.cpp -o test.o g++ -shared -o libtest.so test.o g++ -o main main.cpp -L. -ltest -O1 -fno-omit-frame-pointer -g LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6.0.0 ./main $
Sorry, I mean:
#command1:
g++ -c -fPIC test.cpp -o test.o -fsanitize=address -O1 -fno-omit-frame-pointer -g
g++ -shared -o libtest.so test.o -fsanitize=address -O1 -fno-omit-frame-pointer -g
g++ -o main main.cpp -L. -ltest
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6.0.0 ./main
OK, successed, thank you very much.
update clang++ compile progress command sample:
export LD_LIBRARY_PATH=/usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/:./:$LD_LIBRARY_PATH
clang++ -c -fPIC test.cpp -o test.o -fsanitize=address -shared-libasan -O1 -fno-omit-frame-pointer -g
clang++ -shared -o libtest.so test.o -fsanitize=address -shared-libasan -O1 -fno-omit-frame-pointer -g
clang++ -o main main.cpp -L. -ltest
LD_PRELOAD=/usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.asan-x86_64.so ./main
FAQ: Q: Can I mix code instrumented by Clang with code instrumented by GCC? Or can I at least compile code with Clang and link against GCC ASan runtime and vice versa?
A: No, you cannot, Clang and GCC have completely incompatible ASan implementations, you cannot mix them in any way.
@Enna1 Can you help me to check if asan support below two scenario:
Althogh I have tested they can work on libtest.so, but not sure if it will work on other complex sdk so instead of libtest.so.
# use g++ build libtest.so with asan enable, then g++ build main link with libtest.so
g++ -c -fPIC test.cpp -o test.o -fsanitize=address -O1 -fno-omit-frame-pointer -g
g++ -shared -o libtest.so test.o -fsanitize=address -O1 -fno-omit-frame-pointer -g
clang++ -o main main.cpp -L. -ltest
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libasan.so.6.0.0 ./main
#
export LD_LIBRARY_PATH=/usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/:./:$LD_LIBRARY_PATH
clang++ -c -fPIC test.cpp -o test.o -fsanitize=address -shared-libasan -O1 -fno-omit-frame-pointer -g
clang++ -shared -o libtest.so test.o -fsanitize=address -shared-libasan -O1 -fno-omit-frame-pointer -g
g++ -o main main.cpp -L. -ltest
LD_PRELOAD=/usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.asan-x86_64.so ./main
@Enna1 Can you help me to check if asan support below two scenario:
- g++ build to generate libtest.so with asan enable, then clang++ build main link with libtest.so
- clang++ build to generate libtest.so with asan enable, then g++ build main excutable link with libtest.so
The short answer is NO, don't do this.
Got it, thank you.
test environment: Ubuntu 22.04.1 LTS
AddressSanitizer FAQ: Q: I've built my shared library with ASan. Can I run it with unsanitized executable? A: Yes! You'll need to build your library with dynamic version of ASan and then run executable with LD_PRELOAD=path/to/asan/runtime/lib.
as show below I do test according to FAQ description, the result show that only print memory error when set compile/link option: -fsanitize=address on both dynamic so and excutable . please help to solve the issue, or point out where I'm wrong.
source code file: test.cpp:
main.cpp:
build and run command