11

I build with GCC 10 flag -fsanitize=address and can run the program just fine, however if I run it under Valgrind it shows Asan error:

==477229== Memcheck, a memory error detector
==477229== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==477229== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==477229== Command: ./a.out
==477229== 
==477229==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.
==477229== 
==477229== HEAP SUMMARY:
==477229==     in use at exit: 0 bytes in 0 blocks
==477229==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==477229== 
==477229== All heap blocks were freed -- no leaks are possible
==477229== 
==477229== For lists of detected and suppressed errors, rerun with: -s
==477229== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)
ldd myprogram
    linux-vdso.so.1 (0x00007ffd0bd90000)
    libasan.so.6 => /lib/x86_64-linux-gnu/libasan.so.6 (0x00007f7256ba6000)
    libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f72569b4000)
    libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f72569ae000)
    libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f725698b000)
    libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f725683c000)
    libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007f7256821000)
    /lib64/ld-linux-x86-64.so.2 (0x00007f7257599000)

Remove -fsanitize=address, Valgrind can run it well. So why does the sanitizer make Valgrind miss Asan libraries?

Acorn
  • 24,970
  • 5
  • 40
  • 69
Shawn Shaw
  • 181
  • 3
  • 8

1 Answers1

9

At least a while ago mixing ASan and Valgrind was not supported, so it looks it is still not supported.

See valgrind, gcc 6.2.0 and "-fsanitize=address" for similar questions.

Acorn
  • 24,970
  • 5
  • 40
  • 69
  • char dest[10]; snprintf(dest,20,"%s",src); will run happily under valgrind with no warnings(well, maybe Valgrind is all about heap detection?). with asan this error will be caught immediately, hopefully valgrind will leverage Asan soon. – Shawn Shaw Aug 10 '20 at 01:10
  • 1
    @LaoShaw Valgrind catches only heap overflows. I do not think Valgrind and Asan will ever be compatible as both do very invasive low level instrumentation and there is already an easy workaround (just run QA two times, one under Valgrind and one under sanitizers). – yugr May 09 '21 at 02:19