annotate clang/docs/SanitizerSpecialCaseList.rst @ 221:79ff65ed7e25

LLVM12 Original
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:15:29 +0900
parents 1d019706d866
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 ===========================
anatofuz
parents:
diff changeset
2 Sanitizer special case list
anatofuz
parents:
diff changeset
3 ===========================
anatofuz
parents:
diff changeset
4
anatofuz
parents:
diff changeset
5 .. contents::
anatofuz
parents:
diff changeset
6 :local:
anatofuz
parents:
diff changeset
7
anatofuz
parents:
diff changeset
8 Introduction
anatofuz
parents:
diff changeset
9 ============
anatofuz
parents:
diff changeset
10
anatofuz
parents:
diff changeset
11 This document describes the way to disable or alter the behavior of
anatofuz
parents:
diff changeset
12 sanitizer tools for certain source-level entities by providing a special
anatofuz
parents:
diff changeset
13 file at compile-time.
anatofuz
parents:
diff changeset
14
anatofuz
parents:
diff changeset
15 Goal and usage
anatofuz
parents:
diff changeset
16 ==============
anatofuz
parents:
diff changeset
17
anatofuz
parents:
diff changeset
18 User of sanitizer tools, such as :doc:`AddressSanitizer`, :doc:`ThreadSanitizer`
anatofuz
parents:
diff changeset
19 or :doc:`MemorySanitizer` may want to disable or alter some checks for
anatofuz
parents:
diff changeset
20 certain source-level entities to:
anatofuz
parents:
diff changeset
21
anatofuz
parents:
diff changeset
22 * speedup hot function, which is known to be correct;
anatofuz
parents:
diff changeset
23 * ignore a function that does some low-level magic (e.g. walks through the
anatofuz
parents:
diff changeset
24 thread stack, bypassing the frame boundaries);
anatofuz
parents:
diff changeset
25 * ignore a known problem.
anatofuz
parents:
diff changeset
26
anatofuz
parents:
diff changeset
27 To achieve this, user may create a file listing the entities they want to
anatofuz
parents:
diff changeset
28 ignore, and pass it to clang at compile-time using
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
29 ``-fsanitize-ignorelist`` flag. See :doc:`UsersManual` for details.
150
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 Example
anatofuz
parents:
diff changeset
32 =======
anatofuz
parents:
diff changeset
33
anatofuz
parents:
diff changeset
34 .. code-block:: bash
anatofuz
parents:
diff changeset
35
anatofuz
parents:
diff changeset
36 $ cat foo.c
anatofuz
parents:
diff changeset
37 #include <stdlib.h>
anatofuz
parents:
diff changeset
38 void bad_foo() {
anatofuz
parents:
diff changeset
39 int *a = (int*)malloc(40);
anatofuz
parents:
diff changeset
40 a[10] = 1;
anatofuz
parents:
diff changeset
41 }
anatofuz
parents:
diff changeset
42 int main() { bad_foo(); }
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
43 $ cat ignorelist.txt
150
anatofuz
parents:
diff changeset
44 # Ignore reports from bad_foo function.
anatofuz
parents:
diff changeset
45 fun:bad_foo
anatofuz
parents:
diff changeset
46 $ clang -fsanitize=address foo.c ; ./a.out
anatofuz
parents:
diff changeset
47 # AddressSanitizer prints an error report.
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
48 $ clang -fsanitize=address -fsanitize-ignorelist=ignorelist.txt foo.c ; ./a.out
150
anatofuz
parents:
diff changeset
49 # No error report here.
anatofuz
parents:
diff changeset
50
anatofuz
parents:
diff changeset
51 Format
anatofuz
parents:
diff changeset
52 ======
anatofuz
parents:
diff changeset
53
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
54 Ignorelists consist of entries, optionally grouped into sections. Empty lines
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
55 and lines starting with "#" are ignored.
150
anatofuz
parents:
diff changeset
56
anatofuz
parents:
diff changeset
57 Section names are regular expressions written in square brackets that denote
anatofuz
parents:
diff changeset
58 which sanitizer the following entries apply to. For example, ``[address]``
anatofuz
parents:
diff changeset
59 specifies AddressSanitizer while ``[cfi-vcall|cfi-icall]`` specifies Control
anatofuz
parents:
diff changeset
60 Flow Integrity virtual and indirect call checking. Entries without a section
anatofuz
parents:
diff changeset
61 will be placed under the ``[*]`` section applying to all enabled sanitizers.
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 Entries contain an entity type, followed by a colon and a regular expression,
anatofuz
parents:
diff changeset
64 specifying the names of the entities, optionally followed by an equals sign and
anatofuz
parents:
diff changeset
65 a tool-specific category, e.g. ``fun:*ExampleFunc=example_category``. The
anatofuz
parents:
diff changeset
66 meaning of ``*`` in regular expression for entity names is different - it is
anatofuz
parents:
diff changeset
67 treated as in shell wildcarding. Two generic entity types are ``src`` and
anatofuz
parents:
diff changeset
68 ``fun``, which allow users to specify source files and functions, respectively.
anatofuz
parents:
diff changeset
69 Some sanitizer tools may introduce custom entity types and categories - refer to
anatofuz
parents:
diff changeset
70 tool-specific docs.
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 .. code-block:: bash
anatofuz
parents:
diff changeset
73
anatofuz
parents:
diff changeset
74 # Lines starting with # are ignored.
anatofuz
parents:
diff changeset
75 # Turn off checks for the source file (use absolute path or path relative
anatofuz
parents:
diff changeset
76 # to the current working directory):
anatofuz
parents:
diff changeset
77 src:/path/to/source/file.c
anatofuz
parents:
diff changeset
78 # Turn off checks for a particular functions (use mangled names):
anatofuz
parents:
diff changeset
79 fun:MyFooBar
anatofuz
parents:
diff changeset
80 fun:_Z8MyFooBarv
anatofuz
parents:
diff changeset
81 # Extended regular expressions are supported:
anatofuz
parents:
diff changeset
82 fun:bad_(foo|bar)
anatofuz
parents:
diff changeset
83 src:bad_source[1-9].c
anatofuz
parents:
diff changeset
84 # Shell like usage of * is supported (* is treated as .*):
anatofuz
parents:
diff changeset
85 src:bad/sources/*
anatofuz
parents:
diff changeset
86 fun:*BadFunction*
anatofuz
parents:
diff changeset
87 # Specific sanitizer tools may introduce categories.
anatofuz
parents:
diff changeset
88 src:/special/path/*=special_sources
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
89 # Sections can be used to limit ignorelist entries to specific sanitizers
150
anatofuz
parents:
diff changeset
90 [address]
anatofuz
parents:
diff changeset
91 fun:*BadASanFunc*
anatofuz
parents:
diff changeset
92 # Section names are regular expressions
anatofuz
parents:
diff changeset
93 [cfi-vcall|cfi-icall]
anatofuz
parents:
diff changeset
94 fun:*BadCfiCall
anatofuz
parents:
diff changeset
95 # Entries without sections are placed into [*] and apply to all sanitizers