-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation fault when building instrumented std and with memory sanitizer #68548
Comments
New rustc (rustc 1.42.0-nightly (6d3f4e0 2020-01-25)) doesn't segfault. % env RUSTFLAGS="-Zsanitizer=memory -Cllvm-args=-msan-track-origins=2" cargo -Zbuild-std r --target x86_64-unknown-linux-gnu
Compiling check v0.1.0 (/home/lzutao/fork/rust/check)
Finished dev [unoptimized + debuginfo] target(s) in 0.16s
Running `/home/lzutao/.cargo/target_dir/x86_64-unknown-linux-gnu/debug/check`
Uninitialized bytes in __interceptor_memchr at offset 0 inside [0x701000000000, 4)
==16270==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x5558c424730e in std::sys::unix::memchr::memchr::h093351bf413e1811 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/sys/unix/memchr.rs:6:8
#1 0x5558c424730e in std::memchr::memchr::h611c7bcd6977d5c8 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/memchr.rs:25:4
#2 0x5558c424730e in std::ffi::c_str::CString::_new::hae9b6987fec5f7fd /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/ffi/c_str.rs:354:14
#3 0x5558c424730e in std::ffi::c_str::CString::new::h1ea624224271aaf7 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/ffi/c_str.rs:350:8
#4 0x5558c424730e in std::thread::Thread::new::_$u7b$$u7b$closure$u7d$$u7d$::h1c0ee72b60a277c3 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/thread/mod.rs:1139:25
#5 0x5558c424730e in core::option::Option$LT$T$GT$::map::hcc879affbaa7fe1d /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libcore/option.rs:450:28
#6 0x5558c424730e in std::thread::Thread::new::h50a07a669fcb2430 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/thread/mod.rs:1139:12
#7 0x5558c424dbf8 in std::rt::lang_start_internal::h9d8db41cd41d5c82 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/rt.rs:44:21
#8 0x5558c42441aa in std::rt::lang_start::h49972300d46b5330 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/rt.rs:67:4
#9 0x5558c42453ec in main (/home/lzutao/.cargo/target_dir/x86_64-unknown-linux-gnu/debug/check+0x913ec)
#10 0x7f01d935d09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
#11 0x5558c41e8029 in _start (/home/lzutao/.cargo/target_dir/x86_64-unknown-linux-gnu/debug/check+0x34029)
Uninitialized value was created by a heap allocation
#0 0x5558c41f2f9d in malloc /checkout/src/llvm-project/compiler-rt/lib/msan/msan_interceptors.cc:916:3
#1 0x5558c424dbbb in alloc::alloc::alloc::hcdcb9b2beecd2386 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/alloc.rs:81:4
#2 0x5558c424dbbb in _$LT$alloc..alloc..Global$u20$as$u20$core..alloc..Alloc$GT$::alloc::h6874ec33458db448 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/alloc.rs:169:21
#3 0x5558c424dbbb in alloc::raw_vec::RawVec$LT$T$C$A$GT$::allocate_in::h6551de8396f43b6a /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/raw_vec.rs:88:73
#4 0x5558c424dbbb in alloc::raw_vec::RawVec$LT$T$GT$::with_capacity::ha9f3e23fbbb76ceb /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/raw_vec.rs:140:8
#5 0x5558c424dbbb in alloc::vec::Vec$LT$T$GT$::with_capacity::h07a6336c6cdafeb1 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/vec.rs:355:19
#6 0x5558c424dbbb in alloc::slice::hack::to_vec::h9cacb4bd68db4f4e /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/slice.rs:158:25
#7 0x5558c424dbbb in alloc::slice::_$LT$impl$u20$$u5b$T$u5d$$GT$::to_vec::hb97d0cd8f5bb7f3b /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/slice.rs:394:8
#8 0x5558c424dbbb in alloc::slice::_$LT$impl$u20$alloc..borrow..ToOwned$u20$for$u20$$u5b$T$u5d$$GT$::to_owned::h2141d6531caed0bc /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/slice.rs:727:8
#9 0x5558c424dbbb in alloc::str::_$LT$impl$u20$alloc..borrow..ToOwned$u20$for$u20$str$GT$::to_owned::h8c20d4eb37699c47 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/str.rs:205:45
#10 0x5558c424dbbb in std::rt::lang_start_internal::h9d8db41cd41d5c82 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/rt.rs:44:38
SUMMARY: MemorySanitizer: use-of-uninitialized-value /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/sys/unix/memchr.rs:6:8 in std::sys::unix::memchr::memchr::h093351bf413e1811
Exiting cc @nagisa |
Looks like a bug in cargo. Notice difference between $ export env RUSTFLAGS="-Zsanitizer=memory -Zsanitizer-memory-track-origins"
$ cargo -Zbuild-std run --target x86_64-unknown-linux-gnu
Finished dev [unoptimized + debuginfo] target(s) in 0.10s
Running `target/x86_64-unknown-linux-gnu/debug/foo`
Hello, world!
$ cargo -Zbuild-std r --target x86_64-unknown-linux-gnu
Finished dev [unoptimized + debuginfo] target(s) in 0.01s
Running `target/x86_64-unknown-linux-gnu/debug/foo`
Uninitialized bytes in __interceptor_memchr at offset 0 inside [0x701000000000, 4)
==5321==WARNING: MemorySanitizer: use-of-uninitialized-value
... |
Yeah. It's super weird. Notice the different: % env RUSTFLAGS="-Zsanitizer=memory -Cllvm-args=-msan-track-origins=2" cargo -Zbuild-std run
Finished dev [unoptimized + debuginfo] target(s) in 0.08s
Running `/home/lzutao/.cargo/target_dir/x86_64-unknown-linux-gnu/debug/check`
zsh: segmentation fault env RUSTFLAGS="-Zsanitizer=memory -Cllvm-args=-msan-track-origins=2" cargo
% env RUSTFLAGS="-Zsanitizer=memory -Cllvm-args=-msan-track-origins=2" cargo -Zbuild-std r
Finished dev [unoptimized + debuginfo] target(s) in 0.00s
Running `/home/lzutao/.cargo/target_dir/x86_64-unknown-linux-gnu/debug/check`
Uninitialized bytes in __interceptor_memchr at offset 0 inside [0x701000000000, 4)
==31792==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x55eb5be5430e in std::sys::unix::memchr::memchr::h093351bf413e1811 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/sys/unix/memchr.rs:6:8
#1 0x55eb5be5430e in std::memchr::memchr::h611c7bcd6977d5c8 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/memchr.rs:25:4
#2 0x55eb5be5430e in std::ffi::c_str::CString::_new::hae9b6987fec5f7fd /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/ffi/c_str.rs:354:14
#3 0x55eb5be5430e in std::ffi::c_str::CString::new::h1ea624224271aaf7 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/ffi/c_str.rs:350:8
#4 0x55eb5be5430e in std::thread::Thread::new::_$u7b$$u7b$closure$u7d$$u7d$::h1c0ee72b60a277c3 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/thread/mod.rs:1139:25
#5 0x55eb5be5430e in core::option::Option$LT$T$GT$::map::hcc879affbaa7fe1d /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libcore/option.rs:450:28
#6 0x55eb5be5430e in std::thread::Thread::new::h50a07a669fcb2430 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/thread/mod.rs:1139:12
#7 0x55eb5be5abf8 in std::rt::lang_start_internal::h9d8db41cd41d5c82 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/rt.rs:44:21
#8 0x55eb5be511aa in std::rt::lang_start::h49972300d46b5330 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/rt.rs:67:4
#9 0x55eb5be523ec in main (/home/lzutao/.cargo/target_dir/x86_64-unknown-linux-gnu/debug/check+0x913ec)
#10 0x7fcb662fe09a in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2409a)
#11 0x55eb5bdf5029 in _start (/home/lzutao/.cargo/target_dir/x86_64-unknown-linux-gnu/debug/check+0x34029)
Uninitialized value was created by a heap allocation
#0 0x55eb5bdfff9d in malloc /checkout/src/llvm-project/compiler-rt/lib/msan/msan_interceptors.cc:916:3
#1 0x55eb5be5abbb in alloc::alloc::alloc::hcdcb9b2beecd2386 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/alloc.rs:81:4
#2 0x55eb5be5abbb in _$LT$alloc..alloc..Global$u20$as$u20$core..alloc..Alloc$GT$::alloc::h6874ec33458db448 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/alloc.rs:169:21
#3 0x55eb5be5abbb in alloc::raw_vec::RawVec$LT$T$C$A$GT$::allocate_in::h6551de8396f43b6a /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/raw_vec.rs:88:73
#4 0x55eb5be5abbb in alloc::raw_vec::RawVec$LT$T$GT$::with_capacity::ha9f3e23fbbb76ceb /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/raw_vec.rs:140:8
#5 0x55eb5be5abbb in alloc::vec::Vec$LT$T$GT$::with_capacity::h07a6336c6cdafeb1 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/vec.rs:355:19
#6 0x55eb5be5abbb in alloc::slice::hack::to_vec::h9cacb4bd68db4f4e /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/slice.rs:158:25
#7 0x55eb5be5abbb in alloc::slice::_$LT$impl$u20$$u5b$T$u5d$$GT$::to_vec::hb97d0cd8f5bb7f3b /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/slice.rs:394:8
#8 0x55eb5be5abbb in alloc::slice::_$LT$impl$u20$alloc..borrow..ToOwned$u20$for$u20$$u5b$T$u5d$$GT$::to_owned::h2141d6531caed0bc /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/slice.rs:727:8
#9 0x55eb5be5abbb in alloc::str::_$LT$impl$u20$alloc..borrow..ToOwned$u20$for$u20$str$GT$::to_owned::h8c20d4eb37699c47 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/liballoc/str.rs:205:45
#10 0x55eb5be5abbb in std::rt::lang_start_internal::h9d8db41cd41d5c82 /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/rt.rs:44:38
SUMMARY: MemorySanitizer: use-of-uninitialized-value /rustc/6d3f4e0aab3e36ceb8b83d1e9467514685f6b751/src/libstd/sys/unix/memchr.rs:6:8 in std::sys::unix::memchr::memchr::h093351bf413e1811
Exiting
[alias]
br = 'build --release'
rr = 'run --release'
f = 'fmt' |
cc @ehuss (cargo team member for #68548 (comment)) |
The segmentation fault is probably a duplicate of #68367. Especially if it can be avoided by removing track-origins functionality or when using a newer rustc. |
I was using today nightly. |
Things you can try:
|
Seems like my manually installed llvm has problems. It missed the compiler-rt toolchain |
I am still getting this on nightly on AmazonLinux2. # compiling uutils/coreutils
# rustc 1.52.0-nightly (fe1bf8e05 2021-02-23)
RUSTFLAGS=-Zsanitizer=memory MSAN_OPTIONS=verbosity=2 cargo test --target=x86_64-unknown-linux-gnu
...
Running `/root/github/meta_coreutils/coreutils/target/x86_64-unknown-linux-gnu/debug/deps/coreutils-641830cd6c0f495f`
==363==MemorySanitizer: failed to intercept '__isoc99_printf'
'==363==MemorySanitizer: failed to intercept '__isoc99_sprintf'
'==363==MemorySanitizer: failed to intercept '__isoc99_snprintf'
'==363==MemorySanitizer: failed to intercept '__isoc99_fprintf'
'==363==MemorySanitizer: failed to intercept '__isoc99_vprintf'
'==363==MemorySanitizer: failed to intercept '__isoc99_vsprintf'
'==363==MemorySanitizer: failed to intercept '__isoc99_vsnprintf'
'==363==MemorySanitizer: failed to intercept '__isoc99_vfprintf'
'==363==MemorySanitizer: failed to intercept 'crypt'
'==363==MemorySanitizer: failed to intercept 'crypt_r'
'==363==Installed the sigaction for signal 11
==363==Installed the sigaction for signal 7
==363==Installed the sigaction for signal 8
__msan_init 0x5562988b87b0
app-1: 0 - ffffffffff
shadow-2: 10000000000 - fffffffffff
invalid: 100000000000 - 10ffffffffff
origin-2: 110000000000 - 1fffffffffff
shadow-3: 200000000000 - 2fffffffffff
origin-3: 300000000000 - 3fffffffffff
invalid: 400000000000 - 4fffffffffff
shadow-1: 500000000000 - 50ffffffffff
app-2: 510000000000 - 5fffffffffff
origin-1: 600000000000 - 60ffffffffff
invalid: 610000000000 - 6fffffffffff
app-3: 700000000000 - 7fffffffffff
==363==Using llvm-symbolizer found at: /usr/bin/llvm-symbolizer
MemorySanitizer init done
Uninitialized bytes in __interceptor_memchr at offset 0 inside [0x701000000000, 4)
Shadow map of [0x201000000000, 0x201000000004), 4 bytes:
0x201000000000: ffffffff ........ ........ ........
==363==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x55629896c82a in std::sys::unix::memchr::memchr::h25e994819b34ae60 /rustc/fe1bf8e05c39bdcc73fc09e246b7209444e389bc/library/std/src/sys/unix/memchr.rs:6:9
#1 0x55629896c82a in std::memchr::memchr::hbfa59afe241958cf /rustc/fe1bf8e05c39bdcc73fc09e246b7209444e389bc/library/std/src/memchr.rs:28:5
#2 0x55629896c82a in std::ffi::c_str::CString::_new::h1135c0ef219c53d5 /rustc/fe1bf8e05c39bdcc73fc09e246b7209444e389bc/library/std/src/ffi/c_str.rs:405:15
#3 0x55629896c82a in std::ffi::c_str::CString::new::hfad134e936e82551 /rustc/fe1bf8e05c39bdcc73fc09e246b7209444e389bc/library/std/src/ffi/c_str.rs:401:9
#4 0x55629896c82a in std::thread::Thread::new::_$u7b$$u7b$closure$u7d$$u7d$::hd79cbaf3f8b96dcf /rustc/fe1bf8e05c39bdcc73fc09e246b7209444e389bc/library/std/src/thread/mod.rs:1068:26
#5 0x55629896c82a in core::option::Option$LT$T$GT$::map::h6bf62377f786127c /rustc/fe1bf8e05c39bdcc73fc09e246b7209444e389bc/library/core/src/option.rs:487:29
#6 0x55629896c82a in std::thread::Thread::new::hdef806dddada2f31 /rustc/fe1bf8e05c39bdcc73fc09e246b7209444e389bc/library/std/src/thread/mod.rs:1068:13
#7 0x556298977b45 in std::rt::lang_start_internal::hc92e27a69d75de2a /rustc/fe1bf8e05c39bdcc73fc09e246b7209444e389bc/library/std/src/rt.rs:44:22
#8 0x5562989151cb in std::rt::lang_start::hd7b49f57b17ff86a /root/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/rt.rs:65:5
#9 0x556298914b31 in main (/root/github/meta_coreutils/coreutils/target/x86_64-unknown-linux-gnu/debug/deps/coreutils-641830cd6c0f495f+0x73b31)
#10 0x7f20421ba069 in __libc_start_main (/lib64/libc.so.6+0x21069)
#11 0x5562988b81d9 in _start (/root/github/meta_coreutils/coreutils/target/x86_64-unknown-linux-gnu/debug/deps/coreutils-641830cd6c0f495f+0x171d9)
SUMMARY: MemorySanitizer: use-of-uninitialized-value /rustc/fe1bf8e05c39bdcc73fc09e246b7209444e389bc/library/std/src/sys/unix/memchr.rs:6:9 in std::sys::unix::memchr::memchr::h25e994819b34ae60
Exiting
error: test failed, to rerun pass '--bin coreutils'
-bash-4.2# /usr/bin/llvm-symbolizer --version
LLVM (http://llvm.org/):
LLVM version 7.0.1
Optimized build.
Default target: x86_64-unknown-linux-gnu
Host CPU: skylake |
It is even worse under Kali Rolling. (These are WSL2 runs if it matters) The symbols aren't expanded to source locations. Finished test [unoptimized + debuginfo] target(s) in 3m 55s
Running target/x86_64-unknown-linux-gnu/debug/deps/coreutils-641830cd6c0f495f
==14228==MemorySanitizer: failed to intercept '__isoc99_printf'
'==14228==MemorySanitizer: failed to intercept '__isoc99_sprintf'
'==14228==MemorySanitizer: failed to intercept '__isoc99_snprintf'
'==14228==MemorySanitizer: failed to intercept '__isoc99_fprintf'
'==14228==MemorySanitizer: failed to intercept '__isoc99_vprintf'
'==14228==MemorySanitizer: failed to intercept '__isoc99_vsprintf'
'==14228==MemorySanitizer: failed to intercept '__isoc99_vsnprintf'
'==14228==MemorySanitizer: failed to intercept '__isoc99_vfprintf'
'==14228==MemorySanitizer: failed to intercept 'crypt'
'==14228==MemorySanitizer: failed to intercept 'crypt_r'
'==14228==Installed the sigaction for signal 11
==14228==Installed the sigaction for signal 7
==14228==Installed the sigaction for signal 8
__msan_init 0x559a9a5aa740
app-1: 0 - ffffffffff
shadow-2: 10000000000 - fffffffffff
invalid: 100000000000 - 10ffffffffff
origin-2: 110000000000 - 1fffffffffff
shadow-3: 200000000000 - 2fffffffffff
origin-3: 300000000000 - 3fffffffffff
invalid: 400000000000 - 4fffffffffff
shadow-1: 500000000000 - 50ffffffffff
app-2: 510000000000 - 5fffffffffff
origin-1: 600000000000 - 60ffffffffff
invalid: 610000000000 - 6fffffffffff
app-3: 700000000000 - 7fffffffffff
MemorySanitizer init done
Uninitialized bytes in __interceptor_memchr at offset 0 inside [0x701000000000, 4)
Shadow map of [0x201000000000, 0x201000000004), 4 bytes:
0x201000000000: ffffffff ........ ........ ........
==14228==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x559a9a65e7ba (/home/crb002/github/coreutils/target/x86_64-unknown-linux-gnu/debug/deps/coreutils-641830cd6c0f495f+0xcb7ba)
#1 0x559a9a669ad5 (/home/crb002/github/coreutils/target/x86_64-unknown-linux-gnu/debug/deps/coreutils-641830cd6c0f495f+0xd6ad5)
#2 0x559a9a60715b (/home/crb002/github/coreutils/target/x86_64-unknown-linux-gnu/debug/deps/coreutils-641830cd6c0f495f+0x7415b)
#3 0x559a9a606ac1 (/home/crb002/github/coreutils/target/x86_64-unknown-linux-gnu/debug/deps/coreutils-641830cd6c0f495f+0x73ac1)
#4 0x7f3383b7bd09 (/lib/x86_64-linux-gnu/libc.so.6+0x26d09)
#5 0x559a9a5aa169 (/home/crb002/github/coreutils/target/x86_64-unknown-linux-gnu/debug/deps/coreutils-641830cd6c0f495f+0x17169)
SUMMARY: MemorySanitizer: use-of-uninitialized-value (/home/crb002/github/coreutils/target/x86_64-unknown-linux-gnu/debug/deps/coreutils-641830cd6c0f495f+0xcb7ba)
Exiting
error: test failed, to rerun pass '--bin coreutils'
|
@chadbrewbaker Please open an separate issue since this issue closed, your comments would be lost. |
cc #68539
Consider this snippet:
I got segmentation fault when building instrumented std:
Meta:
Originally posted by @lzutao in #68539 (comment)
The text was updated successfully, but these errors were encountered: