1

I want to disable ASan and TSan checks for one method in a project and the option llvm provides is a Sanitizer special case list.

Here is a small example code which triggers an AddressSanitizer error.

#include <cstdlib>
#include <memory>

class BadASan
{
public:
  void get_memory()
  {
    int *a = reinterpret_cast<int *>(malloc(40));
    a[10] = 1;
  }
};

int main()
{
  auto bad_asan = std::make_unique<BasASan>();
  bad_asan->get_memory();
  return 0;
}

I have a file ignorelist.txt to tell ASan to ignore BadASan::get_memory(), but none of the pattern I tried so far are working. Every line starting with fun: I tried on its own or with combination of others

[address]
fun:BadASan::get_memory       # fully qualified name
fun:*get_memory               # pattern with only the method name
fun:__ZN3BadASan7get_memoryEv # mangled name

I compile the code with:

# clang++ -std=c++17 -fsanitze=address -fsanitize-ignorelist=ignorelist.txt bad_asan.cxx

but still the AddressSanitizer is showing the error.

How do I disable ASan for the method BadASan::get_memory with an ignorelist?

ByteNudger
  • 1,545
  • 5
  • 29
  • 37

1 Answers1

0

Disabling LSan seems a little more complicated than just the ignorelist. The clang documentation redirects to full documentation which has the answer.

Have a file suppr.txt with the content

leak:get_memory

And another file ignorelist.txt with content

fun:*get_memory*

Compile with

clang++ -fsanitize=address -fsanitize-ignorelist=ignorelist.txt main.cpp  

Then run with

ASAN_OPTIONS=detect_leaks=1 LSAN_OPTIONS=suppressions=suppr.txt ./a.out 
Adrian Mole
  • 49,934
  • 160
  • 51
  • 83
bhakku
  • 1
  • Also of interest might be this issue: https://github.com/google/sanitizers/issues/1628 which provides ways to supress leaksanitizers during compile time. – bhakku Mar 09 '23 at 23:33