Search code examples
gccaddress-sanitizer

ASAN: can I have both -fsanitize=address and LD_PRELOAD=/usr/lib/libasan.so on same file


I'm compiling a program with -fsanitize=address, but getting error

==48458==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.

After adding LD_PRELOAD, its working fine, but if I'm using LD_PRELOAD do I need -fsanitize=address compiler flag as well?

After adding LD_PRELOAD, should I still compile my program with -fsanitize=address flag?


Solution

  • Yes, -fsanitize=address inserts additional instrumentation in your code which is used to detect memory errors. You definitely want to keep it.