Skip to content

Commit f4146aa

Browse files
committed
raw dylib: also apply the standard ABI conformance checks
also unify error messages that do not seem to have a good reason to be different
1 parent 1e9ed31 commit f4146aa

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

compiler/rustc_metadata/messages.ftl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,9 @@ metadata_raw_dylib_no_nul =
272272
metadata_raw_dylib_only_windows =
273273
link kind `raw-dylib` is only supported on Windows targets
274274
275+
metadata_raw_dylib_unsupported_abi =
276+
ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture
277+
275278
metadata_renaming_no_link =
276279
renaming of the library `{$lib_name}` was specified, however this crate contains no `#[link(...)]` attributes referencing this library
277280
@@ -319,12 +322,6 @@ metadata_unknown_link_modifier =
319322
320323
metadata_unknown_target_modifier_unsafe_allowed = unknown target modifier `{$flag_name}`, requested by `-Cunsafe-allow-abi-mismatch={$flag_name}`
321324
322-
metadata_unsupported_abi =
323-
ABI not supported by `#[link(kind = "raw-dylib")]` on this architecture
324-
325-
metadata_unsupported_abi_i686 =
326-
ABI not supported by `#[link(kind = "raw-dylib")]` on i686
327-
328325
metadata_wasm_c_abi =
329326
older versions of the `wasm-bindgen` crate are incompatible with current versions of Rust; please update to `wasm-bindgen` v0.2.88
330327

compiler/rustc_metadata/src/errors.rs

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,8 @@ pub struct NoLinkModOverride {
300300
}
301301

302302
#[derive(Diagnostic)]
303-
#[diag(metadata_unsupported_abi_i686)]
304-
pub struct UnsupportedAbiI686 {
305-
#[primary_span]
306-
pub span: Span,
307-
}
308-
309-
#[derive(Diagnostic)]
310-
#[diag(metadata_unsupported_abi)]
311-
pub struct UnsupportedAbi {
303+
#[diag(metadata_raw_dylib_unsupported_abi)]
304+
pub struct RawDylibUnsupportedAbi {
312305
#[primary_span]
313306
pub span: Span,
314307
}

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use rustc_session::config::CrateType;
1212
use rustc_session::cstore::{
1313
DllCallingConvention, DllImport, ForeignModule, NativeLib, PeImportNameType,
1414
};
15+
use rustc_session::lint::builtin::UNSUPPORTED_CALLING_CONVENTIONS;
1516
use rustc_session::parse::feature_err;
1617
use rustc_session::search_paths::PathKind;
1718
use rustc_session::utils::NativeLibKind;
@@ -652,7 +653,23 @@ impl<'tcx> Collector<'tcx> {
652653
) -> DllImport {
653654
let span = self.tcx.def_span(item);
654655

655-
// this logic is similar to `Target::adjust_abi` (in rustc_target/src/spec/mod.rs) but errors on unsupported inputs
656+
// Check whether this ABI is generally supported.
657+
match self.tcx.sess.target.is_abi_supported(abi) {
658+
Some(true) => (),
659+
Some(false) => {
660+
self.tcx.dcx().emit_fatal(errors::RawDylibUnsupportedAbi { span });
661+
}
662+
None => {
663+
let hir_id = self.tcx.local_def_id_to_hir_id(item.expect_local());
664+
self.tcx.node_span_lint(UNSUPPORTED_CALLING_CONVENTIONS, hir_id, span, |lint| {
665+
lint.primary_message("use of calling convention not supported on this target");
666+
});
667+
}
668+
}
669+
670+
// This logic is similar to `Target::adjust_abi` (in rustc_target/src/spec/mod.rs) but we
671+
// need more detail than those adjustments, and we can't support all ABIs that are generally
672+
// supported.
656673
let calling_convention = if self.tcx.sess.target.arch == "x86" {
657674
match abi {
658675
ExternAbi::C { .. } | ExternAbi::Cdecl { .. } => DllCallingConvention::C,
@@ -679,7 +696,7 @@ impl<'tcx> Collector<'tcx> {
679696
DllCallingConvention::Vectorcall(self.i686_arg_list_size(item))
680697
}
681698
_ => {
682-
self.tcx.dcx().emit_fatal(errors::UnsupportedAbiI686 { span });
699+
self.tcx.dcx().emit_fatal(errors::RawDylibUnsupportedAbi { span });
683700
}
684701
}
685702
} else {
@@ -688,7 +705,7 @@ impl<'tcx> Collector<'tcx> {
688705
DllCallingConvention::C
689706
}
690707
_ => {
691-
self.tcx.dcx().emit_fatal(errors::UnsupportedAbi { span });
708+
self.tcx.dcx().emit_fatal(errors::RawDylibUnsupportedAbi { span });
692709
}
693710
}
694711
};

0 commit comments

Comments
 (0)