Skip to content

Commit e17f00d

Browse files
committed
Add section to sanitizer doc for -Zexternal-clangrt
After spending a week looking for answers to how to do the very thing this flag lets me do, it felt appropriate to document it where I would've expected it to be.
1 parent af4a5a1 commit e17f00d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/doc/unstable-book/src/compiler-flags/sanitizer.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ To enable a sanitizer compile with `-Zsanitizer=address`, `-Zsanitizer=cfi`,
4545
`-Zsanitizer=dataflow`,`-Zsanitizer=hwaddress`, `-Zsanitizer=leak`,
4646
`-Zsanitizer=memory`, `-Zsanitizer=memtag`, `-Zsanitizer=shadow-call-stack`, or
4747
`-Zsanitizer=thread`. You might also need the `--target` and `build-std` flags.
48+
If you're working with other languages that are also instrumented with sanitizers,
49+
you might need the `external-clangrt` flag. See the section on [working with other languages](#working-with-other-languages).
4850

4951
Example:
5052
```shell
@@ -853,6 +855,18 @@ functionality][build-std].
853855
854856
[build-std]: ../../cargo/reference/unstable.html#build-std
855857
858+
# Working with other languages
859+
860+
Sanitizers rely on compiler runtime libraries to function properly. Rust links
861+
in its own compiler runtime which might conflict with runtimes required by
862+
languages such as C++. Since Rust's runtime doesn't always contain the symbols
863+
required by C++ instrumented code, you might need to skip linking it so another
864+
runtime can be linked instead.
865+
866+
A separate unstable option `-Zexternal-clangrt` can be used to make rustc skip
867+
linking the compiler runtime for the sanitizer. This will require you to link
868+
in an external runtime, such as from clang instead.
869+
856870
# Build scripts and procedural macros
857871
858872
Use of sanitizers together with build scripts and procedural macros is

0 commit comments

Comments
 (0)