1 ===========================
2 Sanitizer special case list
3 ===========================
11 This document describes the way to disable or alter the behavior of
12 sanitizer tools for certain source-level entities by providing a special
18 User of sanitizer tools, such as :doc:`AddressSanitizer`, :doc:`ThreadSanitizer`
19 or :doc:`MemorySanitizer` may want to disable or alter some checks for
20 certain source-level entities to:
22 * speedup hot function, which is known to be correct;
23 * ignore a function that does some low-level magic (e.g. walks through the
24 thread stack, bypassing the frame boundaries);
25 * ignore a known problem.
27 To achieve this, user may create a file listing the entities they want to
28 ignore, and pass it to clang at compile-time using
29 ``-fsanitize-ignorelist`` flag. See :doc:`UsersManual` for details.
39 int *a = (int*)malloc(40);
42 int main() { bad_foo(); }
44 # Ignore reports from bad_foo function.
46 $ clang -fsanitize=address foo.c ; ./a.out
47 # AddressSanitizer prints an error report.
48 $ clang -fsanitize=address -fsanitize-ignorelist=ignorelist.txt foo.c ; ./a.out
49 # No error report here.
54 Ignorelists consist of entries, optionally grouped into sections. Empty lines
55 and lines starting with "#" are ignored.
57 Section names are regular expressions written in square brackets that denote
58 which sanitizer the following entries apply to. For example, ``[address]``
59 specifies AddressSanitizer while ``[cfi-vcall|cfi-icall]`` specifies Control
60 Flow Integrity virtual and indirect call checking. Entries without a section
61 will be placed under the ``[*]`` section applying to all enabled sanitizers.
63 Entries contain an entity type, followed by a colon and a regular expression,
64 specifying the names of the entities, optionally followed by an equals sign and
65 a tool-specific category, e.g. ``fun:*ExampleFunc=example_category``. The
66 meaning of ``*`` in regular expression for entity names is different - it is
67 treated as in shell wildcarding. Two generic entity types are ``src`` and
68 ``fun``, which allow users to specify source files and functions, respectively.
69 Some sanitizer tools may introduce custom entity types and categories - refer to
74 # Lines starting with # are ignored.
75 # Turn off checks for the source file (use absolute path or path relative
76 # to the current working directory):
77 src:/path/to/source/file.c
78 # Turn off checks for this main file, including files included by it.
79 # Useful when the main file instead of an included file should be ignored.
81 # Turn off checks for a particular functions (use mangled names):
84 # Extended regular expressions are supported:
87 # Shell like usage of * is supported (* is treated as .*):
90 # Specific sanitizer tools may introduce categories.
91 src:/special/path/*=special_sources
92 # Sections can be used to limit ignorelist entries to specific sanitizers
95 # Section names are regular expressions
98 # Entries without sections are placed into [*] and apply to all sanitizers
100 ``mainfile`` is similar to applying ``-fno-sanitize=`` to a set of files but
101 does not need plumbing into the build system. This works well for internal
102 linkage functions but has a caveat for C++ vague linkage functions.
104 C++ vague linkage functions (e.g. inline functions, template instantiations) are
105 deduplicated at link time. A function (in an included file) ignored by a
106 specific ``mainfile`` pattern may not be the prevailing copy picked by the
107 linker. Therefore, using ``mainfile`` requires caution. It may still be useful,
108 e.g. when patterns are picked in a way to ensure the prevailing one is ignored.
109 (There is action-at-a-distance risk.)
111 ``mainfile`` can be useful enabling a ubsan check for a large code base when
112 finding the direct stack frame triggering the failure for every failure is