Skip to content

Commit 8240e7a

Browse files
committed
Replace per-target ABI denylist with an allowlist
It makes very little sense to maintain denylists of ABIs when, as far as non-generic ABIs are concerned, targets usually only support a small subset of the available ABIs. This has historically been a cause of bugs such as us allowing use of the platform-specific ABIs on x86 targets – these in turn would cause LLVM errors or assertions to fire. Fixes #57182 Sponsored by: standard.ai
1 parent 96859db commit 8240e7a

File tree

101 files changed

+1507
-1038
lines changed

Some content is hidden

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

101 files changed

+1507
-1038
lines changed

compiler/rustc_lint_defs/src/builtin.rs

+47
Original file line numberDiff line numberDiff line change
@@ -2974,6 +2974,7 @@ declare_lint_pass! {
29742974
LARGE_ASSIGNMENTS,
29752975
FUTURE_PRELUDE_COLLISION,
29762976
RESERVED_PREFIX,
2977+
UNSUPPORTED_CALLING_CONVENTIONS,
29772978
]
29782979
}
29792980

@@ -3303,3 +3304,49 @@ declare_lint! {
33033304
};
33043305
crate_level_only
33053306
}
3307+
3308+
declare_lint! {
3309+
/// The `unsupported_calling_conventions` lint is output whenever there is an use of the
3310+
/// `stdcall`, `fastcall`, `thiscall`, `vectorcall` calling conventions (or their unwind
3311+
/// variants) on targets that cannot meaningfully be supported for the requested target.
3312+
///
3313+
/// For example `stdcall` does not make much sense for a x86_64 or, more apparently, powerpc
3314+
/// code, because this calling convention was never specified for those targets.
3315+
///
3316+
/// Historically MSVC toolchains have fallen back to the regular C calling convention for
3317+
/// targets other than x86, but Rust doesn't really see a similar need to introduce a similar
3318+
/// hack across many more targets.
3319+
///
3320+
/// ### Example
3321+
///
3322+
/// ```rust,ignore (needs specific targets)
3323+
/// extern "stdcall" fn stdcall() {}
3324+
/// ```
3325+
///
3326+
/// This will produce:
3327+
///
3328+
/// ```text
3329+
/// warning: use of calling convention not supported on this target
3330+
/// --> $DIR/unsupported.rs:39:1
3331+
/// |
3332+
/// LL | extern "stdcall" fn stdcall() {}
3333+
/// | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3334+
/// |
3335+
/// = note: `#[warn(unsupported_calling_conventions)]` on by default
3336+
/// = warning: this was previously accepted by the compiler but is being phased out;
3337+
/// it will become a hard error in a future release!
3338+
/// = note: for more information, see issue ...
3339+
/// ```
3340+
///
3341+
/// ### Explanation
3342+
///
3343+
/// On most of the targets the behaviour of `stdcall` and similar calling conventions is not
3344+
/// defined at all, but was previously accepted due to a bug in the implementation of the
3345+
/// compiler.
3346+
pub UNSUPPORTED_CALLING_CONVENTIONS,
3347+
Warn,
3348+
"use of unsupported calling convention",
3349+
@future_incompatible = FutureIncompatibleInfo {
3350+
reference: "issue #00000 <https://github.com/rust-lang/rust/issues/00000>",
3351+
};
3352+
}

