[PATCH] Documentation for sanitizer special case list

Alexey Samsonov samsonov at google.com
Mon Aug 5 07:48:12 PDT 2013


  Address comments by silvas.

Hi silvas, eugenis,

http://llvm-reviews.chandlerc.com/D1268

CHANGE SINCE LAST DIFF
  http://llvm-reviews.chandlerc.com/D1268?vs=3146&id=3193#toc

Files:
  docs/MemorySanitizer.rst
  docs/SanitizerSpecialCaseList.rst
  docs/AddressSanitizer.rst
  docs/ThreadSanitizer.rst
  docs/index.rst
  docs/UsersManual.rst

Index: docs/MemorySanitizer.rst
===================================================================
--- docs/MemorySanitizer.rst
+++ docs/MemorySanitizer.rst
@@ -93,6 +93,14 @@
 ``__has_feature(memory_sanitizer)``. Note: currently, this attribute will be
 lost if the function is inlined.
 
+Blacklist
+---------
+
+You may use :doc:`SanitizerSpecialCaseList` to relax MemorySanitizer checks
+for certain functions and source files. All "Use of uninitialized value"
+warnings will be suppressed and all values loaded from memory will be
+considered fully initialized.
+
 Origin Tracking
 ===============
 
Index: docs/SanitizerSpecialCaseList.rst
===================================================================
--- /dev/null
+++ docs/SanitizerSpecialCaseList.rst
@@ -0,0 +1,75 @@
+===========================
+Sanitizer special case list
+===========================
+
+.. contents::
+   :local:
+
+Introduction
+============
+
+This document describes the way to disable or alter the behavior of
+sanitizer tools for certain source-level entities by providing a special
+file at compile-time.
+
+Goal and usage
+==============
+
+User of sanitizer tools, such as :doc:`AddressSanitizer`, :doc:`ThreadSanitizer`
+or :doc:`MemorySanitizer` may want to disable or alter some checks for
+certain source-level entities to:
+
+* speedup hot function, which is known to be correct;
+* ignore a function that does some low-level magic (e.g. walks through the
+  thread stack, bypassing the frame boundaries);
+* ignore a known problem.
+
+To achieve this, user may create a file listing the entities he wants to
+ignore, and pass it to clang at compile-time using
+``-fsanitize-blacklist`` flag. See :doc:`UsersManual` for details.
+
+Example
+=======
+
+.. code-block:: bash
+
+  $ cat foo.c
+  #include <stdlib.h>
+  void bad_foo() {
+    int *a = (int*)malloc(40);
+    a[10] = 1;
+  }
+  int main() { bad_foo(); }
+  $ cat blacklist.txt
+  # Ignore reports from bad_foo function.
+  fun:bad_foo
+  $ clang -fsanitize=address foo.c ; ./a.out
+  # AddressSanitizer prints an error report.
+  $ clang -fsanitize=address -fsanitize-blacklist=blacklist.txt foo.c ; ./a.out
+  # No error report here.
+
+Format
+======
+
+Each line contains a prefix, followed by a colon and a regular expression.
+Empty lines and lines starting with "#" are ignored. Prefix defines the type
+of entity, and regular expression defines the names of the entities.
+
+.. code-block:: bash
+
+    # Lines starting with # are ignored.
+    # Turn off checks for the source file (use absolute path or path relative
+    # to the current working directory):
+    src:/path/to/source/file.c
+    # Turn off checks for a particular functions (use mangled names):
+    fun:MyFooBar
+    fun:_Z8MyFooBarv
+    # Basic regular expressions are supported:
+    fun:bad_(foo|bar)
+    src:bad_source[1-9].c
+    # Shell like usage of * is supported (* is treated as .*):
+    src:bad/sources/*
+    fun:*BadFunction*
+
+Some sanitizer tools may introduce custom entry types - see the tool-specific docs.
+
Index: docs/AddressSanitizer.rst
===================================================================
--- docs/AddressSanitizer.rst
+++ docs/AddressSanitizer.rst
@@ -126,6 +126,24 @@
 you should set environment variable
 ``ASAN_OPTIONS=check_initialization_order=1``.
 
+Blacklist
+---------
+
+You may use sanitizer special case list to disable AddressSanizier checks for
+certain source files, functions and global variables. See
+:doc:`SanitizerSpecialCaseList` for general file format description.
+AddressSanitizer-specific entry formats are:
+
+.. code-block:: bash
+
+    # Disable checks for globals with certain names or types:
+    global:bad_array
+    type:*Namespace::BadClassName*
+    # Disable initialization-order checks for globals:
+    global:bad_init_global=init
+    type:*Namespace::BadInitClassName*=init
+    src:bad/init/files/*=init
+
 Supported Platforms
 ===================
 
Index: docs/ThreadSanitizer.rst
===================================================================
--- docs/ThreadSanitizer.rst
+++ docs/ThreadSanitizer.rst
@@ -97,6 +97,12 @@
 ``__has_feature(thread_sanitizer)``. Note: currently, this attribute will be
 lost if the function is inlined.
 
+Blacklist
+---------
+
+You may use :doc:`SanitizerSpecialCaseList` to disable ThreadSanitizer checks
+for certain functions and source files. Data race reports will be suppressed.
+
 Limitations
 -----------
 
Index: docs/index.rst
===================================================================
--- docs/index.rst
+++ docs/index.rst
@@ -21,6 +21,7 @@
    AddressSanitizer
    ThreadSanitizer
    MemorySanitizer
+   SanitizerSpecialCaseList
    Modules
    FAQ
 
Index: docs/UsersManual.rst
===================================================================
--- docs/UsersManual.rst
+++ docs/UsersManual.rst
@@ -940,6 +940,15 @@
       it is of the wrong dynamic type, or that its lifetime has not
       begun or has ended. Incompatible with ``-fno-rtti``.
 
+   You can turn off or modify checks for certain source files, functions
+   or even variables by providing a special file:
+
+   -  ``-fsanitize-blacklist=/path/to/blacklist/file``: disable or modify
+      sanitizer checks for objects listed in the file. See
+      :doc:`SanitizerSpecialCaseList` for file format description.
+   -  ``-fno-sanitize-blacklist``: don't use blacklist file, if it was
+      specified earlier in the command line.
+
    Experimental features of AddressSanitizer (not ready for widespread
    use, require explicit ``-fsanitize=address``):
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D1268.3.patch
Type: text/x-patch
Size: 5608 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130805/f4dcbf1f/attachment.bin>


More information about the cfe-commits mailing list