Skip to content

Commit 02ba22e

Browse files
authored
Merge pull request #2638 from rust-lang/tshepang/sembr
sembr sanitizers.md and improve it a bit
2 parents 310f5ef + 1a3a6c9 commit 02ba22e

File tree

1 file changed

+26
-23
lines changed

1 file changed

+26
-23
lines changed

src/sanitizers.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,26 @@ The rustc compiler contains support for following sanitizers:
1010
* [Hardware-assisted AddressSanitizer][clang-hwasan] a tool similar to
1111
AddressSanitizer but based on partial hardware assistance.
1212
* [KernelControlFlowIntegrity][clang-kcfi] LLVM Kernel Control Flow Integrity
13-
(KCFI) provides forward-edge control flow protection for operating systems
14-
kernels.
13+
(KCFI) provides forward-edge control flow protection for operating systems kernels.
1514
* [LeakSanitizer][clang-lsan] a run-time memory leak detector.
1615
* [MemorySanitizer][clang-msan] a detector of uninitialized reads.
1716
* [ThreadSanitizer][clang-tsan] a fast data race detector.
1817

1918
## How to use the sanitizers?
2019

2120
To enable a sanitizer compile with `-Z sanitizer=...` option, where value is one
22-
of `address`, `cfi`, `hwaddress`, `kcfi`, `leak`, `memory` or `thread`. For more
23-
details on how to use sanitizers please refer to the sanitizer flag in [the
24-
unstable book](https://doc.rust-lang.org/unstable-book/).
21+
of `address`, `cfi`, `hwaddress`, `kcfi`, `leak`, `memory` or `thread`.
22+
For more details on how to use sanitizers,
23+
please refer to the sanitizer flag in [The Unstable Book].
24+
25+
[The Unstable Book]: https://doc.rust-lang.org/unstable-book
2526

2627
## How are sanitizers implemented in rustc?
2728

2829
The implementation of sanitizers (except CFI) relies almost entirely on LLVM.
2930
The rustc is an integration point for LLVM compile time instrumentation passes
30-
and runtime libraries. Highlight of the most important aspects of the
31-
implementation:
31+
and runtime libraries.
32+
Highlight of the most important aspects of the implementation:
3233

3334
* The sanitizer runtime libraries are part of the [compiler-rt] project, and
3435
[will be built][sanitizer-build] on [supported targets][sanitizer-targets]
@@ -43,23 +44,26 @@ implementation:
4344

4445
* During LLVM code generation, the functions intended for instrumentation are
4546
[marked][sanitizer-attribute] with appropriate LLVM attribute:
46-
`SanitizeAddress`, `SanitizeHWAddress`, `SanitizeMemory`, or
47-
`SanitizeThread`. By default all functions are instrumented, but this
47+
`SanitizeAddress`, `SanitizeHWAddress`, `SanitizeMemory`, or `SanitizeThread`.
48+
By default, all functions are instrumented, but this
4849
behaviour can be changed with `#[sanitize(xyz = "on|off|<other>")]`.
4950

5051
* The decision whether to perform instrumentation or not is possible only at a
51-
function granularity. In the cases were those decision differ between
52-
functions it might be necessary to inhibit inlining, both at [MIR
52+
function granularity.
53+
In the cases were those decision differ between
54+
functions, it might be necessary to inhibit inlining, both at [MIR
5355
level][inline-mir] and [LLVM level][inline-llvm].
5456

5557
* The LLVM IR generated by rustc is instrumented by [dedicated LLVM
56-
passes][sanitizer-pass], different for each sanitizer. Instrumentation
57-
passes are invoked after optimization passes.
58+
passes][sanitizer-pass], different for each sanitizer.
59+
Instrumentation passes are invoked after optimization passes.
5860

5961
* When producing an executable, the sanitizer specific runtime library is
60-
[linked in][sanitizer-link]. The libraries are searched for in the target
61-
libdir. First relative to the overridden system root and subsequently
62-
relative to the default system root. Fall-back to the default system root
62+
[linked in][sanitizer-link].
63+
The libraries are searched for in the target libdir.
64+
First, the search is relative to the overridden system root, and subsequently,
65+
it is relative to the default system root.
66+
Fall-back to the default system root
6367
ensures that sanitizer runtimes remain available when using sysroot overrides
6468
constructed by cargo `-Z build-std` or xargo.
6569

@@ -80,21 +84,20 @@ Sanitizers are validated by code generation tests in
8084
[`tests/ui/sanitizer/`][test-ui] directory.
8185

8286
Testing sanitizer functionality requires the sanitizer runtimes (built when
83-
`sanitizer = true` in `bootstrap.toml`) and target providing support for particular
84-
sanitizer. When sanitizer is unsupported on given target, sanitizers tests will
85-
be ignored. This behaviour is controlled by compiletest `needs-sanitizer-*`
86-
directives.
87+
`sanitizer = true` in `bootstrap.toml`) and target providing support for particular a sanitizer.
88+
When a sanitizer is unsupported on a given target, sanitizer tests will be ignored.
89+
This behaviour is controlled by compiletest `needs-sanitizer-*` directives.
8790

8891
[test-cg]: https://github.com/rust-lang/rust/tree/HEAD/tests/codegen-llvm
8992
[test-ui]: https://github.com/rust-lang/rust/tree/HEAD/tests/ui/sanitizer
9093

91-
## Enabling sanitizer on a new target
94+
## Enabling a sanitizer on a new target
9295

9396
To enable a sanitizer on a new target which is already supported by LLVM:
9497

9598
1. Include the sanitizer in the list of `supported_sanitizers` in [the target
96-
definition][target-definition]. `rustc --target .. -Zsanitizer=..` should now
97-
recognize sanitizer as supported.
99+
definition][target-definition].
100+
`rustc --target .. -Zsanitizer=..` should now recognize the sanitizer as supported.
98101
2. [Build the runtime for the target and include it in the libdir.][sanitizer-targets]
99102
3. [Teach compiletest that your target now supports the sanitizer.][compiletest-definition]
100103
Tests marked with `needs-sanitizer-*` should now run on the target.

0 commit comments

Comments
 (0)