Skip to content
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

dogfooding miri #282

Open
oli-obk opened this issue Aug 3, 2017 · 6 comments
Open

dogfooding miri #282

oli-obk opened this issue Aug 3, 2017 · 6 comments
Labels
A-tests Area: affects our test suite or CI C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out

Comments

@oli-obk
Copy link
Contributor

oli-obk commented Aug 3, 2017

This issue is just to document my process. It's ridiculously slow, but a lot of fun.

  1. Build yourself a rustc with -Zalways-encode-mir (stage2 build necessary)
  2. Add it to rustup (e.g. under the name stage2)
  3. Build miri in release mode with --verbose and RUSTFLAGS=-Zalways-encode-mir -Zmir-opt-level=3
  4. Copy all the --extern flags and the -L dependency=... flag
  5. RUSTFLAGS=-Zalways-encode-mir -Zmir-opt-level=3 rustup run stage2 cargo run --bin miri/bin/miri.rs --verbose -- -Zmir-opt-level=3 and append all the flags from 4. after that command line
  6. have patience
  7. rejoice
WARN:miri::fn_call: ignoring C ABI call: pthread_attr_init
WARN:miri::fn_call: ignoring C ABI call: pthread_self
WARN:miri::fn_call: ignoring C ABI call: pthread_getattr_np
WARN:miri::fn_call: ignoring C ABI call: pthread_attr_getstack
WARN:miri::fn_call: ignoring C ABI call: pthread_attr_destroy
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_lock
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_unlock
WARN:miri::fn_call: ignoring C ABI call: pthread_mutexattr_init
WARN:miri::fn_call: ignoring C ABI call: pthread_mutexattr_settype
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_init
WARN:miri::fn_call: ignoring C ABI call: pthread_mutexattr_destroy
WARN:miri::fn_call: ignoring C ABI call: pthread_condattr_init
WARN:miri::fn_call: ignoring C ABI call: pthread_condattr_setclock
WARN:miri::fn_call: ignoring C ABI call: pthread_cond_init
WARN:miri::fn_call: ignoring C ABI call: pthread_condattr_destroy
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_lock
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_unlock
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_lock
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_unlock
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_lock
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_unlock
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_lock
WARN:miri::fn_call: ignoring C ABI call: pthread_mutex_unlock
error: get_field_offset: can't handle type: getopts::HasArg, with layout: CEnum { discr: I8, signed: false, non_zero: false, min: 0, max: 2 }
    --> rust/rust/src/liballoc/vec.rs:1825:17
     |
1825 | /                 for element in iterator {
1826 | |                     ptr::write(ptr, element);
1827 | |                     ptr = ptr.offset(1);
1828 | |                     // NB can't overflow since we would have had to alloc the address space
1829 | |                     local_len.increment_len(1);
1830 | |                 }
     | |_________________^
     |
note: inside call to <std::vec::Vec<T> as std::vec::SpecExtend<T, I>><getopts::Opt, std::iter::Map<std::slice::Iter<getopts::OptGroup>, [closure@DefId { krate: CrateNum(12), node: DefIndex(2147483707) => getopts/12fdf82::{{impl}}[0]::parse[0]::{{closure}}[0] }]>>::spec_extend
    --> rust/rust/src/liballoc/vec.rs:1808:9
     |
1808 |         vector.spec_extend(iterator);
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to <std::vec::Vec<T> as std::vec::SpecExtend<T, I>><getopts::Opt, std::iter::Map<std::slice::Iter<getopts::OptGroup>, [closure@DefId { krate: CrateNum(12), node: DefIndex(2147483707) => getopts/12fdf82::{{impl}}[0]::parse[0]::{{closure}}[0] }]>>::from_iter
    --> rust/rust/src/liballoc/vec.rs:1695:9
     |
1695 |         <Self as SpecExtend<T, I::IntoIter>>::from_iter(iter.into_iter())
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to <std::vec::Vec<T> as std::iter::FromIterator<T>><getopts::Opt>::from_iter::<std::iter::Map<std::slice::Iter<getopts::OptGroup>, [closure@DefId { krate: CrateNum(12), node: DefIndex(2147483707) => getopts/12fdf82::{{impl}}[0]::parse[0]::{{closure}}[0] }]>>
    --> rust/rust/src/libcore/iter/iterator.rs:1302:9
     |
1302 |         FromIterator::from_iter(self)
     |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to <std::iter::Map<std::slice::Iter<getopts::OptGroup>, [closure@DefId { krate: CrateNum(12), node: DefIndex(2147483707) => getopts/12fdf82::{{impl}}[0]::parse[0]::{{closure}}[0] }]> as std::iter::Iterator>::collect::<std::vec::Vec<getopts::Opt>>
    --> /home/ws/ca8159/.cargo/registry/src/github.com-1ecc6299db9ec823/getopts-0.2.14/src/lib.rs:301:30
     |
301  |         let opts: Vec<Opt> = self.grps.iter().map(|x| x.long_to_short()).collect();
     |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to getopts::Options::parse::<&[std::string::String]>
    --> rust/rust/src/librustc_driver/lib.rs:1031:25
     |
1031 |     let matches = match options.parse(args) {
     |                         ^^^^^^^^^^^^^^^^^^^
note: inside call to rustc_driver::handle_options
    --> rust/rust/src/librustc_driver/lib.rs:170:25
     |
170  |     let matches = match handle_options(args) {
     |                         ^^^^^^^^^^^^^^^^^^^^
note: inside call to rustc_driver::run_compiler
    --> miri/bin/miri.rs:206:5
     |
206  |     rustc_driver::run_compiler(&args, &mut MiriCompilerCalls(RustcDefaultCalls), None, None);
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to main
    --> rust/rust/src/libcore/ops/function.rs:143:5
     |
143  |     extern "rust-call" fn call_once(self, args: Args) -> Self::Output;
     |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to <fn() as std::ops::FnOnce<()>>::call_once - shim(fn())
    --> rust/rust/src/libstd/sys_common/backtrace.rs:136:5
     |
136  |     f()
     |     ^^^
note: inside call to std::sys_common::backtrace::__rust_begin_short_backtrace::<fn(), ()>
    --> rust/rust/src/libstd/rt.rs:62:13
     |
62   |             ::sys_common::backtrace::__rust_begin_short_backtrace(main)
     |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: inside call to closure
    --> rust/rust/src/libstd/panicking.rs:479:40
     |
479  |             ptr::write(&mut (*data).r, f());
     |                                        ^^^
note: inside call to std::panicking::try::do_call::<[closure@DefId { krate: CrateNum(1), node: DefIndex(2147491399) => std/78549ff::rt[0]::lang_start[0]::{{closure}}[0] } 0:&fn()], ()>
    --> rust/rust/src/libstd/panicking.rs:475:5
     |
475  | /     fn do_call<F: FnOnce() -> R, R>(data: *mut u8) {
476  | |         unsafe {
477  | |             let data = data as *mut Data<F, R>;
478  | |             let f = ptr::read(&mut (*data).f);
479  | |             ptr::write(&mut (*data).r, f());
480  | |         }
481  | |     }
     | |_____^
note: inside call to std::panicking::try::<(), [closure@DefId { krate: CrateNum(1), node: DefIndex(2147491399) => std/78549ff::rt[0]::lang_start[0]::{{closure}}[0] } 0:&fn()]>
    --> rust/rust/src/libstd/panic.rs:361:9
     |
361  |         panicking::try(f)
     |         ^^^^^^^^^^^^^^^^^
note: inside call to std::panic::catch_unwind::<[closure@DefId { krate: CrateNum(1), node: DefIndex(2147491399) => std/78549ff::rt[0]::lang_start[0]::{{closure}}[0] } 0:&fn()], ()>
    --> rust/rust/src/libstd/rt.rs:61:19
     |
61   |           let res = panic::catch_unwind(|| {
     |  ___________________^
62   | |             ::sys_common::backtrace::__rust_begin_short_backtrace(main)
63   | |         });
     | |__________^
note: inside call to std::rt::lang_start
    --> rust/rust/src/libstd/rt.rs:34:1
     |
34   | / fn lang_start(main: fn(), argc: isize, argv: *const *const u8) -> isize {
35   | |     use panic;
36   | |     use sys;
37   | |     use sys_common;
...    |
74   | |     }
75   | | }
     | |_^

@RalfJung
Copy link
Member

RalfJung commented Aug 5, 2017

Build yourself a rustc with -Zalways-encode-mir (stage2 build necessary)

Where does that flag have to be added?

@oli-obk
Copy link
Contributor Author

oli-obk commented Aug 5, 2017

Good question. I turned it on unconditionally in the source... I should probably add a config.toml flag

@oli-obk oli-obk added the C-project Category: a larger project is being tracked here, usually with checkmarks for individual steps label Aug 10, 2017
@RalfJung RalfJung added the C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement label Nov 17, 2018
@RalfJung RalfJung added the A-tests Area: affects our test suite or CI label Mar 8, 2019
@RalfJung RalfJung removed the C-enhancement Category: a PR with an enhancement or an issue tracking an accepted enhancement label Apr 8, 2019
@RalfJung RalfJung added C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out and removed C-project Category: a larger project is being tracked here, usually with checkmarks for individual steps labels Jul 1, 2019
@saethlin
Copy link
Member

saethlin commented Jul 9, 2022

This issue is pretty old, but every few months someone on the community Discord will point out some dodgy code in rustc and everyone will clamor that we should run Miri on rustc or Miri on Miri. So I think it's fair to say that there is ambient interest in this, if it were made more accessible.

I looked over the instructions above and I think there is a bit missing.

  1. How does one provide -Zalways-encode-mir? The instructions mention a stage2 build, so does one set RUSTFLAGS_BOOTSTRAP or RUSTFLAGS_NOT_BOOTSTRAP? Both?
  2. What's up with the -Zmir-opt-level=3? I thought the whole point of Miri was to run on fully unoptimized MIR.
  3. Instructions mention cargo run --bin miri/bin/miri.rs which seems wrong? I've only ever build/run inside the repo with ./miri. Is this use of cargo run directly correct?

@oli-obk
Copy link
Contributor Author

oli-obk commented Jul 12, 2022

  1. How does one provide -Zalways-encode-mir? The instructions mention a stage2 build, so does one set RUSTFLAGS_BOOTSTRAP or RUSTFLAGS_NOT_BOOTSTRAP? Both?

only RUSTFLAGS_NOT_BOOTSTRAP should be necessary

2. What's up with the -Zmir-opt-level=3? I thought the whole point of Miri was to run on fully unoptimized MIR.

that was just me hoping it would run faster that way ^^

3. Instructions mention cargo run --bin miri/bin/miri.rs which seems wrong? I've only ever build/run inside the repo with ./miri. Is this use of cargo run directly correct?

yea that's really old. I think if you install miri in step 3 you can use cargo miri run inside the miri repository itself

@saethlin
Copy link
Member

With this in my config.toml:

extended = true
tools = ["cargo", "clippy", "rustfmt", "src", "miri"]

I ran this to build rustc:

RUSTFLAGS_NOT_BOOTSTRAP x build --stage 2

Then based on the contents of the miri script, I ran

export RUSTFLAGS="-C link-args=-Wl,-rpath,/home/ben/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib"

Then tried to

cargo +stage2 miri run --bin miri --verbose

And all I see is:

     Running `/home/ben/.cargo/bin/cargo-miri /home/ben/.cargo/bin/miri --crate-name miri --edition=2021 src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="default"' --cfg 'feature="stack-cache"' -C metadata=24c414736c1dfa74 -C extra-filename=-24c414736c1dfa74 --out-dir /home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps --target x86_64-unknown-linux-gnu -C linker=clang -C incremental=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/incremental -L dependency=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps -L dependency=/home/ben/miri/target/miri/debug/deps --extern env_logger=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/libenv_logger-6f6d8da2b7ee6306.rmeta --extern getrandom=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/libgetrandom-d277bf60883b4b86.rmeta --extern libc=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/liblibc-ed6a90483caf3f1a.rmeta --extern libffi=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/liblibffi-f56d2af76a51dbca.rmeta --extern libloading=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/liblibloading-7816860288464c34.rmeta --extern log=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/liblog-fea090e2364200e8.rmeta --extern measureme=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/libmeasureme-25a6023984e08d37.rmeta --extern rand=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/librand-f84f5437562e1f0a.rmeta --extern rustc_workspace_hack=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/librustc_workspace_hack-2ee5e29a45fa7105.rmeta --extern shell_escape=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/libshell_escape-f71c5889ef27c6e3.rmeta --extern smallvec=/home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/deps/libsmallvec-e028de92ed4a41db.rmeta -C link-args=-Wl,-rpath,/home/ben/rust/build/x86_64-unknown-linux-gnu/stage2/lib/rustlib/x86_64-unknown-linux-gnu/lib -L /home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/build/libffi-sys-b8d8cd4be8d71230/out/libffi-root/lib -L /home/ben/miri/target/miri/x86_64-unknown-linux-gnu/debug/build/libffi-sys-b8d8cd4be8d71230/out/libffi-root/lib64`
error[E0463]: can't find crate for `rustc_apfloat`
  --> src/lib.rs:42:1
   |
42 | extern crate rustc_apfloat;
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't find crate
   |
   = help: maybe you need to install the missing components with: `rustup component add rust-src rustc-dev llvm-tools-preview`

and more missing rustc_ crates then a cascade of errors from missing them.

There is for example a rustc_apfloat rlib in the directory mentioned in my RUSTFLAGS. Do you have any idea what's going on here?

@bjorn3
Copy link
Member

bjorn3 commented Aug 27, 2022

The rustc-dev compoment needs to be installed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tests Area: affects our test suite or CI C-proposal Category: a proposal for something we might want to do, or maybe not; details still being worked out
Projects
None yet
Development

No branches or pull requests

4 participants