Skip to content

Commit ca99e3e

Browse files
committed
Auto merge of #86922 - joshtriplett:target-abi, r=oli-obk
target abi Implement cfg(target_abi) (RFC 2992) Add an `abi` field to `TargetOptions`, defaulting to "". Support using `cfg(target_abi = "...")` for conditional compilation on that field. Gated by `feature(cfg_target_abi)`. Add a test for `target_abi`, and a test for the feature gate. Add `target_abi` to tidy as a platform-specific cfg. Update targets to use `target_abi` All eabi targets have `target_abi = "eabi".` All eabihf targets have `target_abi = "eabihf"`. `armv6_unknown_freebsd` and `armv7_unknown_freebsd` have `target_abi = "eabihf"`. All abi64 targets have `target_abi = "abi64"`. All ilp32 targets have `target_abi = "ilp32"`. All softfloat targets have `target_abi = "softfloat"`. All *-uwp-windows-* targets have `target_abi = "uwp"`. All spe targets have `target_abi = "spe"`. All macabi targets have `target_abi = "macabi"`. aarch64-apple-ios-sim has `target_abi = "sim"`. `x86_64-fortanix-unknown-sgx` has `target_abi = "fortanix"`. `x86_64-unknown-linux-gnux32` has `target_abi = "x32"`. Add FIXME entries for targets for which existing values need to change once `cfg_target_abi` becomes stable. (All of them are tier 3 targets.) Add a test for `target_abi` in `--print cfg`.
2 parents 5aff6dd + c3fbafd commit ca99e3e

File tree

62 files changed

+170
-8
lines changed

Some content is hidden

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

62 files changed

+170
-8
lines changed

compiler/rustc_feature/src/active.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,9 @@ declare_features! (
684684
/// Allows qualified paths in struct expressions, struct patterns and tuple struct patterns.
685685
(active, more_qualified_paths, "1.54.0", Some(86935), None),
686686

687+
/// Allows `cfg(target_abi = "...")`.
688+
(active, cfg_target_abi, "1.55.0", Some(80970), None),
689+
687690
// -------------------------------------------------------------------------
688691
// feature-group-end: actual feature gates
689692
// -------------------------------------------------------------------------

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ pub type GatedCfg = (Symbol, Symbol, GateFn);
2323
/// `cfg(...)`'s that are feature gated.
2424
const GATED_CFGS: &[GatedCfg] = &[
2525
// (name in cfg, feature, function to check if the feature is enabled)
26+
(sym::target_abi, sym::cfg_target_abi, cfg_fn!(cfg_target_abi)),
2627
(sym::target_thread_local, sym::cfg_target_thread_local, cfg_fn!(cfg_target_thread_local)),
2728
(sym::target_has_atomic, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),
2829
(sym::target_has_atomic_load_store, sym::cfg_target_has_atomic, cfg_fn!(cfg_target_has_atomic)),

compiler/rustc_session/src/config.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
805805
let wordsz = sess.target.pointer_width.to_string();
806806
let os = &sess.target.os;
807807
let env = &sess.target.env;
808+
let abi = &sess.target.abi;
808809
let vendor = &sess.target.vendor;
809810
let min_atomic_width = sess.target.min_atomic_width();
810811
let max_atomic_width = sess.target.max_atomic_width();
@@ -814,7 +815,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
814815
});
815816

