diff options
| author | Ralf Jung <post@ralfj.de> | 2025-05-23 12:44:15 +0200 | 
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2025-06-08 07:34:41 +0200 | 
| commit | b616e1197482f31c0a403d2dac41bb7425cd70f4 (patch) | |
| tree | 410f8648919940e886f2dbeb10d9e056c7fee1b0 /compiler/rustc_metadata | |
| parent | 873122c006315e541c30809210089606877122c5 (diff) | |
| download | rust-b616e1197482f31c0a403d2dac41bb7425cd70f4.tar.gz rust-b616e1197482f31c0a403d2dac41bb7425cd70f4.zip | |
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
Diffstat (limited to 'compiler/rustc_metadata')
| -rw-r--r-- | compiler/rustc_metadata/messages.ftl | 9 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/errors.rs | 11 | ||||
| -rw-r--r-- | compiler/rustc_metadata/src/native_libs.rs | 12 | 
3 files changed, 14 insertions, 18 deletions
| diff --git a/compiler/rustc_metadata/messages.ftl b/compiler/rustc_metadata/messages.ftl index bccffe39243..3bef5ca114b 100644 --- a/compiler/rustc_metadata/messages.ftl +++ b/compiler/rustc_metadata/messages.ftl @@ -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 diff --git a/compiler/rustc_metadata/src/errors.rs b/compiler/rustc_metadata/src/errors.rs index 16f59793e63..71da4290174 100644 --- a/compiler/rustc_metadata/src/errors.rs +++ b/compiler/rustc_metadata/src/errors.rs @@ -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, } diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index cee9cff0775..5cdeb8935f7 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -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 }); } } }; | 
