Skip to content

Commit e30025a

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 e30025a

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ 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
50+
[working with other languages](#working-with-other-languages).
4851

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

0 commit comments

Comments
 (0)