816817
let mut ret = FxHashSet::default();
817-
ret.reserve(6); // the minimum number of insertions
818+
ret.reserve(7); // the minimum number of insertions
818819
// Target bindings.
819820
ret.insert((sym::target_os, Some(Symbol::intern(os))));
820821
for fam in &sess.target.families {
@@ -829,6 +830,7 @@ fn default_configuration(sess: &Session) -> CrateConfig {
829830
ret.insert((sym::target_endian, Some(Symbol::intern(end.as_str()))));
830831
ret.insert((sym::target_pointer_width, Some(Symbol::intern(&wordsz))));
831832
ret.insert((sym::target_env, Some(Symbol::intern(env))));
833+
ret.insert((sym::target_abi, Some(Symbol::intern(abi))));
832834
ret.insert((sym::target_vendor, Some(Symbol::intern(vendor))));
833835
if sess.target.has_elf_tls {
834836
ret.insert((sym::target_thread_local, None));

compiler/rustc_span/src/symbol.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,7 @@ symbols! {
354354
cfg_eval,
355355
cfg_panic,
356356
cfg_sanitize,
357+
cfg_target_abi,
357358
cfg_target_feature,
358359
cfg_target_has_atomic,
359360
cfg_target_thread_local,
@@ -1203,6 +1204,7 @@ symbols! {
12031204
sync,
12041205
sync_trait,
12051206
t32,
1207+
target_abi,
12061208
target_arch,
12071209
target_endian,
12081210
target_env,

compiler/rustc_target/src/spec/aarch64_be_unknown_linux_gnu_ilp32.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ 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 { mcount: "\u{1}_mcount".to_string(), endian: Endian::Big, ..base },
13+
options: TargetOptions {
14+
abi: "ilp32".to_string(),
15+
mcount: "\u{1}_mcount".to_string(),
16+
endian: Endian::Big,
17+
..base
18+
},
1419
}
1520
}

compiler/rustc_target/src/spec/aarch64_unknown_linux_gnu_ilp32.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub fn target() -> Target {
77
data_layout: "e-m:e-p:32:32-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128".to_string(),
88
arch: "aarch64".to_string(),
99
options: TargetOptions {
10+
abi: "ilp32".to_string(),
1011
max_atomic_width: Some(128),
1112
mcount: "\u{1}_mcount".to_string(),
1213
..super::linux_gnu_base::opts()

compiler/rustc_target/src/spec/aarch64_unknown_none_softfloat.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use super::{LinkerFlavor, LldFlavor, PanicStrategy, RelocModel, Target, TargetOp
1010

1111
pub fn target() -> Target {
1212
let opts = TargetOptions {
13+
abi: "softfloat".to_string(),
1314
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
1415
linker: Some("rust-lld".to_owned()),
1516
features: "+strict-align,-neon,-fp-armv8".to_string(),

compiler/rustc_target/src/spec/apple_sdk_base.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,15 @@ pub enum Arch {
1414
Arm64_sim,
1515
}
1616

17+
fn target_abi(arch: Arch) -> String {
18+
match arch {
19+
Armv7 | Armv7s | Arm64 | I386 | X86_64 => "",
20+
X86_64_macabi | Arm64_macabi => "macabi",
21+
Arm64_sim => "sim",
22+
}
23+
.to_string()
24+
}
25+
1726
fn target_cpu(arch: Arch) -> String {
1827
match arch {
1928
Armv7 => "cortex-a8", // iOS7 is supported on iPhone 4 and higher
@@ -39,6 +48,7 @@ fn link_env_remove(arch: Arch) -> Vec<String> {
3948

4049
pub fn opts(os: &str, arch: Arch) -> TargetOptions {
4150
TargetOptions {
51+
abi: target_abi(arch),
4252
cpu: target_cpu(arch),
4353
dynamic_linking: false,
4454
executables: true,

compiler/rustc_target/src/spec/arm_linux_androideabi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub fn target() -> Target {
77
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
88
arch: "arm".to_string(),
99
options: TargetOptions {
10+
abi: "eabi".to_string(),
1011
// https://developer.android.com/ndk/guides/abis.html#armeabi
1112
features: "+strict-align,+v5te".to_string(),
1213
max_atomic_width: Some(32),

compiler/rustc_target/src/spec/arm_unknown_linux_gnueabi.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ pub fn target() -> Target {
77
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
88
arch: "arm".to_string(),
99
options: TargetOptions {
10+
abi: "eabi".to_string(),
1011
features: "+strict-align,+v6".to_string(),
1112
max_atomic_width: Some(64),
1213
mcount: "\u{1}__gnu_mcount_nc".to_string(),

0 commit comments

Comments
 (0)