Commit Graph

2641 Commits

Author SHA1 Message Date
Ralf Jung
0766da6fbe implement simd_add 2021-11-20 22:30:49 -05:00
Ralf Jung
d8bee92aee rename track-raw-pointers flag to tag-raw-pointers 2021-11-13 15:48:27 -05:00
Noah Lev
e6a9b2ce68 Update Miri for detecting uninitialized numbers
This commit adds a `-Zmiri-check-number-initialization` flag to check
that integers and floats are initialized.

This commit also changes some shims to write at type `MaybeUninit<...>`
in order to prevent spurious errors from the uninit check.
2021-11-10 11:36:42 -08:00
bjorn3
9944a2daf3 rustup 2021-10-26 13:42:03 +02:00
bors
adc26a3062 Auto merge of #1885 - DrMeepster:global_allocator, r=RalfJung
add support for `#[global_allocator]`

This PR adds support for custom global allocators. Unfortunately, the code given in #1207 still causes errors when used with box. I believe this is because Box is special-cased in miri and stacked borrows.
2021-09-30 01:37:38 +00:00
DrMeepster
e6a27a68fa implement #[global_allocator] 2021-09-28 20:32:53 -07:00
Ralf Jung
5f825ae895 rustup 2021-09-27 15:59:18 -04:00
Ralf Jung
405de0217d some more Windows argument passing tests 2021-09-24 10:33:32 -04:00
Chris Denton
cfd1316e60
Apply review changes 2021-09-22 20:46:20 +01:00
Chris Denton
f6cedbc744
Correct Windows argument handling
Previously the command line string would have been incorrectly constructed if argv[0] contained a doublequote (`"`) or ended in a trailing backslash (`\`). This is a very rare edge case because, by convention, argv[0] is the path to the application and Windows file names cannot contain doublequotes.

Fixes #1881
2021-09-18 18:41:55 +01:00
hyd-dev
9c62b6454e
rustc_mir -> rustc_const_eval 2021-09-09 17:36:39 +08:00
bors
1cc822e6af Auto merge of #1884 - DrMeepster:start, r=RalfJung
add support for `#[start]`

This PR adds support for the `#[start]` attribute and fixes #1825.

It also renames `eval_main` to `eval_entry` to reflect that it can evaluate any entry function.
2021-09-08 19:43:41 +00:00
hyd-dev
3fedc7b249
rustc_target::abi::LayoutOf -> rustc_middle::ty::layout::LayoutOf 2021-09-06 23:05:48 +08:00
DrMeepster
1ec28f78f3 remove commented out code 2021-09-02 15:45:52 -07:00
DrMeepster
84b058ac47 add support for #[start] 2021-09-02 15:41:10 -07:00
Ralf Jung
35b64447f3 rustup 2021-08-30 10:35:34 -04:00
bors
94ae910131 Auto merge of #1875 - niluxv:volatile_set_memory_intrinsic, r=RalfJung
Add support for the `volatile_set_memory` intrinsic

Add support for the unstable `volatile_set_memory` intrinsic

(Runtime behaviour and soundness requirements for `volatile_set_memory` are identical to those of `write_bytes`, so supporting this intrinsic is trivial.)
2021-08-23 10:55:48 +00:00
Frank Steffahn
c79f6dd5a0 Fix a typo “an”→“a” 2021-08-22 18:07:01 +02:00
niluxv
32c2df87be Add support for the volatile_set_memory intrinsic
Runtime behaviour and soundness requirements are identical to `write_bytes`.
2021-08-22 17:48:31 +02:00
Frank Steffahn
a0d4372ff9 Fix typos “a”→“an” 2021-08-22 16:42:23 +02:00
Ralf Jung
257e9cef66 docify some comments 2021-08-02 17:58:55 +02:00
Ralf Jung
5338a16018 adjust for ERR_ON_PARTIAL_PTR_OVERWRITE 2021-08-02 17:58:55 +02:00
hyd-dev
a789b49e4c
Use Lrc instead of Rc in MiriCompilerCalls::config() 2021-07-30 21:28:34 +08:00
bors
02f78b089c Auto merge of #1858 - RalfJung:thread-leaks, r=oli-obk
also ignore 'thread leaks' with -Zmiri-ignore-leaks

This is a step towards https://github.com/rust-lang/miri/issues/1371. The remaining hard part would be supporting checking for memory leaks when there are threads still running. For now we elegantly avoid this problem by using the same flag to control both of these checks. :)
2021-07-27 12:23:56 +00:00
Ralf Jung
df9d481989 tell users how to disable the leak check 2021-07-25 14:21:06 +02:00
Ralf Jung
71efd950d1 also ignore 'thread leaks' with -Zmiri-ignore-leaks 2021-07-25 14:21:06 +02:00
bors
eb9e3073a0 Auto merge of #1856 - RalfJung:no-mir, r=RalfJung
show proper error when using a sysroot without MIR

Fixes https://github.com/rust-lang/miri/issues/1834
2021-07-25 09:50:06 +00:00
Smit Soni
20d0f2ee26 Move shim argument checks before isolation check
This allows catching extremely incorrect arguments before rejecting
due to isolation.
2021-07-24 11:54:55 -07:00
Ralf Jung
46d31f9230 show proper error when using a sysroot without MIR 2021-07-24 14:02:09 +02:00
Smit Soni
da6880427a Update error code for fs ops in isolation
Change the code to either `EACCES` (if the op is performed on the
path), or `EBADF` (if the op is performed the fd)

Updated ops: `stat`, `opendir`, `ftruncate64`, and `readlink`

Add a new test for fs ops in isolation.
2021-07-20 08:23:51 -07:00
Smit Soni
a1cabac727 Fix use of deprecated check_no_isolation in posix fs ops
Update posix fs shims to use new API `reject_in_isolation`, which
allows rejection with error code instead of always forcing abort.
Error code chosen for each op is the most appropriate one from the
list in corresponding syscall's manual.

Updated helper APIs to not use quotes (`) around input name while
preparing the message. This allows callers to pass multi-word string
like -- "`read` from stdin".
2021-07-20 08:23:51 -07:00
Ralf Jung
46ed39ec20 adjust for PointerOutOfBounds change 2021-07-20 13:30:49 +02:00
Ralf Jung
a1233a721d adjust Miri to Pointer type overhaul 2021-07-16 10:10:12 +02:00
Ralf Jung
0341b8ac84 fmt: set force_multiline_blocks=true 2021-07-11 14:18:44 +02:00
Ralf Jung
447f23c71b fmt 2021-07-06 10:13:30 +02:00
Ralf Jung
340267525c exported_symbols_cache: ensure we do not overwrite anything 2021-07-06 10:09:53 +02:00
Ralf Jung
9b57313a4d also treat CallerLocation and Machine memory as properly tagged 2021-07-06 10:07:48 +02:00
Ralf Jung
efd582c6d8 explicitly list memory kinds for stacked borrows 2021-07-06 10:04:16 +02:00
Smitty
d19376985d Make work after mir-alloc-oom 2021-07-04 09:59:55 -04:00
hyd-dev
76fe48543c
Update for TyCtxt::crates() change 2021-07-02 16:08:27 +08:00
Ralf Jung
e33bf695db rustup 2021-06-29 20:47:28 +02:00
Ralf Jung
7b2d2cfa46 use exhaustive struct match for manual Debug impl 2021-06-20 19:33:05 +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
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