Update sanitizers documentation (#562)
This commit is contained in:
parent
7e93524143
commit
c83c96402a
|
|
@ -1,6 +1,6 @@
|
||||||
# Sanitizers Support
|
# Sanitizers Support
|
||||||
|
|
||||||
The rustc compiler contains basic support for following sanitizers:
|
The rustc compiler contains support for following sanitizers:
|
||||||
|
|
||||||
* [AddressSanitizer][clang-asan] a faster memory error detector. Can
|
* [AddressSanitizer][clang-asan] a faster memory error detector. Can
|
||||||
detect out-of-bounds access to heap, stack, and globals, use after free, use
|
detect out-of-bounds access to heap, stack, and globals, use after free, use
|
||||||
|
|
@ -17,13 +17,12 @@ sanitizers please refer to [the unstable book](https://doc.rust-lang.org/unstabl
|
||||||
|
|
||||||
## How are sanitizers implemented in rustc?
|
## How are sanitizers implemented in rustc?
|
||||||
|
|
||||||
The implementation of sanitizers relies entirely on LLVM. It consists of
|
The implementation of sanitizers relies almost entirely on LLVM. The rustc is
|
||||||
compile time instrumentation passes and runtime libraries. The role rustc plays
|
an integration point for LLVM compile time instrumentation passes and runtime
|
||||||
in the implementation is limited to the execution of the following steps:
|
libraries. Highlight of the most important aspects of the implementation:
|
||||||
|
|
||||||
1. The sanitizer runtime libraries are part of the [compiler-rt] project, and
|
* The sanitizer runtime libraries are part of the [compiler-rt] project, and
|
||||||
[will be built as an LLVM subproject][sanitizer-build] when enabled in
|
[will be built on supported targets][sanitizer-build] when enabled in `config.toml`:
|
||||||
`config.toml`:
|
|
||||||
|
|
||||||
```toml
|
```toml
|
||||||
[build]
|
[build]
|
||||||
|
|
@ -32,27 +31,34 @@ in the implementation is limited to the execution of the following steps:
|
||||||
|
|
||||||
The runtimes are [placed into target libdir][sanitizer-copy].
|
The runtimes are [placed into target libdir][sanitizer-copy].
|
||||||
|
|
||||||
2. During LLVM code generation, the functions intended for instrumentation are
|
* During LLVM code generation, the functions intended for instrumentation are
|
||||||
[marked][sanitizer-attribute] with `SanitizeAddress`, `SanitizeMemory`, or
|
[marked][sanitizer-attribute] with appropriate LLVM attribute:
|
||||||
`SanitizeThread` attribute. Currently those attributes are applied in
|
`SanitizeAddress`, `SanitizeMemory`, or `SanitizeThread`. By default all
|
||||||
indiscriminate manner. but in principle they could be used to perform
|
functions are instrumented, but this behaviour can be changed with
|
||||||
instrumentation selectively.
|
`#[no_sanitize(...)]`.
|
||||||
|
|
||||||
3. The LLVM IR generated by rustc is instrumented by [dedicated LLVM
|
* The decision whether to perform instrumentation or not is possible only at a
|
||||||
|
function granularity. In the cases were those decision differ between
|
||||||
|
functions it might be necessary to inhibit inlining, both at [MIR
|
||||||
|
level][inline-mir] and [LLVM level][inline-llvm].
|
||||||
|
|
||||||
|
* The LLVM IR generated by rustc is instrumented by [dedicated LLVM
|
||||||
passes][sanitizer-pass], different for each sanitizer. Instrumentation
|
passes][sanitizer-pass], different for each sanitizer. Instrumentation
|
||||||
passes are invoked after optimization passes.
|
passes are invoked after optimization passes.
|
||||||
|
|
||||||
4. When producing an executable, the sanitizer specific runtime library is
|
* When producing an executable, the sanitizer specific runtime library is
|
||||||
[linked in][sanitizer-link]. The libraries are searched for in target libdir
|
[linked in][sanitizer-link]. The libraries are searched for in target libdir
|
||||||
relative to default system root, so that this process is not affected
|
relative to default system root, so that this process is not affected
|
||||||
by sysroot overrides used for example by cargo `-Zbuild-std` functionality.
|
by sysroot overrides used for example by cargo `-Zbuild-std` functionality.
|
||||||
|
|
||||||
[compiler-rt]: https://github.com/llvm/llvm-project/tree/master/compiler-rt
|
[compiler-rt]: https://github.com/llvm/llvm-project/tree/master/compiler-rt
|
||||||
[sanitizer-build]: https://github.com/rust-lang/rust/blob/87c3eedffba64830b67e54e75dd479f9fd83cc7d/src/bootstrap/native.rs#L220-L225
|
[sanitizer-build]: https://github.com/rust-lang/rust/blob/a29424a2265411dda7d7446516ac5fd7499e2b55/src/bootstrap/native.rs#L566-L624
|
||||||
[sanitizer-copy]: https://github.com/rust-lang/rust/blob/87c3eedffba64830b67e54e75dd479f9fd83cc7d/src/bootstrap/compile.rs#L269-L321
|
[sanitizer-copy]: https://github.com/rust-lang/rust/blob/a29424a2265411dda7d7446516ac5fd7499e2b55/src/bootstrap/compile.rs#L270-L304
|
||||||
[sanitizer-attribute]: https://github.com/rust-lang/rust/blob/1.38.0/src/librustc_codegen_llvm/declare.rs#L53-L66
|
[sanitizer-attribute]: https://github.com/rust-lang/rust/blob/a29424a2265411dda7d7446516ac5fd7499e2b55/src/librustc_codegen_llvm/attributes.rs#L49-L72
|
||||||
[sanitizer-pass]: https://github.com/rust-lang/rust/blob/1.38.0/src/librustc_codegen_ssa/back/write.rs#L406-L420
|
[inline-mir]: https://github.com/rust-lang/rust/blob/a29424a2265411dda7d7446516ac5fd7499e2b55/src/librustc_mir/transform/inline.rs#L232-L252
|
||||||
[sanitizer-link]: https://github.com/rust-lang/rust/blob/87c3eedffba64830b67e54e75dd479f9fd83cc7d/src/librustc_codegen_ssa/back/link.rs#L729-L770
|
[inline-llvm]: https://github.com/rust-lang/llvm-project/blob/9330ec5a4c1df5fc1fa62f993ed6a04da68cb040/llvm/include/llvm/IR/Attributes.td#L225-L241
|
||||||
|
[sanitizer-pass]: https://github.com/rust-lang/rust/blob/a29424a2265411dda7d7446516ac5fd7499e2b55/src/librustc_codegen_llvm/back/write.rs#L454-L475
|
||||||
|
[sanitizer-link]: https://github.com/rust-lang/rust/blob/a29424a2265411dda7d7446516ac5fd7499e2b55/src/librustc_codegen_ssa/back/link.rs#L748-L787
|
||||||
|
|
||||||
## Additional Information
|
## Additional Information
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue