Commit Graph

5487 Commits

Author SHA1 Message Date
bors
05fdec916a Auto merge of #1844 - hyd-dev:rustup, r=RalfJung
Update for `TyCtxt::crates()` change

cc rust-lang/rust#86792
2021-07-02 08:49:49 +00:00
hyd-dev
76fe48543c
Update for TyCtxt::crates() change 2021-07-02 16:08:27 +08:00
bors
61605ebde2 Auto merge of #1843 - RalfJung:rustup, r=RalfJung
rustup

Cc https://github.com/rust-lang/rust/issues/86723
2021-06-29 18:48:08 +00:00
Ralf Jung
e33bf695db rustup 2021-06-29 20:47:28 +02:00
bors
4933e280b2 Auto merge of #1841 - RalfJung:debug, r=RalfJung
use exhaustive struct match for manual Debug impl
2021-06-20 17:47:42 +00:00
Ralf Jung
7b2d2cfa46 use exhaustive struct match for manual Debug impl 2021-06-20 19:33:05 +02:00
bors
23f05fc603 Auto merge of #1840 - hyd-dev:rustup, r=RalfJung
Update backtraces

(rust-lang/rust#86034 changed them.)

cc rust-lang/rust#86474
2021-06-20 09:54:48 +00:00
hyd-dev
2644647053
Update backtraces 2021-06-20 15:12:11 +08:00
bors
5b7f1f919b Auto merge of #1839 - RalfJung:rustup, r=RalfJung
rustup

Cc https://github.com/rust-lang/rust/issues/86409
2021-06-17 18:53:16 +00:00
Ralf Jung
7f3dd37f1e rustup 2021-06-17 20:52:35 +02:00
bors
35af23b6a9 Auto merge of #1833 - hyd-dev:82261, r=RalfJung
Filter out items other than non-generic functions and statics in our version of `exported_symbols`

[`#[no_mangle]` on a `use` item](https://docs.rs/brotli-decompressor/2.3.1/src/brotli_decompressor/ffi/mod.rs.html#3-5) can make Miri ICE when compiling a dependency (rust-lang/rust#86261):
```rs
#[no_mangle]
use std::{thread,panic, io, boxed, any, string};
```

<details>

```
error: internal compiler error: compiler/rustc_middle/src/ty/mod.rs:1650:13: item_name: no name for DefPath { data: [DisambiguatedDefPathData { data: Misc, disambiguator: 14 }], krate: crate0 }

thread 'rustc' panicked at 'Box<dyn Any>', compiler/rustc_errors/src/lib.rs:1007:9
stack backtrace:
   0: std::panicking::begin_panic
   1: std::panic::panic_any
   2: rustc_errors::HandlerInner::bug
   3: rustc_errors::Handler::bug
   4: rustc_middle::ty::context::tls::with_opt
   5: rustc_middle::util:🐛:opt_span_bug_fmt
   6: rustc_middle::util:🐛:bug_fmt
   7: rustc_middle::ty::<impl rustc_middle::ty::context::TyCtxt>::item_name
   8: rustc_symbol_mangling::symbol_name_provider
   9: rustc_query_impl::<impl rustc_query_system::query::config::QueryAccessors<rustc_query_impl::plumbing::QueryCtxt> for rustc_query_impl::queries::symbol_name>::compute
  10: rustc_query_system::query::plumbing::get_query_impl
  11: <rustc_query_impl::Queries as rustc_middle::ty::query::QueryEngine>::symbol_name
  12: rustc_middle::middle::exported_symbols::ExportedSymbol::symbol_name_for_local_instance
  13: rustc_codegen_ssa:🔙:symbol_export::symbol_name_for_instance_in_crate
  14: rustc_codegen_ssa:🔙:linker::exported_symbols
  15: <core::iter::adapters::map::Map<I,F> as core::iter::traits::iterator::Iterator>::fold
  16: rustc_codegen_ssa:🔙:linker::LinkerInfo::new
  17: rustc_codegen_ssa:🔙:write::start_async_codegen
  18: <rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::CodegenBackend>::codegen_crate
  19: rustc_interface::passes::QueryContext::enter
  20: rustc_interface::queries::Queries::ongoing_codegen
  21: rustc_interface::queries::<impl rustc_interface::interface::Compiler>::enter
  22: rustc_span::with_source_map
  23: rustc_interface::interface::create_compiler_and_run
  24: rustc_span::with_session_globals
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

note: the compiler unexpectedly panicked. this is a bug.

note: we would appreciate a bug report: https://github.com/rust-lang/rust/issues/new?labels=C-bug%2C+I-ICE%2C+T-compiler&template=ice.md

note: rustc 1.54.0-nightly (a50d72158 2021-06-08) running on x86_64-unknown-linux-gnu

note: compiler flags: -C embed-bitcode=no -C debuginfo=1 --crate-type lib

note: some of the compiler flags provided by cargo are hidden

query stack during panic:
#0 [symbol_name] computing the symbol for `{misc#14}`
end of query stack
```
</details>

This might be because in #1776, we override the `exported_symbols` query, and our version of `exported_symbols` can return a `use` item which don't have a name if the `use` item is tagged with `#[no_mangle]`, and then:
- `rustc_codegen_ssa:🔙:symbol_export::symbol_name_for_instance_in_crate` is called for for every `exported_symbols`: fb3ea63d9b/compiler/rustc_codegen_ssa/src/back/linker.rs (L1300-L1304)
- it calls `rustc_middle::middle::exported_symbols::ExportedSymbol::symbol_name_for_local_instance`: fb3ea63d9b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs (L412)
- which calls `rustc_symbol_mangling::symbol_name_provider`: fb3ea63d9b/compiler/rustc_middle/src/middle/exported_symbols.rs (L37-L44)
- which calls `item_name`: fb3ea63d9b/compiler/rustc_symbol_mangling/src/lib.rs (L216), which triggers the ICE

It might also be problematic for d39f0c64b8/src/shims/foreign_items.rs (L165) which also uses `item_name`, but Miri cannot compile the dependency, so that code can't be reached.

Therefore, this PR makes `exported_symbols` filter out all items that are not functions or statics, so all items returned will have a name, which avoids the ICE (I have tested it in the https://github.com/jorgecarleitao/arrow2 repository).
(This PR also includes a commit that fixes a small (unrelated) bug for `#[no_mangle]` on associated functions -- I found that because I notice `#[no_mangle]` is supported on associated functions and they should not be filtered out in `exported_symbols`.)

Fixes (when the submodule is bumped) rust-lang/rust#86261.
2021-06-15 10:07:24 +00:00
bors
486b5dfe74 Auto merge of #1832 - hyd-dev:1776-follow-up, r=RalfJung
Report an error if a `#[no_mangle]`/`#[export_name = ...]` function has the same symbol name as a built-in shim

Implements https://github.com/rust-lang/miri/pull/1776#issuecomment-821322605.

The error looks like this:
```
error: found `malloc` symbol definition that clashes with a built-in shim
  --> tests/compile-fail/function_calls/exported_symbol_shim_clashing.rs:12:9
   |
12 |         malloc(0);
   |         ^^^^^^^^^ found `malloc` symbol definition that clashes with a built-in shim
   |
help: the `malloc` symbol is defined here

  --> tests/compile-fail/function_calls/exported_symbol_shim_clashing.rs:2:1
   |
2  | / extern "C" fn malloc(_: usize) -> *mut std::ffi::c_void {
3  | |     //~^ HELP the `malloc` symbol is defined here
4  | |     unreachable!()
5  | | }
   | |_^
   = note: inside `main` at tests/compile-fail/function_calls/exported_symbol_shim_clashing.rs:12:9
```

This does not implement "better error messages than we do currently for arg/ABI mismatches" in https://github.com/rust-lang/miri/pull/1776#issuecomment-821343175 -- I failed to remove all `check_arg_count()` and `check_abi()` (they are still used in `src/shims/intrinsics.rs` and `call_dlsym()`) and they don't receive the name of the shim.
2021-06-15 09:53:05 +00:00
bors
042db78ab3 Auto merge of #1836 - hyd-dev:rustup, r=RalfJung
Rustup

cc https://github.com/rust-lang/rust/issues/86316

(I beat `@lqd` to this!)
2021-06-15 09:38:44 +00:00
hyd-dev
dfd7a6d5aa
Rustup 2021-06-15 16:12:47 +08:00
hyd-dev
aaaa142dc1
Rename all link_name_sym to link_name and remove the only remaining let link_name = link_name_sym.as_str() 2021-06-15 01:24:09 +08:00
hyd-dev
9011524454
Remove strip_linker_suffix 2021-06-15 01:16:38 +08:00
hyd-dev
a67a65359f
Only pass Symbol to emulate_foreign_item_by_name 2021-06-15 00:43:15 +08:00
hyd-dev
34603e586f
Add whitespace 2021-06-14 23:38:15 +08:00
hyd-dev
d1e72d0854
Check argument count for CreateThread 2021-06-14 23:01:06 +08:00
hyd-dev
89c722ac32
Add some comments about check_shim 2021-06-14 22:53:17 +08:00
hyd-dev
da2ed6f768
Don't report UB for #[no_mangle] on associated functions 2021-06-14 20:58:54 +08:00
hyd-dev
99467349f2
Do not return DefId that doesn't have exported symbol in exported_symbols 2021-06-14 20:55:27 +08:00
hyd-dev
49a8f002a0
let-bind exp_abi of "exit" | "ExitProcess" 2021-06-11 15:53:58 +08:00
hyd-dev
e46aab5816
Use check_shim() for abort 2021-06-11 15:47:12 +08:00
bors
d39f0c64b8 Auto merge of #1831 - hyd-dev:emulate-by-name-result, r=RalfJung
Fix the wrong `EmulateByNameResult::NotSupported` in `syscall` shim

Without the change, the newly added test will fail with:
```diff
-thread 'main' panicked at 'unsupported Miri functionality: can't execute syscall with ID 0', $DIR/unsupported_syscall.rs:10:9
+thread 'main' panicked at 'unsupported Miri functionality: can't call foreign function: syscall', $DIR/unsupported_syscall.rs:10:9
 note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
```
cc https://github.com/rust-lang/miri/pull/1818#discussion_r648868937
2021-06-11 07:32:23 +00:00
hyd-dev
c822ec59aa
Implement cache for not found symbols 2021-06-11 15:24:51 +08:00
hyd-dev
ce7040075a
Disallow #[no_mangle]/#[export_name = ...] functions that have the same symbol name as built-in shims 2021-06-11 15:18:47 +08:00
hyd-dev
6aef1d687d
Remove erroneous exit() and ExitProcess() in tests/run-pass/function_calls/exported_symbol.rs 2021-06-11 13:32:00 +08:00
hyd-dev
4f3718ef85
Fix the wrong EmulateByNameResult::NotSupported in syscall shim 2021-06-11 11:44:57 +08:00
bors
83dd2d7b1f Auto merge of #1830 - RalfJung:readme, r=RalfJung
tweak isolation-error message in README
2021-06-09 19:12:17 +00:00
Ralf Jung
87f2073c80 tweak isolation-error message in README 2021-06-09 21:09:17 +02:00
bors
e5c3af6f51 Auto merge of #1818 - landaire:feature/panic-on-unsupported-syscalls, r=RalfJung
Add support for panicking in the emulated application when unsupported functionality is encountered

This PR fixes #1807 and allows an optional flag to be specified to panic when an unsupported syscall is encountered. In essence, instead of bubbling up an error in the context of the Miri application Miri will panic within the context of the *emulated* application. This feature is desired to allow CI pipelines to determine if a Miri failure is unsupported functionality or actual UB. Please read [this comment](https://github.com/rust-lang/miri/issues/1807#issuecomment-845425076) for the rationale behind this change.

Note: this change does not cover all cases where unsupported functionality errors may be raised. If you search the repo for `throw_unsup_format!` there are many cases that I think are less likely to occur and may still be problematic for some folks.

TODO:

- [x] README documentation on this new flag
- [x] Add tests
2021-06-09 18:09:06 +00:00
bors
6c63506e97 Auto merge of #1829 - RalfJung:isolation, r=RalfJung
isolated operations return EPERM; tweak isolation hint

Follow-up to https://github.com/rust-lang/miri/pull/1797
2021-06-09 16:38:43 +00:00
Ralf Jung
a38f02c44c isolated operations return EPERM; tweak isolation hint 2021-06-09 18:24:59 +02:00
bors
31c1afac5d Auto merge of #1797 - atsmtat:env-isolation, r=RalfJung
fix: avoid stopping machine upon running env operations in isolation

get and set current dir operations used to halt the machine by
throwing an exception in isolation mode. This change updates them to
return a dummy `NotFound` error instead, and keep the machine running.

I started with a custom error using `ErrorKind::Other`, but since it
can't be mapped to a raw OS error, I dropped it. `NotFound` kind of make
sense for get operations, but not much for set operations. But that's
the only error supported for windows currently.
2021-06-09 15:30:50 +00:00
Smit Soni
ba64f485c8 Fix parameter of io error helper function
`set_last_error_from_io_error` works with only the error kind, and
discards the payload. Fix its signature to make it explicit.
2021-06-09 06:28:35 -07:00
Smit Soni
892f706ce5 Add a support to execute isolated op without halting
In user interface, added a new flag `-Zmiri-isolation-error` which
takes one of the four values -- hide, warn, warn-nobacktrace, and
abort. This option can be used to configure Miri to either abort or
return an error code upon executing isolated op. If not aborted, Miri
prints a warning, whose verbosity can be configured using this flag.

In implementation, added a new enum `IsolatedOp` to capture all the
settings related to ops requiring communication with the
host. Old `communicate` flag in both miri configs and machine
stats is replaced with a new helper function `communicate()` which
checks `isolated_op` internally.

Added a new helper function `reject_in_isolation` which can be called
by shims to reject ops according to the reject_with settings. Use miri
specific diagnostics function `report_msg` to print backtrace in the
warning. Update it to take an enum value instead of a bool, indicating
the level of diagnostics.

Updated shims related to current dir to use the new APIs. Added a new
test for current dir ops in isolation without halting machine.
2021-06-09 05:50:52 -07:00
bors
f73db5ce6b Auto merge of #1827 - l4l:patch-1, r=RalfJung
Specify miri toolchain for CI example

In particular current example doesn't work if you have a rust-toolchain file in the project.
2021-06-09 08:00:57 +00:00
Kitsu
c6bcb4d3c0 Specify miri toolchain for CI example 2021-06-09 10:48:43 +03:00
bors
c8713c2f9f Auto merge of #1828 - hyd-dev:rustup, r=RalfJung
Update `Box<Any>` to `Box<dyn Any>` in `catch_panic.stderr`

https://github.com/rust-lang-ci/rust/runs/2771244703#step:25:9487
cc rust-lang/rust#86133 rust-lang/rust#86074
2021-06-08 15:15:05 +00:00
hyd-dev
23c0495ebd
Update Box<Any> to Box<dyn Any> in catch_panic.stderr 2021-06-08 22:18:27 +08:00
Lander Brandt
ae237098f8 Add support for panicking in the emulated application when unsupported syscalls are encountered 2021-06-07 15:21:53 -07:00
bors
81ee877f71 Auto merge of #1826 - hyd-dev:rustup, r=RalfJung
Update `cargo-miri` tests

The test output has been changed recently (likely by rust-lang/rust#84863) and caused a test failure: https://github.com/rust-lang/miri/runs/2761591139#step:8:1228
2021-06-07 09:50:44 +00:00
hyd-dev
9549faa81c
Update cargo-miri tests 2021-06-07 16:53:31 +08:00
bors
28fbf81c40 Auto merge of #1823 - hyd-dev:extern-crate-std, r=RalfJung
Detect `std` by checking if the crate defines `#[lang = "start"]` rather than string comparison

I also considered to compare the crate name with `sym::std`, but it's easy to name any crate `std` by using `--crate-name std`, so I don't think that is robust enough.

Note that this only checks the crate, it does not check whether the call is in `sys::unix` or `sys::windows`, unlike the previous implementation, but I think it's already robust enough.

Fixes #1821.
2021-06-06 08:34:12 +00:00
Ralf Jung
0ece55d748
expand comment 2021-06-06 10:33:46 +02:00
hyd-dev
d7aff96053
Remove 2 tests 2021-06-06 11:22:25 +08:00
hyd-dev
3871c493b2
in_std -> frame_in_std 2021-06-06 11:21:20 +08:00
hyd-dev
545101040d
Don't unwrap() in in_std() 2021-06-06 11:12:13 +08:00
hyd-dev
879000b133
Detect std by checking if the crate defines #[lang = "start"] rather than string comparison 2021-06-06 11:12:05 +08:00