raw dylib: ensure that we have applied standard ABI checks

also unify error messages that do not seem to have a good reason to be different
This commit is contained in:
Ralf Jung 2025-05-23 12:44:15 +02:00
parent 873122c006
commit b616e11974
5 changed files with 41 additions and 19 deletions

View file

@ -272,6 +272,9 @@ metadata_raw_dylib_no_nul =
metadata_raw_dylib_only_windows =
link kind `raw-dylib` is only supported on Windows targets
metadata_raw_dylib_unsupported_abi =
ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture
metadata_renaming_no_link =
renaming of the library `{$lib_name}` was specified, however this crate contains no `#[link(...)]` attributes referencing this library
@ -319,12 +322,6 @@ metadata_unknown_link_modifier =
metadata_unknown_target_modifier_unsafe_allowed = unknown target modifier `{$flag_name}`, requested by `-Cunsafe-allow-abi-mismatch={$flag_name}`
metadata_unsupported_abi =
ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture
metadata_unsupported_abi_i686 =
ABI not supported by `#[link(kind = "raw-dylib")]` on i686
metadata_wasm_c_abi =
older versions of the `wasm-bindgen` crate are incompatible with current versions of Rust; please update to `wasm-bindgen` v0.2.88

View file

@ -300,15 +300,8 @@ pub struct NoLinkModOverride {
}
#[derive(Diagnostic)]
#[diag(metadata_unsupported_abi_i686)]
pub struct UnsupportedAbiI686 {
#[primary_span]
pub span: Span,
}
#[derive(Diagnostic)]
#[diag(metadata_unsupported_abi)]
pub struct UnsupportedAbi {
#[diag(metadata_raw_dylib_unsupported_abi)]
pub struct RawDylibUnsupportedAbi {
#[primary_span]
pub span: Span,
}

View file

@ -652,7 +652,13 @@ impl<'tcx> Collector<'tcx> {
) -> DllImport {
let span = self.tcx.def_span(item);
// this logic is similar to `Target::adjust_abi` (in rustc_target/src/spec/mod.rs) but errors on unsupported inputs
// This `extern` block should have been checked for general ABI support before, but let's
// double-check that.
assert!(self.tcx.sess.target.is_abi_supported(abi));
// This logic is similar to `AbiMap::canonize_abi` (in rustc_target/src/spec/abi_map.rs) but
// we need more detail than those adjustments, and we can't support all ABIs that are
// generally supported.
let calling_convention = if self.tcx.sess.target.arch == "x86" {
match abi {
ExternAbi::C { .. } | ExternAbi::Cdecl { .. } => DllCallingConvention::C,
@ -679,7 +685,7 @@ impl<'tcx> Collector<'tcx> {
DllCallingConvention::Vectorcall(self.i686_arg_list_size(item))
}
_ => {
self.tcx.dcx().emit_fatal(errors::UnsupportedAbiI686 { span });
self.tcx.dcx().emit_fatal(errors::RawDylibUnsupportedAbi { span });
}
}
} else {
@ -688,7 +694,7 @@ impl<'tcx> Collector<'tcx> {
DllCallingConvention::C
}
_ => {
self.tcx.dcx().emit_fatal(errors::UnsupportedAbi { span });
self.tcx.dcx().emit_fatal(errors::RawDylibUnsupportedAbi { span });
}
}
};

View file

@ -284,3 +284,9 @@ fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
}
extern "C-cmse-nonsecure-entry" {}
//~^ ERROR is not a supported ABI
#[cfg(windows)]
#[link(name = "foo", kind = "raw-dylib")]
extern "cdecl" {}
//[x64_win]~^ WARN use of calling convention not supported on this target
//[x64_win]~^^ WARN this was previously accepted

View file

@ -150,6 +150,15 @@ error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current
LL | extern "C-cmse-nonsecure-entry" {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: use of calling convention not supported on this target
--> $DIR/unsupported.rs:290:1
|
LL | extern "cdecl" {}
| ^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target
--> $DIR/unsupported.rs:36:1
|
@ -216,7 +225,7 @@ error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current
LL | extern "C-cmse-nonsecure-entry" fn cmse_entry() {}
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 15 previous errors; 14 warnings emitted
error: aborting due to 15 previous errors; 15 warnings emitted
For more information about this error, try `rustc --explain E0570`.
Future incompatibility report: Future breakage diagnostic:
@ -351,6 +360,17 @@ LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
Future breakage diagnostic:
warning: use of calling convention not supported on this target
--> $DIR/unsupported.rs:290:1
|
LL | extern "cdecl" {}
| ^^^^^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
= note: `#[warn(unsupported_calling_conventions)]` on by default
Future breakage diagnostic:
warning: use of calling convention not supported on this target
--> $DIR/unsupported.rs:176:1