Skip to content

Commit 82a8059

Browse files
committed
Auto merge of rust-lang#3562 - RalfJung:unsupported, r=RalfJung
only show the 'basic API common for this target' message when this is a missing foreign function Follow-up to rust-lang/miri#3558
2 parents d0e7772 + cdf3f3c commit 82a8059

32 files changed

+34
-44
lines changed

src/tools/miri/src/diagnostics.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub enum TerminationInfo {
4848
extra: Option<&'static str>,
4949
retag_explain: bool,
5050
},
51+
UnsupportedForeignItem(String),
5152
}
5253

5354
pub struct RacingOp {
@@ -85,6 +86,7 @@ impl fmt::Display for TerminationInfo {
8586
op2.action,
8687
op2.thread_info
8788
),
89+
UnsupportedForeignItem(msg) => write!(f, "{msg}"),
8890
}
8991
}
9092
}
@@ -214,7 +216,7 @@ pub fn report_error<'tcx, 'mir>(
214216
let title = match info {
215217
Exit { code, leak_check } => return Some((*code, *leak_check)),
216218
Abort(_) => Some("abnormal termination"),
217-
UnsupportedInIsolation(_) | Int2PtrWithStrictProvenance =>
219+
UnsupportedInIsolation(_) | Int2PtrWithStrictProvenance | UnsupportedForeignItem(_) =>
218220
Some("unsupported operation"),
219221
StackedBorrowsUb { .. } | TreeBorrowsUb { .. } | DataRace { .. } =>
220222
Some("Undefined Behavior"),
@@ -228,6 +230,12 @@ pub fn report_error<'tcx, 'mir>(
228230
(None, format!("pass the flag `-Zmiri-disable-isolation` to disable isolation;")),
229231
(None, format!("or pass `-Zmiri-isolation-error=warn` to configure Miri to return an error code from isolated operations (if supported for that operation) and continue with a warning")),
230232
],
233+
UnsupportedForeignItem(_) => {
234+
vec![
235+
(None, format!("if this is a basic API commonly used on this target, please report an issue with Miri")),
236+
(None, format!("however, note that Miri does not aim to support every FFI function out there; for instance, we will not support APIs for things such as GUIs, scripting languages, or databases")),
237+
]
238+
}
231239
StackedBorrowsUb { help, history, .. } => {
232240
msg.extend(help.clone());
233241
let mut helps = vec![
@@ -322,7 +330,6 @@ pub fn report_error<'tcx, 'mir>(
322330
Unsupported(_) =>
323331
vec![
324332
(None, format!("this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support")),
325-
(None, format!("if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there")),
326333
],
327334
UndefinedBehavior(AlignmentCheckFailed { .. })
328335
if ecx.machine.check_alignment == AlignmentCheck::Symbolic
@@ -347,7 +354,7 @@ pub fn report_error<'tcx, 'mir>(
347354
}
348355
AbiMismatchArgument { .. } | AbiMismatchReturn { .. } => {
349356
helps.push((None, format!("this means these two types are not *guaranteed* to be ABI-compatible across all targets")));
350-
helps.push((None, format!("if you think this code should be accepted anyway, please report an issue")));
357+
helps.push((None, format!("if you think this code should be accepted anyway, please report an issue with Miri")));
351358
}
352359
_ => {},
353360
}

src/tools/miri/src/helpers.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -1067,20 +1067,18 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
10671067
crate_name == "std" || crate_name == "std_miri_test"
10681068
}
10691069

1070-
/// Handler that should be called when unsupported functionality is encountered.
1070+
/// Handler that should be called when an unsupported foreign item is encountered.
10711071
/// This function will either panic within the context of the emulated application
10721072
/// or return an error in the Miri process context
1073-
///
1074-
/// Return value of `Ok(bool)` indicates whether execution should continue.
1075-
fn handle_unsupported<S: AsRef<str>>(&mut self, error_msg: S) -> InterpResult<'tcx, ()> {
1073+
fn handle_unsupported_foreign_item(&mut self, error_msg: String) -> InterpResult<'tcx, ()> {
10761074
let this = self.eval_context_mut();
10771075
if this.machine.panic_on_unsupported {
10781076
// message is slightly different here to make automated analysis easier
1079-
let error_msg = format!("unsupported Miri functionality: {}", error_msg.as_ref());
1077+
let error_msg = format!("unsupported Miri functionality: {error_msg}");
10801078
this.start_panic(error_msg.as_ref(), mir::UnwindAction::Continue)?;
10811079
Ok(())
10821080
} else {
1083-
throw_unsup_format!("{}", error_msg.as_ref());
1081+
throw_machine_stop!(TerminationInfo::UnsupportedForeignItem(error_msg));
10841082
}
10851083
}
10861084

src/tools/miri/src/shims/foreign_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
119119
if let Some(body) = this.lookup_exported_symbol(link_name)? {
120120
return Ok(Some(body));
121121
}
122-
this.handle_unsupported(format!(
122+
this.handle_unsupported_foreign_item(format!(
123123
"can't call (diverging) foreign function: {link_name}"
124124
))?;
125125
return Ok(None);
@@ -140,7 +140,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
140140
return Ok(Some(body));
141141
}
142142

143-
this.handle_unsupported(format!(
143+
this.handle_unsupported_foreign_item(format!(
144144
"can't call foreign function `{link_name}` on OS `{os}`",
145145
os = this.tcx.sess.target.os,
146146
))?;

src/tools/miri/src/shims/unix/linux/foreign_items.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriInterpCxExt<'mir, 'tcx> {
144144
futex(this, &args[1..], dest)?;
145145
}
146146
id => {
147-
this.handle_unsupported(format!("can't execute syscall with ID {id}"))?;
147+
this.handle_unsupported_foreign_item(format!(
148+
"can't execute syscall with ID {id}"
149+
))?;
148150
return Ok(EmulateForeignItemResult::AlreadyJumped);
149151
}
150152
}

src/tools/miri/tests/extern-so/fail/function_not_in_so.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: unsupported operation: can't call foreign function `foo` on $OS
44
LL | foo();
55
| ^^^^^ can't call foreign function `foo` on $OS
66
|
7-
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
7+
= help: if this is a basic API commonly used on this target, please report an issue with Miri
8+
= help: however, note that Miri does not aim to support every FFI function out there; for instance, we will not support APIs for things such as GUIs, scripting languages, or databases
99
= note: BACKTRACE:
1010
= note: inside `main` at $DIR/function_not_in_so.rs:LL:CC
1111

src/tools/miri/tests/fail-dep/shims/fs/close_stdout.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | libc::close(1);
55
| ^^^^^^^^^^^^^^ cannot close stdout
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/close_stdout.rs:LL:CC
1110

src/tools/miri/tests/fail-dep/shims/fs/read_from_stdout.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | libc::read(1, bytes.as_mut_ptr() as *mut libc::c_void, 512);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot read from stdout
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/read_from_stdout.rs:LL:CC
1110

src/tools/miri/tests/fail-dep/shims/fs/write_to_stdin.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | libc::write(0, bytes.as_ptr() as *const libc::c_void, 5);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cannot write to stdin
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/write_to_stdin.rs:LL:CC
1110

src/tools/miri/tests/fail-dep/tokio/sleep.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ LL | | ))
1010
| |__________^ returning ready events from epoll_wait is not yet implemented
1111
|
1212
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
13-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
1413

1514
error: aborting due to 1 previous error
1615

src/tools/miri/tests/fail-dep/unsupported_incomplete_function.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: unsupported operation: can't call foreign function `signal` on $OS
44
LL | libc::signal(libc::SIGPIPE, libc::SIG_IGN);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ can't call foreign function `signal` on $OS
66
|
7-
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
7+
= help: if this is a basic API commonly used on this target, please report an issue with Miri
8+
= help: however, note that Miri does not aim to support every FFI function out there; for instance, we will not support APIs for things such as GUIs, scripting languages, or databases
99
= note: BACKTRACE:
1010
= note: inside `main` at $DIR/unsupported_incomplete_function.rs:LL:CC
1111

src/tools/miri/tests/fail/alloc/no_global_allocator.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ error: unsupported operation: can't call foreign function `__rust_alloc` on $OS
44
LL | __rust_alloc(1, 1);
55
| ^^^^^^^^^^^^^^^^^^ can't call foreign function `__rust_alloc` on $OS
66
|
7-
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
7+
= help: if this is a basic API commonly used on this target, please report an issue with Miri
8+
= help: however, note that Miri does not aim to support every FFI function out there; for instance, we will not support APIs for things such as GUIs, scripting languages, or databases
99
= note: BACKTRACE:
1010
= note: inside `start` at $DIR/no_global_allocator.rs:LL:CC
1111

src/tools/miri/tests/fail/extern-type-field-offset.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | let _field = &x.a;
55
| ^^^^ `extern type` does not have a known offset
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/extern-type-field-offset.rs:LL:CC
1110

src/tools/miri/tests/fail/extern_static.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | let _val = unsafe { std::ptr::addr_of!(FOO) };
55
| ^^^ extern static `FOO` is not supported by Miri
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/extern_static.rs:LL:CC
1110

src/tools/miri/tests/fail/extern_static_in_const.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | let _val = X;
55
| ^ extern static `E` is not supported by Miri
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/extern_static_in_const.rs:LL:CC
1110

src/tools/miri/tests/fail/extern_static_wrong_size.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | let _val = unsafe { environ };
55
| ^^^^^^^ extern static `environ` has been declared as `extern_static_wrong_size::environ` with a size of 1 bytes and alignment of 1 bytes, but Miri emulates it via an extern static shim with a size of N bytes and alignment of N bytes
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/extern_static_wrong_size.rs:LL:CC
1110

src/tools/miri/tests/fail/function_pointers/abi_mismatch_array_vs_struct.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | g(Default::default())
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= help: this means these two types are not *guaranteed* to be ABI-compatible across all targets
10-
= help: if you think this code should be accepted anyway, please report an issue
10+
= help: if you think this code should be accepted anyway, please report an issue with Miri
1111
= note: BACKTRACE:
1212
= note: inside `main` at $DIR/abi_mismatch_array_vs_struct.rs:LL:CC
1313

src/tools/miri/tests/fail/function_pointers/abi_mismatch_int_vs_float.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | g(42)
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= help: this means these two types are not *guaranteed* to be ABI-compatible across all targets
10-
= help: if you think this code should be accepted anyway, please report an issue
10+
= help: if you think this code should be accepted anyway, please report an issue with Miri
1111
= note: BACKTRACE:
1212
= note: inside `main` at $DIR/abi_mismatch_int_vs_float.rs:LL:CC
1313

src/tools/miri/tests/fail/function_pointers/abi_mismatch_raw_pointer.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | g(&42 as *const i32)
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= help: this means these two types are not *guaranteed* to be ABI-compatible across all targets
10-
= help: if you think this code should be accepted anyway, please report an issue
10+
= help: if you think this code should be accepted anyway, please report an issue with Miri
1111
= note: BACKTRACE:
1212
= note: inside `main` at $DIR/abi_mismatch_raw_pointer.rs:LL:CC
1313

src/tools/miri/tests/fail/function_pointers/abi_mismatch_repr_C.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | fnptr(S1(NonZeroI32::new(1).unwrap()));
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= help: this means these two types are not *guaranteed* to be ABI-compatible across all targets
10-
= help: if you think this code should be accepted anyway, please report an issue
10+
= help: if you think this code should be accepted anyway, please report an issue with Miri
1111
= note: BACKTRACE:
1212
= note: inside `main` at $DIR/abi_mismatch_repr_C.rs:LL:CC
1313

src/tools/miri/tests/fail/function_pointers/abi_mismatch_return_type.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | g()
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= help: this means these two types are not *guaranteed* to be ABI-compatible across all targets
10-
= help: if you think this code should be accepted anyway, please report an issue
10+
= help: if you think this code should be accepted anyway, please report an issue with Miri
1111
= note: BACKTRACE:
1212
= note: inside `main` at $DIR/abi_mismatch_return_type.rs:LL:CC
1313

src/tools/miri/tests/fail/function_pointers/abi_mismatch_simple.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | g(42)
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= help: this means these two types are not *guaranteed* to be ABI-compatible across all targets
10-
= help: if you think this code should be accepted anyway, please report an issue
10+
= help: if you think this code should be accepted anyway, please report an issue with Miri
1111
= note: BACKTRACE:
1212
= note: inside `main` at $DIR/abi_mismatch_simple.rs:LL:CC
1313

src/tools/miri/tests/fail/function_pointers/abi_mismatch_vector.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ LL | g(Default::default())
77
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior
88
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information
99
= help: this means these two types are not *guaranteed* to be ABI-compatible across all targets
10-
= help: if you think this code should be accepted anyway, please report an issue
10+
= help: if you think this code should be accepted anyway, please report an issue with Miri
1111
= note: BACKTRACE:
1212
= note: inside `main` at $DIR/abi_mismatch_vector.rs:LL:CC
1313

src/tools/miri/tests/fail/intrinsic_fallback_checks_ub.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | ptr_guaranteed_cmp::<()>(std::ptr::null(), std::ptr::null());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ miri can only use intrinsic fallback bodies that check UB. After verifying that `ptr_guaranteed_cmp` does so, add the `#[miri::intrinsic_fallback_checks_ub]` attribute to it; also ping @rust-lang/miri when you do that
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/intrinsic_fallback_checks_ub.rs:LL:CC
1110

src/tools/miri/tests/fail/issue-miri-3288-ice-symbolic-alignment-extern-static.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | let _val = *DISPATCH_QUEUE_CONCURRENT;
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^ extern static `_dispatch_queue_attr_concurrent` is not supported by Miri
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/issue-miri-3288-ice-symbolic-alignment-extern-static.rs:LL:CC
1110

src/tools/miri/tests/fail/shims/backtrace/bad-backtrace-flags.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | miri_get_backtrace(2, std::ptr::null_mut());
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown `miri_get_backtrace` flags 2
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/bad-backtrace-flags.rs:LL:CC
1110

src/tools/miri/tests/fail/shims/backtrace/bad-backtrace-resolve-flags.stderr

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ LL | miri_resolve_frame(buf[0], 2);
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ unknown `miri_resolve_frame` flags 2
66
|
77
= help: this is likely not a bug in the program; it indicates that the program performed an operation that Miri does not support
8-
= help: if this is a basic API commonly used on this target, please report an issue; but note that Miri does not aim to support every FFI function out there
98
= note: BACKTRACE:
109
= note: inside `main` at $DIR/bad-backtrace-resolve-flags.rs:LL:CC
1110

0 commit comments

Comments
 (0)