Skip to content

Commit

Permalink
Auto merge of #99916 - dpaoliello:stablizerawdylib, r=wesleywiser
Browse files Browse the repository at this point in the history
Stabilize raw-dylib for non-x86

This stabilizes the `raw-dylib` and `link_ordinal` features (#58713) for non-x86 architectures (i.e., `x86_64`, `aarch64` and `thumbv7a`):
* Marked the `raw_dylib` feature as `active`.
* Marked the `link_ordinal` attribute as `ungated`.
* Added new errors if either feature is used on x86 targets without the `raw_dylib` feature being enabled.
* Updated tests to only set the `raw_dylib` feature when building for x86.
  • Loading branch information
bors committed Sep 10, 2022
2 parents 87eb3e2 + c747501 commit cedd26b
Show file tree
Hide file tree
Showing 46 changed files with 86 additions and 231 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_feature/src/active.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ declare_features! (
/// Allows macro attributes on expressions, statements and non-inline modules.
(active, proc_macro_hygiene, "1.30.0", Some(54727), None),
/// Allows the use of raw-dylibs (RFC 2627).
(incomplete, raw_dylib, "1.40.0", Some(58713), None),
(active, raw_dylib, "CURRENT_RUSTC_VERSION", Some(58713), None),
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
(active, raw_ref_op, "1.41.0", Some(64490), None),
/// Allows using the `#[register_tool]` attribute.
Expand Down
5 changes: 1 addition & 4 deletions compiler/rustc_feature/src/builtin_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
ungated!(link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
ungated!(no_mangle, Normal, template!(Word), WarnFollowing, @only_local: true),
ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, @only_local: true),
ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding),

// Limits:
ungated!(recursion_limit, CrateLevel, template!(NameValueStr: "N"), FutureWarnFollowing),
Expand Down Expand Up @@ -406,10 +407,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[

// Linking:
gated!(naked, Normal, template!(Word), WarnFollowing, @only_local: true, naked_functions, experimental!(naked)),
gated!(
link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding, raw_dylib,
experimental!(link_ordinal)
),

// Plugins:
BuiltinAttribute {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_metadata/src/native_libs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,12 +113,12 @@ impl<'tcx> Collector<'tcx> {
"raw-dylib" => {
if !sess.target.is_like_windows {
sess.emit_err(FrameworkOnlyWindows { span });
} else if !features.raw_dylib {
} else if !features.raw_dylib && sess.target.arch == "x86" {
feature_err(
&sess.parse_sess,
sym::raw_dylib,
span,
"link kind `raw-dylib` is unstable",
"link kind `raw-dylib` is unstable on x86",
)
.emit();
}
Expand Down
9 changes: 9 additions & 0 deletions compiler/rustc_typeck/src/collect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3287,6 +3287,15 @@ fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {

fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> {
use rustc_ast::{Lit, LitIntType, LitKind};
if !tcx.features().raw_dylib && tcx.sess.target.arch == "x86" {
feature_err(
&tcx.sess.parse_sess,
sym::raw_dylib,
attr.span,
"`#[link_ordinal]` is unstable on x86",
)
.emit();
}
let meta_item_list = attr.meta_item_list();
let meta_item_list: Option<&[ast::NestedMetaItem]> = meta_item_list.as_ref().map(Vec::as_ref);
let sole_meta_list = match meta_item_list {
Expand Down
10 changes: 5 additions & 5 deletions src/doc/unstable-book/src/language-features/raw-dylib.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ fn main() {

## Limitations

Currently, this feature is only supported on `-windows-msvc` targets. Non-Windows platforms don't have import
libraries, and an incompatibility between LLVM and the BFD linker means that it is not currently supported on
`-windows-gnu` targets.
This feature is unstable for the `x86` architecture, and stable for all other architectures.

On the `i686-pc-windows-msvc` target, this feature supports only the `cdecl`, `stdcall`, `system`, and `fastcall`
calling conventions.
This feature is only supported on Windows.

On the `x86` architecture, this feature supports only the `cdecl`, `stdcall`, `system`, `fastcall`, and
`vectorcall` calling conventions.
2 changes: 1 addition & 1 deletion src/test/run-make/raw-dylib-alt-calling-convention/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#![feature(raw_dylib)]
#![feature(abi_vectorcall)]
#![cfg_attr(target_arch = "x86", feature(raw_dylib))]

#[repr(C)]
#[derive(Clone)]
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/raw-dylib-link-ordinal/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(raw_dylib)]
#![cfg_attr(target_arch = "x86", feature(raw_dylib))]

#[link(name = "exporter", kind = "raw-dylib")]
extern {
Expand Down
2 changes: 1 addition & 1 deletion src/test/run-make/raw-dylib-stdcall-ordinal/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![feature(raw_dylib)]
#![cfg_attr(target_arch = "x86", feature(raw_dylib))]

#[link(name = "exporter", kind = "raw-dylib")]
extern "stdcall" {
Expand Down
5 changes: 3 additions & 2 deletions src/test/ui/feature-gates/feature-gate-raw-dylib-2.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// only-x86
#[link(name = "foo")]
extern "C" {
#[link_ordinal(42)]
//~^ ERROR: the `#[link_ordinal]` attribute is an experimental feature
//~^ ERROR: `#[link_ordinal]` is unstable on x86
fn foo();
#[link_ordinal(5)]
//~^ ERROR: the `#[link_ordinal]` attribute is an experimental feature
//~^ ERROR: `#[link_ordinal]` is unstable on x86
static mut imported_variable: i32;
}

Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/feature-gates/feature-gate-raw-dylib-2.stderr
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
error[E0658]: the `#[link_ordinal]` attribute is an experimental feature
--> $DIR/feature-gate-raw-dylib-2.rs:3:5
error[E0658]: `#[link_ordinal]` is unstable on x86
--> $DIR/feature-gate-raw-dylib-2.rs:4:5
|
LL | #[link_ordinal(42)]
| ^^^^^^^^^^^^^^^^^^^
|
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information
= help: add `#![feature(raw_dylib)]` to the crate attributes to enable

error[E0658]: the `#[link_ordinal]` attribute is an experimental feature
--> $DIR/feature-gate-raw-dylib-2.rs:6:5
error[E0658]: `#[link_ordinal]` is unstable on x86
--> $DIR/feature-gate-raw-dylib-2.rs:7:5
|
LL | #[link_ordinal(5)]
| ^^^^^^^^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// only-windows
// only-x86
#[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated")]
//~^ ERROR link kind `raw-dylib` is unstable
//~^ ERROR link kind `raw-dylib` is unstable on x86
//~| ERROR import name type is unstable
extern "C" {}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error[E0658]: link kind `raw-dylib` is unstable
error[E0658]: link kind `raw-dylib` is unstable on x86
--> $DIR/feature-gate-raw-dylib-import-name-type.rs:3:29
|
LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated")]
Expand Down
3 changes: 2 additions & 1 deletion src/test/ui/feature-gates/feature-gate-raw-dylib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// only-windows
// only-x86
#[link(name = "foo", kind = "raw-dylib")]
//~^ ERROR: link kind `raw-dylib` is unstable
//~^ ERROR: link kind `raw-dylib` is unstable on x86
extern "C" {}

fn main() {}
4 changes: 2 additions & 2 deletions src/test/ui/feature-gates/feature-gate-raw-dylib.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0658]: link kind `raw-dylib` is unstable
--> $DIR/feature-gate-raw-dylib.rs:2:29
error[E0658]: link kind `raw-dylib` is unstable on x86
--> $DIR/feature-gate-raw-dylib.rs:3:29
|
LL | #[link(name = "foo", kind = "raw-dylib")]
| ^^^^^^^^^^^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// only-windows
// only-x86
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete

#[link(name = "foo", kind = "raw-dylib", import_name_type = 6)]
//~^ ERROR import name type must be of the form `import_name_type = "string"`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/import-name-type-invalid-format.rs:3:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information

error: import name type must be of the form `import_name_type = "string"`
--> $DIR/import-name-type-invalid-format.rs:6:42
--> $DIR/import-name-type-invalid-format.rs:5:42
|
LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = 6)]
| ^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error; 1 warning emitted
error: aborting due to previous error

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// only-windows
// only-x86
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete

#[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated", import_name_type = "decorated")]
//~^ ERROR multiple `import_name_type` arguments in a single `#[link]` attribute
Expand Down
13 changes: 2 additions & 11 deletions src/test/ui/rfc-2627-raw-dylib/import-name-type-multiple.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/import-name-type-multiple.rs:4:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information

error: multiple `import_name_type` arguments in a single `#[link]` attribute
--> $DIR/import-name-type-multiple.rs:7:74
--> $DIR/import-name-type-multiple.rs:6:74
|
LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated", import_name_type = "decorated")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error; 1 warning emitted
error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// only-windows
// only-x86
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete

#[link(name = "foo", kind = "raw-dylib", import_name_type = "unknown")]
//~^ ERROR unknown import name type `unknown`, expected one of: decorated, noprefix, undecorated
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/import-name-type-unknown-value.rs:3:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information

error: unknown import name type `unknown`, expected one of: decorated, noprefix, undecorated
--> $DIR/import-name-type-unknown-value.rs:6:42
--> $DIR/import-name-type-unknown-value.rs:5:42
|
LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = "unknown")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error; 1 warning emitted
error: aborting due to previous error

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// only-windows
// only-x86
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete

#[link(name = "foo", import_name_type = "decorated")]
//~^ ERROR import name type can only be used with link kind `raw-dylib`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/import-name-type-unsupported-link-kind.rs:3:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information

error: import name type can only be used with link kind `raw-dylib`
--> $DIR/import-name-type-unsupported-link-kind.rs:6:22
--> $DIR/import-name-type-unsupported-link-kind.rs:5:22
|
LL | #[link(name = "foo", import_name_type = "decorated")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: import name type can only be used with link kind `raw-dylib`
--> $DIR/import-name-type-unsupported-link-kind.rs:10:39
--> $DIR/import-name-type-unsupported-link-kind.rs:9:39
|
LL | #[link(name = "bar", kind = "static", import_name_type = "decorated")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 2 previous errors

2 changes: 0 additions & 2 deletions src/test/ui/rfc-2627-raw-dylib/import-name-type-x86-only.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
// only-windows
// ignore-x86
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete
#[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated")]
//~^ ERROR import name type is only supported on x86
extern "C" { }
Expand Down
13 changes: 2 additions & 11 deletions src/test/ui/rfc-2627-raw-dylib/import-name-type-x86-only.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,8 @@
warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/import-name-type-x86-only.rs:3:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information

error: import name type is only supported on x86
--> $DIR/import-name-type-x86-only.rs:5:42
--> $DIR/import-name-type-x86-only.rs:3:42
|
LL | #[link(name = "foo", kind = "raw-dylib", import_name_type = "decorated")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

error: aborting due to previous error; 1 warning emitted
error: aborting due to previous error

3 changes: 1 addition & 2 deletions src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete
#![cfg_attr(target_arch = "x86", feature(raw_dylib))]

#[link(name="foo")]
extern "C" {
Expand Down
15 changes: 3 additions & 12 deletions src/test/ui/rfc-2627-raw-dylib/link-ordinal-and-name.stderr
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/link-ordinal-and-name.rs:1:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information

error: cannot use `#[link_name]` with `#[link_ordinal]`
--> $DIR/link-ordinal-and-name.rs:7:5
--> $DIR/link-ordinal-and-name.rs:6:5
|
LL | #[link_ordinal(42)]
| ^^^^^^^^^^^^^^^^^^^

error: cannot use `#[link_name]` with `#[link_ordinal]`
--> $DIR/link-ordinal-and-name.rs:11:5
--> $DIR/link-ordinal-and-name.rs:10:5
|
LL | #[link_ordinal(5)]
| ^^^^^^^^^^^^^^^^^^

error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete
#![cfg_attr(target_arch = "x86", feature(raw_dylib))]

#[link(name = "foo")]
extern "C" {
Expand Down
15 changes: 3 additions & 12 deletions src/test/ui/rfc-2627-raw-dylib/link-ordinal-invalid-format.stderr
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
warning: the feature `raw_dylib` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/link-ordinal-invalid-format.rs:1:12
|
LL | #![feature(raw_dylib)]
| ^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information

error: illegal ordinal format in `link_ordinal`
--> $DIR/link-ordinal-invalid-format.rs:6:5
--> $DIR/link-ordinal-invalid-format.rs:5:5
|
LL | #[link_ordinal("JustMonika")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: an unsuffixed integer value, e.g., `1`, is expected

error: illegal ordinal format in `link_ordinal`
--> $DIR/link-ordinal-invalid-format.rs:9:5
--> $DIR/link-ordinal-invalid-format.rs:8:5
|
LL | #[link_ordinal("JustMonika")]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: an unsuffixed integer value, e.g., `1`, is expected

error: aborting due to 2 previous errors; 1 warning emitted
error: aborting due to 2 previous errors

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![feature(raw_dylib)]
//~^ WARN the feature `raw_dylib` is incomplete
#![cfg_attr(target_arch = "x86", feature(raw_dylib))]

#[link(name = "foo")]
extern "C" {
Expand Down
Loading

0 comments on commit cedd26b

Please sign in to comment.