MJUCOM
MJUCOM

Reputation: 11

How to disable address Sanitizer Checking Function when memory access

I wonder that how to disable address sanitizer insert checking function when memory access. As I know that address sanitizer pass insert the checking function to detect out of access or buffer overflow..etc.[(https://github.com/llvm/llvmproject/blob/main/llvm/lib/Transforms/Instrumentation/AddressSanitizer.cpp) ]

I want to disable that address sanitizer insert the checking function. Is there any flag to disable to insert checking function? Or, How to disable address sanitizer code to check?

Thank you! Have a nice day :)

I expect to check the code line in AddressSanitizer.cpp

Upvotes: 1

Views: 3751

Answers (1)

Chandler Carruth
Chandler Carruth

Reputation: 3341

You can't disable different parts of the instrumentation independently - the instrumentation is done holistically both to check memory accesses and maintain the relevant metadata. If you want to track metadata similar to Address Sanitizer but w/o its checking, you'd have to write a new sanitizer pass to implement that.

However, you can disable Address Sanitizer on a more granular basis. For example, you con link together files where some are compiled with -fsanitize=address and some are not. You can also disable it using a function attribute:

https://clang.llvm.org/docs/AddressSanitizer.html#disabling-instrumentation-with-attribute-no-sanitize-address

You can see this in action here: https://cpp.compiler-explorer.com/z/rj95nKMY8

#include <iostream>

__attribute__((no_sanitize("address")))
int uninstrumented_access(int* array, int index) {
  return array[index];
}

int access(int* array, int index) {
  return array[index];
}

int main() {
  int *array = new int[10]();

  (void)uninstrumented_access(array, 42);
  std::cerr << "No ASan error from un-instrumented access due to attribute!\n";

  (void)access(array, 42);
  std::cerr << "No ASan error even from instrumented access!\n";
}

Here, uninstrumented_access disables all of the ASan checks. If you look at the Compiler Explorer output, you'll see that there is no ASan error from that function, but the normal version of it does produce an error.

Upvotes: 6

Related Questions