Skip to content

Commit b8f4367

Browse files
committed
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
1 parent 1e9ed31 commit b8f4367

File tree

5 files changed

+41
-19
lines changed

5 files changed

+41
-19
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: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,13 @@ impl<'tcx> Collector<'tcx> {
652652
) -> DllImport {
653653
let span = self.tcx.def_span(item);
654654

655-
// this logic is similar to `Target::adjust_abi` (in rustc_target/src/spec/mod.rs) but errors on unsupported inputs
655+
// This `extern` block should have been checked for general ABI support before, but let's
656+
// double-check that.
657+
assert!(self.tcx.sess.target.is_abi_supported(abi).unwrap_or(true));
658+
659+
// This logic is similar to `Target::adjust_abi` (in rustc_target/src/spec/mod.rs) but we
660+
// need more detail than those adjustments, and we can't support all ABIs that are generally
661+
// supported.
656662
let calling_convention = if self.tcx.sess.target.arch == "x86" {
657663
match abi {
658664
ExternAbi::C { .. } | ExternAbi::Cdecl { .. } => DllCallingConvention::C,
@@ -679,7 +685,7 @@ impl<'tcx> Collector<'tcx> {
679685
DllCallingConvention::Vectorcall(self.i686_arg_list_size(item))
680686
}
681687
_ => {
682-
self.tcx.dcx().emit_fatal(errors::UnsupportedAbiI686 { span });
688+
self.tcx.dcx().emit_fatal(errors::RawDylibUnsupportedAbi { span });
683689
}
684690
}
685691
} else {
@@ -688,7 +694,7 @@ impl<'tcx> Collector<'tcx> {
688694
DllCallingConvention::C
689695
}
690696
_ => {
691-
self.tcx.dcx().emit_fatal(errors::UnsupportedAbi { span });
697+
self.tcx.dcx().emit_fatal(errors::RawDylibUnsupportedAbi { span });
692698
}
693699
}
694700
};

tests/ui/abi/unsupported.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,9 @@ fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
284284
}
285285
extern "C-cmse-nonsecure-entry" {}
286286
//~^ ERROR is not a supported ABI
287+
288+
#[cfg(windows)]
289+
#[link(name = "foo", kind = "raw-dylib")]
290+
extern "cdecl" {}
291+
//[x64_win]~^ WARN use of calling convention not supported on this target
292+
//[x64_win]~^^ WARN this was previously accepted

tests/ui/abi/unsupported.x64_win.stderr

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,15 @@ error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current
150150
LL | extern "C-cmse-nonsecure-entry" {}
151151
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
152152

153+
warning: use of calling convention not supported on this target
154+
--> $DIR/unsupported.rs:290:1
155+
|
156+
LL | extern "cdecl" {}
157+
| ^^^^^^^^^^^^^^^^^
158+
|
159+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
160+
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
161+
153162
error[E0570]: `"ptx-kernel"` is not a supported ABI for the current target
154163
--> $DIR/unsupported.rs:36:1
155164
|
@@ -216,7 +225,7 @@ error[E0570]: `"C-cmse-nonsecure-entry"` is not a supported ABI for the current
216225
LL | extern "C-cmse-nonsecure-entry" fn cmse_entry() {}
217226
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
218227

219-
error: aborting due to 15 previous errors; 14 warnings emitted
228+
error: aborting due to 15 previous errors; 15 warnings emitted
220229

221230
For more information about this error, try `rustc --explain E0570`.
222231
Future incompatibility report: Future breakage diagnostic:
@@ -351,6 +360,17 @@ LL | fn cmse_entry_ptr(f: extern "C-cmse-nonsecure-entry" fn()) {
351360
= note: for more information, see issue #130260 <https://github.com/rust-lang/rust/issues/130260>
352361
= note: `#[warn(unsupported_fn_ptr_calling_conventions)]` on by default
353362

363+
Future breakage diagnostic:
364+
warning: use of calling convention not supported on this target
365+
--> $DIR/unsupported.rs:290:1
366+
|
367+
LL | extern "cdecl" {}
368+
| ^^^^^^^^^^^^^^^^^
369+
|
370+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
371+
= note: for more information, see issue #137018 <https://github.com/rust-lang/rust/issues/137018>
372+
= note: `#[warn(unsupported_calling_conventions)]` on by default
373+
354374
Future breakage diagnostic:
355375
warning: use of calling convention not supported on this target
356376
--> $DIR/unsupported.rs:176:1

0 commit comments

Comments
 (0)