@@ -12,6 +12,7 @@ use rustc_session::config::CrateType;
12
12
use rustc_session:: cstore:: {
13
13
DllCallingConvention , DllImport , ForeignModule , NativeLib , PeImportNameType ,
14
14
} ;
15
+ use rustc_session:: lint:: builtin:: UNSUPPORTED_CALLING_CONVENTIONS ;
15
16
use rustc_session:: parse:: feature_err;
16
17
use rustc_session:: search_paths:: PathKind ;
17
18
use rustc_session:: utils:: NativeLibKind ;
@@ -652,7 +653,23 @@ impl<'tcx> Collector<'tcx> {
652
653
) -> DllImport {
653
654
let span = self . tcx . def_span ( item) ;
654
655
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.
656
673
let calling_convention = if self . tcx . sess . target . arch == "x86" {
657
674
match abi {
658
675
ExternAbi :: C { .. } | ExternAbi :: Cdecl { .. } => DllCallingConvention :: C ,
@@ -679,7 +696,7 @@ impl<'tcx> Collector<'tcx> {
679
696
DllCallingConvention :: Vectorcall ( self . i686_arg_list_size ( item) )
680
697
}
681
698
_ => {
682
- self . tcx . dcx ( ) . emit_fatal ( errors:: UnsupportedAbiI686 { span } ) ;
699
+ self . tcx . dcx ( ) . emit_fatal ( errors:: RawDylibUnsupportedAbi { span } ) ;
683
700
}
684
701
}
685
702
} else {
@@ -688,7 +705,7 @@ impl<'tcx> Collector<'tcx> {
688
705
DllCallingConvention :: C
689
706
}
690
707
_ => {
691
- self . tcx . dcx ( ) . emit_fatal ( errors:: UnsupportedAbi { span } ) ;
708
+ self . tcx . dcx ( ) . emit_fatal ( errors:: RawDylibUnsupportedAbi { span } ) ;
692
709
}
693
710
}
694
711
} ;
0 commit comments