Skip to content

Commit 7e3c51d

Browse files
committed
Instrument C / C++ in MemorySanitizer example
Modify the example to instrument C / C++ in addition to Rust, since it will be generally required (e.g., when using libbacktrace for symbolication). Additionally use rustc specific flag to track the origins of unitialized memory rather than LLVM one.
1 parent 3bf71b3 commit 7e3c51d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

+10-2
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ Shadow byte legend (one shadow byte represents 8 application bytes):
9696
## MemorySanitizer
9797
9898
Use of uninitialized memory. Note that we are using `-Zbuild-std` to instrument
99-
standard library, and passing `-msan-track-origins=2` to the LLVM to track
99+
the standard library, and passing `-Zsanitizer-track-origins` to track the
100100
origins of uninitialized memory:
101101
102102
```shell
@@ -111,7 +111,15 @@ fn main() {
111111
}
112112
}
113113

114-
$ env RUSTFLAGS="-Zsanitizer=memory -Cllvm-args=-msan-track-origins=2" cargo -Zbuild-std run --target x86_64-unknown-linux-gnu
114+
$ export \
115+
CC=clang \
116+
CXX=clang++ \
117+
CFLAGS='-fsanitize=memory -fsanitize-memory-track-origins' \
118+
CXXFLAGS='-fsanitize=memory -fsanitize-memory-track-origins' \
119+
RUSTFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins' \
120+
RUSTDOCFLAGS='-Zsanitizer=memory -Zsanitizer-memory-track-origins'
121+
$ cargo clean
122+
$ cargo -Zbuild-std run --target x86_64-unknown-linux-gnu
115123
==9416==WARNING: MemorySanitizer: use-of-uninitialized-value
116124
#0 0x560c04f7488a in core::fmt::num::imp::fmt_u64::haa293b0b098501ca $RUST/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/src/libcore/fmt/num.rs:202:16
117125
...

0 commit comments

Comments
 (0)