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 Users 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.
59 In `D154014 <https://reviews.llvm.org/D154014>`_ we transitioned to using globs instead
60 of regexes to match patterns in special case lists. Since this was a
61 breaking change, we will temporarily support the original behavior using
62 regexes. If ``#!special-case-list-v2`` is the first line of the file, then
63 we will use the new behavior using globs. For more details, see
64 `this discourse post <https://discourse.llvm.org/t/use-glob-instead-of-regex-for-specialcaselists/71666>`_.
67 Section names are globs written in square brackets that denote
68 which sanitizer the following entries apply to. For example, ``[address]``
69 specifies AddressSanitizer while ``[{cfi-vcall,cfi-icall}]`` specifies Control
70 Flow Integrity virtual and indirect call checking. Entries without a section
71 will be placed under the ``[*]`` section applying to all enabled sanitizers.
73 Entries contain an entity type, followed by a colon and a glob,
74 specifying the names of the entities, optionally followed by an equals sign and
75 a tool-specific category, e.g. ``fun:*ExampleFunc=example_category``.
76 Two generic entity types are ``src`` and
77 ``fun``, which allow users to specify source files and functions, respectively.
78 Some sanitizer tools may introduce custom entity types and categories - refer to
83 #!special-case-list-v2
84 # The line above is explained in the note above
85 # Lines starting with # are ignored.
86 # Turn off checks for the source file
87 # Entries without sections are placed into [*] and apply to all sanitizers
88 src:path/to/source/file.c
90 # Turn off checks for this main file, including files included by it.
91 # Useful when the main file instead of an included file should be ignored.
93 # Turn off checks for a particular functions (use mangled names):
95 # Glob brace expansions and character ranges are supported
98 # "*" matches zero or more characters
101 # Specific sanitizer tools may introduce categories.
102 src:/special/path/*=special_sources
103 # Sections can be used to limit ignorelist entries to specific sanitizers
106 # Section names are globs
107 [{cfi-vcall,cfi-icall}]
110 ``mainfile`` is similar to applying ``-fno-sanitize=`` to a set of files but
111 does not need plumbing into the build system. This works well for internal
112 linkage functions but has a caveat for C++ vague linkage functions.
114 C++ vague linkage functions (e.g. inline functions, template instantiations) are
115 deduplicated at link time. A function (in an included file) ignored by a
116 specific ``mainfile`` pattern may not be the prevailing copy picked by the
117 linker. Therefore, using ``mainfile`` requires caution. It may still be useful,
118 e.g. when patterns are picked in a way to ensure the prevailing one is ignored.
119 (There is action-at-a-distance risk.)
121 ``mainfile`` can be useful enabling a ubsan check for a large code base when
122 finding the direct stack frame triggering the failure for every failure is