You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The previous sanitizer support was implemented in a very rigid manner,
with the compile options available for each sanitizer type been preset,
and enabling of each sanitizer through a preset variable.
This change makes it so that setting of compile options can be set on a
per-sanitizer-type basis and then added to builds via functions. Use via
the legacy `USE_SANITIZER` is available, but deprecated.
This is also flexible enough to allow overriding of the compile options,
via variables either in-script or passed in via the command-line.
Results of checks for compile compatability are cached, reducing time
on subsequent builds, provided the associated compile options are not
updated.
Checks for sanitizer availability/compatability are no longer platform
dependent. It will check on all platforms.
-[Example 1 - All targets instrumented](#example-1---all-targets-instrumented)
14
15
-[1a - Via global command](#1a---via-global-command)
15
16
-[1b - Via target commands](#1b---via-target-commands)
16
17
-[Example 2: Target instrumented, but with regex pattern of files to be excluded from report](#example-2-target-instrumented-but-with-regex-pattern-of-files-to-be-excluded-from-report)
17
18
-[Example 3: Target added to the 'ccov' and 'ccov-all' targets](#example-3-target-added-to-the-ccov-and-ccov-all-targets)
-[Control Flow Integrity](https://clang.llvm.org/docs/ControlFlowIntegrity.html) is designed to detect certain forms of undefined behaviour that can potentially allow attackers to subvert the program's control flow.
90
91
91
-
These are used by declaring the `USE_SANITIZER` CMake variable as string containing any of:
92
-
- Address
93
-
- Memory
94
-
- MemoryWithOrigins
95
-
- Undefined
96
-
- Thread
97
-
- Leak
98
-
- CFI
92
+
### Usage
93
+
94
+
The most basic way to enable sanitizers is to simply call `add_sanitizer_support` with the desired sanitizer names, whereupon it will check for the availability and compatability of the combined flags and apply to following compile targets:
95
+
```cmake
96
+
# apply address and leak sanitizers
97
+
add_sanitizer_support(address leak)
98
+
# future targets will be compiled with '-fsanitize=address -fsanitize=leak'
99
+
```
100
+
101
+
Compile options on a per-sanitizer basis can be accomplished by calling `set_sanitizer_options` before with the name of the sanitizer and desired compile options:
102
+
```cmake
103
+
# set custom options that will be applies with that specific sanitizer
# future targets will be compiled with '-fsanitize=address -fno-omit-frame-pointer -fsanitize=leak'
108
+
```
109
+
110
+
Per-sanitizer compile options can also be set by setting the named `SANITIZER_${SANITIZER_NAME}_OPTIONS` variable before, either in script or via the command line.
111
+
```cmake
112
+
# CMake called from command line as `cmake -S . -B build -D SANITIZER_ADDRESS_OPTION='-fno-omit-frame-pointer'`
113
+
114
+
add_sanitizer_support(address)
115
+
# future targets will be compiled with '-fsanitize=address -fno-omit-frame-pointer'
116
+
# despite no call to `set_sanitizer_options`
117
+
```
118
+
119
+
To prevent custom sanitizer options from external source being overwritten, the `DEFAULT` option can be used, so that the flags are only used if none have been set previously:
120
+
```cmake
121
+
# command line has options set via command-line: `cmake -S . -B build -D SANITIZER_ADDRESS_OPTION='-fno-omit-frame-pointer'`
99
122
100
-
Multiple values are allowed, e.g. `-DUSE_SANITIZER=Address,Leak` but some sanitizers cannot be combined together, e.g.`-DUSE_SANITIZER=Address,Memory` will result in configuration error. The delimeter character is not required and `-DUSE_SANITIZER=AddressLeak` would work as well.
123
+
# attempt to set custom options that will not apply since the variable already exists
0 commit comments