llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.15k stars 12.03k forks source link

clang for sanitizes dynamic libasan support seems missing #115599

Open akhileshkumar80 opened 1 week ago

akhileshkumar80 commented 1 week ago

Hello

Ubuntu clang version 18.1.3 (1ubuntu1) $ clang++ -O1 -g -fsanitize=address -fno-omit-frame-pointer example_UseAfterFree.cc $ clang++ -O1 -g -fsanitize=address -fno-omit-frame-pointer example_UseAfterFree.cc -static-libsan -o a.out.static dongkyun@SDK:~/tmp/asan/clang$ ll -rwxr-xr-x 1 root root 1663576 Oct 30 14:14 a.out.static -rwxr-xr-x 1 root root 1663576 Oct 30 14:13 a.out

in case of default compilation observed only static libs are linked, is this normal behavior or bug please guide ? even i observed the same clang older versions too.

"/usr/bin/ld" -pie -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o a.out.static /lib/x86_64-linux-gnu/Scrt1.o /lib/x86_64-linux-gnu/crti.o /usr/bin/../lib/gcc/x86_64-linux-gnu/11/crtbeginS.o -L/usr/bin/../lib/gcc/x86_64-linux-gnu/11 -L/usr/bin/../lib/gcc/x86_64-linux-gnu/11/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/usr/lib/llvm-14/bin/../lib -L/lib -L/usr/lib --whole-archive /usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.asan_static-x86_64.a --no-whole-archive --whole-archive /usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.asan-x86_64.a --no-whole-archive --dynamic-list=/usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.asan-x86_64.a.syms --whole-archive /usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.asan_cxx-x86_64.a --no-whole-archive --dynamic-list=/usr/lib/llvm-14/lib/clang/14.0.0/lib/linux/libclang_rt.asan_cxx-x86_64.a.syms /tmp/use_after_free-47420a.o -lstdc++ -lm --no-as-needed -lpthread -lrt -lm -ldl -lgcc_s -lgcc -lc -lgcc_s -lgcc /usr/bin/../lib/gcc/x86_64-linux-gnu/11/crtendS.o /lib/x86_64-linux-gnu/crtn.o

EugeneZelenko commented 1 week ago

Could you please try 19 or main branch? https://godbolt.org should be helpful.

dkson95 commented 1 week ago

Could you please try 19 or main branch? https://godbolt.org should be helpful.

Hi, Example from https://clang.llvm.org/docs/AddressSanitizer.html

Btw, g++ (Ubuntu 13.2.0-23ubuntu4) 13.2.0 support dynamic libasan with same example.

$ g++ -O1 -g -fsanitize=address -fno-omit-frame-pointer example_UseAfterFree.cc
$ g++ -O1 -g -fsanitize=address -fno-omit-frame-pointer example_UseAfterFree.cc -static-libasan -o a.out.static
$ ls -al
-rwxrwxr-x 1 dongkyun dongkyun 1659584 Oct 30 14:47 a.out.static
-rwxrwxr-x 1 dongkyun dongkyun   25992 Oct 30 14:47 a.out

So, it needs to check how llvm/clang support dynamic libasan

Limitations

Static linking of executables is not supported.

Unlike the limitatin note, shared version might not be supported