Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit cedd26b

Browse files
committed
Auto merge of rust-lang#99916 - dpaoliello:stablizerawdylib, r=wesleywiser
Stabilize raw-dylib for non-x86 This stabilizes the `raw-dylib` and `link_ordinal` features (rust-lang#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.
2 parents 87eb3e2 + c747501 commit cedd26b

File tree

46 files changed

+86
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+86
-231
lines changed

compiler/rustc_feature/src/active.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ declare_features! (
478478
/// Allows macro attributes on expressions, statements and non-inline modules.
479479
(active, proc_macro_hygiene, "1.30.0", Some(54727), None),
480480
/// Allows the use of raw-dylibs (RFC 2627).
481-
(incomplete, raw_dylib, "1.40.0", Some(58713), None),
481+
(active, raw_dylib, "CURRENT_RUSTC_VERSION", Some(58713), None),
482482
/// Allows `&raw const $place_expr` and `&raw mut $place_expr` expressions.
483483
(active, raw_ref_op, "1.41.0", Some(64490), None),
484484
/// Allows using the `#[register_tool]` attribute.

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
345345
ungated!(link_section, Normal, template!(NameValueStr: "name"), FutureWarnPreceding),
346346
ungated!(no_mangle, Normal, template!(Word), WarnFollowing, @only_local: true),
347347
ungated!(used, Normal, template!(Word, List: "compiler|linker"), WarnFollowing, @only_local: true),
348+
ungated!(link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding),
348349

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

407408
// Linking:
408409
gated!(naked, Normal, template!(Word), WarnFollowing, @only_local: true, naked_functions, experimental!(naked)),
409-
gated!(
410-
link_ordinal, Normal, template!(List: "ordinal"), ErrorPreceding, raw_dylib,
411-
experimental!(link_ordinal)
412-
),
413410

414411
// Plugins:
415412
BuiltinAttribute {

compiler/rustc_metadata/src/native_libs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,12 +113,12 @@ impl<'tcx> Collector<'tcx> {
113113
"raw-dylib" => {
114114
if !sess.target.is_like_windows {
115115
sess.emit_err(FrameworkOnlyWindows { span });
116-
} else if !features.raw_dylib {
116+
} else if !features.raw_dylib && sess.target.arch == "x86" {
117117
feature_err(
118118
&sess.parse_sess,
119119
sym::raw_dylib,
120120
span,
121-
"link kind `raw-dylib` is unstable",
121+
"link kind `raw-dylib` is unstable on x86",
122122
)
123123
.emit();
124124
}

compiler/rustc_typeck/src/collect.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3287,6 +3287,15 @@ fn should_inherit_track_caller(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
32873287

32883288
fn check_link_ordinal(tcx: TyCtxt<'_>, attr: &ast::Attribute) -> Option<u16> {
32893289
use rustc_ast::{Lit, LitIntType, LitKind};
3290+
if !tcx.features().raw_dylib && tcx.sess.target.arch == "x86" {
3291+
feature_err(
3292+
&tcx.sess.parse_sess,
3293+
sym::raw_dylib,
3294+
attr.span,
3295+
"`#[link_ordinal]` is unstable on x86",
3296+
)
3297+
.emit();
3298+
}
32903299
let meta_item_list = attr.meta_item_list();
32913300
let meta_item_list: Option<&[ast::NestedMetaItem]> = meta_item_list.as_ref().map(Vec::as_ref);
32923301
let sole_meta_list = match meta_item_list {

src/doc/unstable-book/src/language-features/raw-dylib.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ fn main() {
2626

2727
## Limitations
2828

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

33-
On the `i686-pc-windows-msvc` target, this feature supports only the `cdecl`, `stdcall`, `system`, and `fastcall`
34-
calling conventions.
31+
This feature is only supported on Windows.
32+
33+
On the `x86` architecture, this feature supports only the `cdecl`, `stdcall`, `system`, `fastcall`, and
34+
`vectorcall` calling conventions.

src/test/run-make/raw-dylib-alt-calling-convention/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#![feature(raw_dylib)]
21
#![feature(abi_vectorcall)]
2+
#![cfg_attr(target_arch = "x86", feature(raw_dylib))]
33

44
#[repr(C)]
55
#[derive(Clone)]

src/test/run-make/raw-dylib-link-ordinal/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(raw_dylib)]
1+
#![cfg_attr(target_arch = "x86", feature(raw_dylib))]
22

33
#[link(name = "exporter", kind = "raw-dylib")]
44
extern {

src/test/run-make/raw-dylib-stdcall-ordinal/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#![feature(raw_dylib)]
1+
#![cfg_attr(target_arch = "x86", feature(raw_dylib))]
22

33
#[link(name = "exporter", kind = "raw-dylib")]
44
extern "stdcall" {

src/test/ui/feature-gates/feature-gate-raw-dylib-2.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
// only-x86
12
#[link(name = "foo")]
23
extern "C" {
34
#[link_ordinal(42)]
4-
//~^ ERROR: the `#[link_ordinal]` attribute is an experimental feature
5+
//~^ ERROR: `#[link_ordinal]` is unstable on x86
56
fn foo();
67
#[link_ordinal(5)]
7-
//~^ ERROR: the `#[link_ordinal]` attribute is an experimental feature
8+
//~^ ERROR: `#[link_ordinal]` is unstable on x86
89
static mut imported_variable: i32;
910
}
1011

src/test/ui/feature-gates/feature-gate-raw-dylib-2.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
error[E0658]: the `#[link_ordinal]` attribute is an experimental feature
2-
--> $DIR/feature-gate-raw-dylib-2.rs:3:5
1+
error[E0658]: `#[link_ordinal]` is unstable on x86
2+
--> $DIR/feature-gate-raw-dylib-2.rs:4:5
33
|
44
LL | #[link_ordinal(42)]
55
| ^^^^^^^^^^^^^^^^^^^
66
|
77
= note: see issue #58713 <https://github.com/rust-lang/rust/issues/58713> for more information
88
= help: add `#![feature(raw_dylib)]` to the crate attributes to enable
99

10-
error[E0658]: the `#[link_ordinal]` attribute is an experimental feature
11-
--> $DIR/feature-gate-raw-dylib-2.rs:6:5
10+
error[E0658]: `#[link_ordinal]` is unstable on x86
11+
--> $DIR/feature-gate-raw-dylib-2.rs:7:5
1212
|
1313
LL | #[link_ordinal(5)]
1414
| ^^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)