@@ -12,6 +12,7 @@ use rustc_session::config::CrateType;
1212use rustc_session:: cstore:: {
1313 DllCallingConvention , DllImport , ForeignModule , NativeLib , PeImportNameType ,
1414} ;
15+ use rustc_session:: lint:: builtin:: UNSUPPORTED_CALLING_CONVENTIONS ;
1516use rustc_session:: parse:: feature_err;
1617use rustc_session:: search_paths:: PathKind ;
1718use 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