Description
We're building the rust toolchain with LLVM at HEAD (https://buildkite.com/llvm-project/rust-llvm-integrate-prototype/builds?branch=master). I'm looking into using sanitizers there. I noticed that building rust + llvm @ head produced a toolchain that is generally useable, but when using it to compile a sample binary with msan, running the binary fails with an msan error at core::hint::black_box (dummy=())
:
#0 __msan_warning_noreturn () at /example/rust/src/llvm-project/compiler-rt/lib/msan/msan.cpp:394
#1 0x00005642583215c4 in core::hint::black_box (dummy=()) at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core/src/hint.rs:226
#2 0x0000564258310e4b in std::sys_common::backtrace::__rust_begin_short_backtrace (f=0x5642583106b0 <foo::main>) at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/sys_common/backtrace.rs:124
#3 0x00005642583109a9 in std::rt::lang_start::{{closure}} () at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/rt.rs:166
#4 0x00005642584225a5 in core::ops::function::impls::<impl core::ops::function::FnOnce<A> for &F>::call_once (self=..., args=()) at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core/src/ops/function.rs:286
#5 0x00005642585799da in std::panicking::try::do_call (data=0x7ffcb0931f80 "\310#\223\260\374\177") at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/panicking.rs:483
#6 0x00005642585844aa in __rust_try ()
#7 0x00005642585790b7 in std::panicking::try (f=...) at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/panicking.rs:447
#8 0x0000564258419f9e in std::panic::catch_unwind (f=...) at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/panic.rs:137
#9 0x00005642584d5b5f in std::rt::lang_start_internal::{{closure}} () at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/rt.rs:148
#10 0x0000564258579d0f in std::panicking::try::do_call (data=0x7ffcb09321b0 "\310#\223\260\374\177") at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/panicking.rs:483
#11 0x00005642585844aa in __rust_try ()
#12 0x0000564258578957 in std::panicking::try (f=...) at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/panicking.rs:447
#13 0x000056425841a17e in std::panic::catch_unwind (f=...) at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/panic.rs:137
#14 0x00005642584d55af in std::rt::lang_start_internal (main=..., argc=1, argv=0x7ffcb0932528, sigpipe=2) at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/rt.rs:148
#15 0x00005642583108c6 in std::rt::lang_start (main=0x5642583106b0 <foo::main>, argc=1, argv=0x7ffcb0932528, sigpipe=2) at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/std/src/rt.rs:165
#16 0x000056425831077a in main ()
#17 0x00007f77d10ba083 in __libc_start_main (main=0x564258310720 <main>, argc=1, argv=0x7ffcb0932528, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>, stack_end=0x7ffcb0932518) at ../csu/libc-start.c:308
#18 0x00005642582a721e in _start ()
Since there are quite a few steps to reproduce this (we need to build rustc with llvm at head, then we need to make cargo pick this up etc), I set up https://github.com/krasimirgg/example-rust-llvm-head-16-msan-error/tree/main with a docker reproducer.
I checked that using the initial llvm-init-16 revision the problem doesn't occur. I'm currently bisecting over llvm revisions.
Activity
[-][MSAN when using rustc compiled with llvm at HEAD] Unexpected memory sanitizer error in core::hint::black_box (dummy=()) at /example/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core/src/hint.rs:226[/-][+][MSAN when using rustc compiled with llvm at HEAD] Unexpected memory sanitizer error in core::hint::black_box[/+]saethlin commentedon Oct 20, 2022
I have seen similar errors when running
criterion
's tests under ASan: https://asan.saethlin.dev/logs/criterion/0.4.0.htmlAs well as another benchmarking library which does the same
read_volatile
trick.Similarly, I do not understand why this happens, but I have not reported that anywhere because I have been completely unable to reproduce these ASan issues outside of my somewhat-complicated test harness: https://github.com/saethlin/miri-tools/blob/9799fd71de5d33f3dc360d94d3ffdb76b28ee841/src/main.rs#L218-L234
@rustbot label +A-LLVM
krasimirgg commentedon Nov 2, 2022
I digged a bit more. This started failing after LLVM commit llvm/llvm-project@e7bac3b
[msan] Convert Msan to ModulePass
.There's something wrong with the
core::hint::black_box
intrinsic:rust/library/core/src/hint.rs
Lines 225 to 227 in 822f8c2
That gets lowered into assembly here:
rust/compiler/rustc_codegen_llvm/src/intrinsic.rs
Lines 341 to 366 in 822f8c2
I set up an example here: https://github.com/krasimirgg/example-rust-llvm-head-16-msan-error, reproducible via
run_in_docker.sh penguin
. Consider this code:That produces this LLVM IR:
I asked around and was told MSAN is supposed to warn on stuff like this
(ptr undef)
and warns after that LLVM commit via the unconditional call to__msan_warning_noreturn
after the MSAN pass. I suspect before that LLVM commit something else in the pipeline was interfering with producing this warning.Rollup merge of rust-lang#104110 - krasimirgg:msan-16, r=nagisa
Rollup merge of rust-lang#104110 - krasimirgg:msan-16, r=nagisa
Rollup merge of rust-lang#104110 - krasimirgg:msan-16, r=nagisa
Rollup merge of rust-lang#104110 - krasimirgg:msan-16, r=nagisa
Rollup merge of rust-lang#104110 - krasimirgg:msan-16, r=nagisa
Rollup merge of rust-lang#104110 - krasimirgg:msan-16, r=nagisa
Rollup merge of rust-lang#104110 - krasimirgg:msan-16, r=nagisa
Rollup merge of rust-lang#104110 - krasimirgg:msan-16, r=nagisa
Rollup merge of rust-lang#104110 - krasimirgg:msan-16, r=nagisa
tmiasko commentedon Apr 15, 2023
Fixed in #104110.