compiler/rustc_target/src/spec/aarch64_apple_ios.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::apple_sdk_base::{opts, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("ios", Arch::Arm64);
65
Target {
76
llvm_target: "arm64-apple-ios".to_string(),
87
pointer_width: 64,
@@ -11,7 +10,6 @@ pub fn target() -> Target {
1110
options: TargetOptions {
1211
features: "+neon,+fp-armv8,+apple-a7".to_string(),
1312
max_atomic_width: Some(128),
14-
unsupported_abis: super::arm_base::unsupported_abis(),
1513
forces_embed_bitcode: true,
1614
frame_pointer: FramePointer::NonLeaf,
1715
// Taken from a clang build on Xcode 11.4.1.
@@ -25,7 +23,7 @@ pub fn target() -> Target {
2523
darwinpcs\0\
2624
-Os\0"
2725
.to_string(),
28-
..base
26+
..opts("ios", Arch::Arm64)
2927
},
3028
}
3129
}

compiler/rustc_target/src/spec/aarch64_apple_ios_macabi.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::apple_sdk_base::{opts, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("ios", Arch::Arm64_macabi);
65
Target {
76
llvm_target: "arm64-apple-ios14.0-macabi".to_string(),
87
pointer_width: 64,
@@ -11,7 +10,6 @@ pub fn target() -> Target {
1110
options: TargetOptions {
1211
features: "+neon,+fp-armv8,+apple-a12".to_string(),
1312
max_atomic_width: Some(128),
14-
unsupported_abis: super::arm_base::unsupported_abis(),
1513
forces_embed_bitcode: true,
1614
frame_pointer: FramePointer::NonLeaf,
1715
// Taken from a clang build on Xcode 11.4.1.
@@ -23,7 +21,7 @@ pub fn target() -> Target {
2321
-disable-llvm-passes\0\
2422
-Os\0"
2523
.to_string(),
26-
..base
24+
..opts("ios", Arch::Arm64_macabi)
2725
},
2826
}
2927
}

compiler/rustc_target/src/spec/aarch64_apple_ios_sim.rs

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ pub fn target() -> Target {
1919
options: TargetOptions {
2020
features: "+neon,+fp-armv8,+apple-a7".to_string(),
2121
max_atomic_width: Some(128),
22-
unsupported_abis: super::arm_base::unsupported_abis(),
2322
forces_embed_bitcode: true,
2423
frame_pointer: FramePointer::NonLeaf,
2524
// Taken from a clang build on Xcode 11.4.1.

compiler/rustc_target/src/spec/aarch64_apple_tvos.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::apple_sdk_base::{opts, Arch};
22
use crate::spec::{FramePointer, Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let base = opts("tvos", Arch::Arm64);
65
Target {
76
llvm_target: "arm64-apple-tvos".to_string(),
87
pointer_width: 64,
@@ -11,10 +10,9 @@ pub fn target() -> Target {
1110
options: TargetOptions {
1211
features: "+neon,+fp-armv8,+apple-a7".to_string(),
1312
max_atomic_width: Some(128),
14-
unsupported_abis: super::arm_base::unsupported_abis(),
1513
forces_embed_bitcode: true,
1614
frame_pointer: FramePointer::NonLeaf,
17-
..base
15+
..opts("tvos", Arch::Arm64)
1816
},
1917
}
2018
}

compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@ use crate::abi::Endian;
22
use crate::spec::{Target, TargetOptions};
33

44
pub fn target() -> Target {
5-
let mut base = super::linux_gnu_base::opts();
6-
base.max_atomic_width = Some(128);
7-
85
Target {
96
llvm_target: "aarch64_be-unknown-linux-gnu".to_string(),
107
pointer_width: 64,
118
data_layout: "E-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
129
arch: "aarch64".to_string(),
1310
options: TargetOptions {
14-
unsupported_abis: super::arm_base::unsupported_abis(),
11+
max_atomic_width: Some(128),
1512
mcount: "\u{1}_mcount".to_string(),
1613
endian: Endian::Big,
17-
..base
14+
..super::linux_gnu_base::opts()
1815
},
1916
}
2017
}

compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu_ilp32.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,6 @@ pub fn target() -> Target {
1010
pointer_width: 32,
1111
data_layout: "E-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
1212
arch: "aarch64".to_string(),
13-
options: TargetOptions {
14-
unsupported_abis: super::arm_base::unsupported_abis(),
15-
mcount: "\u{1}_mcount".to_string(),
16-
endian: Endian::Big,
17-
..base
18-
},
13+
options: TargetOptions { mcount: "\u{1}_mcount".to_string(), endian: Endian::Big, ..base },
1914
}
2015
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::spec::{SanitizerSet, Target, TargetOptions};
22

33
pub fn target() -> Target {
4-
let mut base = super::fuchsia_base::opts();
5-
base.max_atomic_width = Some(128);
6-
base.supported_sanitizers = SanitizerSet::ADDRESS;
7-
84
Target {
95
llvm_target: "aarch64-fuchsia".to_string(),
106
pointer_width: 64,
117
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
128
arch: "aarch64".to_string(),
13-
options: TargetOptions { unsupported_abis: super::arm_base::unsupported_abis(), ..base },
9+
options: TargetOptions {
10+
max_atomic_width: Some(128),
11+
supported_sanitizers: SanitizerSet::ADDRESS,
12+
..super::fuchsia_base::opts()
13+
},
1414
}
1515
}

compiler/rustc_target/src/spec/aarch64_linux_android.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,18 @@ use crate::spec::{SanitizerSet, Target, TargetOptions};
44
// for target ABI requirements.
55

66
pub fn target() -> Target {
7-
let mut base = super::android_base::opts();
8-
base.max_atomic_width = Some(128);
9-
// As documented in https://developer.android.com/ndk/guides/cpu-features.html
10-
// the neon (ASIMD) and FP must exist on all android aarch64 targets.
11-
base.features = "+neon,+fp-armv8".to_string();
12-
base.supported_sanitizers = SanitizerSet::HWADDRESS;
137
Target {
148
llvm_target: "aarch64-linux-android".to_string(),
159
pointer_width: 64,
1610
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
1711
arch: "aarch64".to_string(),
18-
options: TargetOptions { unsupported_abis: super::arm_base::unsupported_abis(), ..base },
12+
options: TargetOptions {
13+
max_atomic_width: Some(128),
14+
// As documented in https://developer.android.com/ndk/guides/cpu-features.html
15+
// the neon (ASIMD) and FP must exist on all android aarch64 targets.
16+
features: "+neon,+fp-armv8".to_string(),
17+
supported_sanitizers: SanitizerSet::HWADDRESS,
18+
..super::android_base::opts()
19+
},
1920
}
2021
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use crate::spec::{Target, TargetOptions};
22

33
pub fn target() -> Target {
4-
let mut base = super::freebsd_base::opts();
5-
base.max_atomic_width = Some(128);
6-
74
Target {
85
llvm_target: "aarch64-unknown-freebsd".to_string(),
96
pointer_width: 64,
107
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
118
arch: "aarch64".to_string(),
12-
options: TargetOptions { unsupported_abis: super::arm_base::unsupported_abis(), ..base },
9+
options: TargetOptions { max_atomic_width: Some(128), ..super::freebsd_base::opts() },
1310
}
1411
}
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
11
use crate::spec::{SanitizerSet, Target, TargetOptions};
22

33
pub fn target() -> Target {
4-
let mut base = super::linux_gnu_base::opts();
5-
base.max_atomic_width = Some(128);
6-
base.supported_sanitizers = SanitizerSet::ADDRESS
7-
| SanitizerSet::LEAK
8-
| SanitizerSet::MEMORY
9-
| SanitizerSet::THREAD
10-
| SanitizerSet::HWADDRESS;
11-
124
Target {
135
llvm_target: "aarch64-unknown-linux-gnu".to_string(),
146
pointer_width: 64,
157
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
168
arch: "aarch64".to_string(),
179
options: TargetOptions {
18-
unsupported_abis: super::arm_base::unsupported_abis(),
1910
mcount: "\u{1}_mcount".to_string(),
20-
..base
11+
max_atomic_width: Some(128),
12+
supported_sanitizers: SanitizerSet::ADDRESS
13+
| SanitizerSet::LEAK
14+
| SanitizerSet::MEMORY
15+
| SanitizerSet::THREAD
16+
| SanitizerSet::HWADDRESS,
17+
..super::linux_gnu_base::opts()
2118
},
2219
}
2320
}
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
use crate::spec::{Target, TargetOptions};
22

33
pub fn target() -> Target {
4-
let mut base = super::linux_gnu_base::opts();
5-
base.max_atomic_width = Some(128);
6-
74
Target {
85
llvm_target: "aarch64-unknown-linux-gnu_ilp32".to_string(),
96
pointer_width: 32,
107
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
118
arch: "aarch64".to_string(),
129
options: TargetOptions {
13-
unsupported_abis: super::arm_base::unsupported_abis(),
10+
max_atomic_width: Some(128),
1411
mcount: "\u{1}_mcount".to_string(),
15-
..base
12+
..super::linux_gnu_base::opts()
1613
},
1714
}
1815
}

compiler/rustc_target/src/spec/aarch64_unknown_linux_musl.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ pub fn target() -> Target {
99
pointer_width: 64,
1010
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
1111
arch: "aarch64".to_string(),
12-
options: TargetOptions {
13-
unsupported_abis: super::arm_base::unsupported_abis(),
14-
mcount: "\u{1}_mcount".to_string(),
15-
..base
16-
},
12+
options: TargetOptions { mcount: "\u{1}_mcount".to_string(), ..base },
1713
}
1814
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
use crate::spec::{Target, TargetOptions};
22

33
pub fn target() -> Target {
4-
let mut base = super::netbsd_base::opts();
5-
base.max_atomic_width = Some(128);
6-
base.unsupported_abis = super::arm_base::unsupported_abis();
7-
84
Target {
95
llvm_target: "aarch64-unknown-netbsd".to_string(),
106
pointer_width: 64,
117
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
128
arch: "aarch64".to_string(),
13-
options: TargetOptions { mcount: "__mcount".to_string(), ..base },
9+
options: TargetOptions {
10+
mcount: "__mcount".to_string(),
11+
max_atomic_width: Some(128),
12+
..super::netbsd_base::opts()
13+
},
1414
}
1515
}

compiler/rustc_target/src/spec/aarch64_unknown_none.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub fn target() -> Target {
1818
disable_redzone: true,
1919
max_atomic_width: Some(128),
2020
panic_strategy: PanicStrategy::Abort,
21-
unsupported_abis: super::arm_base::unsupported_abis(),
2221
..Default::default()
2322
};
2423
Target {

compiler/rustc_target/src/spec/aarch64_unknown_none_softfloat.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub fn target() -> Target {
1818
disable_redzone: true,
1919
max_atomic_width: Some(128),
2020
panic_strategy: PanicStrategy::Abort,
21-
unsupported_abis: super::arm_base::unsupported_abis(),
2221
..Default::default()
2322
};
2423
Target {
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
1-
use crate::spec::Target;
1+
use crate::spec::{Target, TargetOptions};
22

33
pub fn target() -> Target {
4-
let mut base = super::openbsd_base::opts();
5-
base.max_atomic_width = Some(128);
6-
base.unsupported_abis = super::arm_base::unsupported_abis();
7-
84
Target {
95
llvm_target: "aarch64-unknown-openbsd".to_string(),
106
pointer_width: 64,
117
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
128
arch: "aarch64".to_string(),
13-
options: base,
9+
options: TargetOptions { max_atomic_width: Some(128), ..super::openbsd_base::opts() },
1410
}
1511
}
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
use crate::spec::{Target, TargetOptions};
22

33
pub fn target() -> Target {
4-
let mut base = super::vxworks_base::opts();
5-
base.max_atomic_width = Some(128);
6-
74
Target {
85
llvm_target: "aarch64-unknown-linux-gnu".to_string(),
96
pointer_width: 64,
107
data_layout: "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
118
arch: "aarch64".to_string(),
12-
options: TargetOptions { unsupported_abis: super::arm_base::unsupported_abis(), ..base },
9+
options: TargetOptions { max_atomic_width: Some(128), ..super::vxworks_base::opts() },
1310
}
1411
}

0 commit comments

Comments
 (0)