Skip to content

Commit bed4a73

Browse files
committed
Unify the arm*-none-* and thumb*-none-* target descriptions.
1 parent 38987c0 commit bed4a73

25 files changed

+36
-168
lines changed

compiler/rustc_target/src/spec/base/thumb.rs renamed to compiler/rustc_target/src/spec/base/arm_none.rs

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,4 @@
1-
// These `thumbv*` targets cover the ARM Cortex-M family of processors which are widely used in
2-
// microcontrollers. Namely, all these processors:
3-
//
4-
// - Cortex-M0
5-
// - Cortex-M0+
6-
// - Cortex-M1
7-
// - Cortex-M3
8-
// - Cortex-M4(F)
9-
// - Cortex-M7(F)
10-
// - Cortex-M23
11-
// - Cortex-M33
12-
//
13-
// We have opted for these instead of one target per processor (e.g., `cortex-m0`, `cortex-m3`,
14-
// etc) because the differences between some processors like the cortex-m0 and cortex-m1 are almost
15-
// nonexistent from the POV of codegen so it doesn't make sense to have separate targets for them.
16-
// And if differences exist between two processors under the same target, rustc flags can be used to
17-
// optimize for one processor or the other.
18-
//
19-
// Also, we have not chosen a single target (`arm-none-eabi`) like GCC does because this makes
20-
// difficult to integrate Rust code and C code. Targeting the Cortex-M4 requires different gcc flags
21-
// than the ones you would use for the Cortex-M0 and with a single target it'd be impossible to
22-
// differentiate one processor from the other.
23-
//
24-
// About arm vs thumb in the name. The Cortex-M devices only support the Thumb instruction set,
25-
// which is more compact (higher code density), and not the ARM instruction set. That's why LLVM
26-
// triples use thumb instead of arm. We follow suit because having thumb in the name let us
27-
// differentiate these targets from our other `arm(v7)-*-*-gnueabi(hf)` targets in the context of
28-
// build scripts / gcc flags.
1+
// These are the baseline settings for 32-bit bare-metal Arm targets using the EABI or EABIHF ABI.
292

303
use crate::spec::{Cc, FramePointer, LinkerFlavor, Lld, PanicStrategy, RelocModel, TargetOptions};
314

compiler/rustc_target/src/spec/base/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
pub(crate) mod aix;
22
pub(crate) mod android;
33
pub mod apple;
4+
pub(crate) mod arm_none;
45
pub(crate) mod avr;
56
pub(crate) mod bpf;
67
pub(crate) mod cygwin;
@@ -31,7 +32,6 @@ pub(crate) mod redox;
3132
pub(crate) mod solaris;
3233
pub(crate) mod solid;
3334
pub(crate) mod teeos;
34-
pub(crate) mod thumb;
3535
pub(crate) mod uefi_msvc;
3636
pub(crate) mod unikraft_linux_musl;
3737
pub(crate) mod vxworks;

compiler/rustc_target/src/spec/targets/armv4t_none_eabi.rs

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -29,36 +29,11 @@ pub(crate) fn target() -> Target {
2929
options: TargetOptions {
3030
abi: Abi::Eabi,
3131
llvm_floatabi: Some(FloatAbi::Soft),
32-
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
33-
linker: Some("rust-lld".into()),
3432
asm_args: cvs!["-mthumb-interwork", "-march=armv4t", "-mlittle-endian",],
35-
// Force-enable 32-bit atomics, which allows the use of atomic load/store only.
36-
// The resulting atomics are ABI incompatible with atomics backed by libatomic.
3733
features: "+soft-float,+strict-align".into(),
3834
atomic_cas: false,
3935
has_thumb_interworking: true,
40-
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
41-
linker: Some("rust-lld".into()),
42-
// Because these devices have very little resources having an unwinder is too onerous so we
43-
// default to "abort" because the "unwind" strategy is very rare.
44-
panic_strategy: PanicStrategy::Abort,
45-
// Similarly, one almost always never wants to use relocatable code because of the extra
46-
// costs it involves.
47-
relocation_model: RelocModel::Static,
48-
// When this section is added a volatile load to its start address is also generated. This
49-
// volatile load is a footgun as it can end up loading an invalid memory address, depending
50-
// on how the user set up their linker scripts. This section adds pretty printer for stuff
51-
// like std::Vec, which is not that used in no-std context, so it's best to left it out
52-
// until we figure a way to add the pretty printers without requiring a volatile load cf.
53-
// rust-lang/rust#44993.
54-
emit_debug_gdb_scripts: false,
55-
// LLVM is eager to trash the link register when calling `noreturn` functions, which
56-
// breaks debugging. Preserve LR by default to prevent that from happening.
57-
frame_pointer: FramePointer::Always,
58-
// ARM supports multiple ABIs for enums, the linux one matches the default of 32 here
59-
// but any arm-none or thumb-none target will be defaulted to 8 on GCC.
60-
c_enum_min_bits: Some(8),
61-
..Default::default()
36+
..base::arm_none::opts()
6237
},
6338
}
6439
}
Lines changed: 2 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Targets the ARMv5TE, with code as `a32` code by default.
22
3-
use crate::spec::{
4-
Abi, Arch, FloatAbi, FramePointer, Target, TargetMetadata, TargetOptions, base, cvs,
5-
};
3+
use crate::spec::{Abi, Arch, FloatAbi, Target, TargetMetadata, TargetOptions, base, cvs};
64

75
pub(crate) fn target() -> Target {
86
Target {
@@ -19,37 +17,11 @@ pub(crate) fn target() -> Target {
1917
options: TargetOptions {
2018
abi: Abi::Eabi,
2119
llvm_floatabi: Some(FloatAbi::Soft),
22-
// extra args passed to the external assembler (assuming `arm-none-eabi-as`):
23-
// * activate t32/a32 interworking
24-
// * use arch ARMv5TE
25-
// * use little-endian
2620
asm_args: cvs!["-mthumb-interwork", "-march=armv5te", "-mlittle-endian",],
27-
// minimum extra features, these cannot be disabled via -C
2821
features: "+soft-float,+strict-align".into(),
2922
atomic_cas: false,
3023
has_thumb_interworking: true,
31-
linker_flavor: LinkerFlavor::Gnu(Cc::No, Lld::Yes),
32-
linker: Some("rust-lld".into()),
33-
// Because these devices have very little resources having an unwinder is too onerous so we
34-
// default to "abort" because the "unwind" strategy is very rare.
35-
panic_strategy: PanicStrategy::Abort,
36-
// Similarly, one almost always never wants to use relocatable code because of the extra
37-
// costs it involves.
38-
relocation_model: RelocModel::Static,
39-
// When this section is added a volatile load to its start address is also generated. This
40-
// volatile load is a footgun as it can end up loading an invalid memory address, depending
41-
// on how the user set up their linker scripts. This section adds pretty printer for stuff
42-
// like std::Vec, which is not that used in no-std context, so it's best to left it out
43-
// until we figure a way to add the pretty printers without requiring a volatile load cf.
44-
// rust-lang/rust#44993.
45-
emit_debug_gdb_scripts: false,
46-
// LLVM is eager to trash the link register when calling `noreturn` functions, which
47-
// breaks debugging. Preserve LR by default to prevent that from happening.
48-
frame_pointer: FramePointer::Always,
49-
// ARM supports multiple ABIs for enums, the linux one matches the default of 32 here
50-
// but any arm-none or thumb-none target will be defaulted to 8 on GCC.
51-
c_enum_min_bits: Some(8),
52-
..Default::default()
24+
..base::arm_none::opts()
5325
},
5426
}
5527
}

compiler/rustc_target/src/spec/targets/thumbv4t_none_eabi.rs

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,7 @@
99
//! The default link script is very likely wrong, so you should use
1010
//! `-Clink-arg=-Tmy_script.ld` to override that with a correct linker script.
1111
12-
use crate::spec::{
13-
Abi, Arch, FloatAbi, FramePointer, PanicStrategy, RelocModel, Target, TargetMetadata,
14-
TargetOptions, base, cvs,
15-
};
12+
use crate::spec::{Abi, Arch, FloatAbi, Target, TargetMetadata, TargetOptions, base, cvs};
1613

1714
pub(crate) fn target() -> Target {
1815
Target {
@@ -25,44 +22,15 @@ pub(crate) fn target() -> Target {
2522
},
2623
pointer_width: 32,
2724
arch: Arch::Arm,
28-
/* Data layout args are '-' separated:
29-
* little endian
30-
* stack is 64-bit aligned (EABI)
31-
* pointers are 32-bit
32-
* i64 must be 64-bit aligned (EABI)
33-
* mangle names with ELF style
34-
* native integers are 32-bit
35-
* All other elements are default
36-
*/
3725
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
3826
options: TargetOptions {
3927
abi: Abi::Eabi,
4028
llvm_floatabi: Some(FloatAbi::Soft),
41-
42-
// extra args passed to the external assembler (assuming `arm-none-eabi-as`):
43-
// * activate t32/a32 interworking
44-
// * use arch ARMv4T
45-
// * use little-endian
4629
asm_args: cvs!["-mthumb-interwork", "-march=armv4t", "-mlittle-endian",],
47-
48-
// minimum extra features, these cannot be disabled via -C
49-
// Also force-enable 32-bit atomics, which allows the use of atomic load/store only.
50-
// The resulting atomics are ABI incompatible with atomics backed by libatomic.
51-
features: "+soft-float,+strict-align,+atomics-32".into(),
52-
53-
panic_strategy: PanicStrategy::Abort,
54-
relocation_model: RelocModel::Static,
55-
// suggested from thumb_base, rust-lang/rust#44993.
56-
emit_debug_gdb_scripts: false,
57-
frame_pointer: FramePointer::MayOmit,
58-
59-
main_needs_argc_argv: false,
60-
61-
// don't have atomic compare-and-swap
30+
features: "+soft-float,+strict-align".into(),
6231
atomic_cas: false,
6332
has_thumb_interworking: true,
64-
65-
..base::thumb::opts()
33+
..base::arm_none::opts()
6634
},
6735
}
6836
}
Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Targets the ARMv5TE, with code as `t32` code by default.
22
3-
use crate::spec::{
4-
Abi, Arch, FloatAbi, FramePointer, Target, TargetMetadata, TargetOptions, base, cvs,
5-
};
3+
use crate::spec::{Abi, Arch, FloatAbi, Target, TargetMetadata, TargetOptions, base, cvs};
64

75
pub(crate) fn target() -> Target {
86
Target {
@@ -15,36 +13,15 @@ pub(crate) fn target() -> Target {
1513
},
1614
pointer_width: 32,
1715
arch: Arch::Arm,
18-
/* Data layout args are '-' separated:
19-
* little endian
20-
* stack is 64-bit aligned (EABI)
21-
* pointers are 32-bit
22-
* i64 must be 64-bit aligned (EABI)
23-
* mangle names with ELF style
24-
* native integers are 32-bit
25-
* All other elements are default
26-
*/
2716
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
28-
2917
options: TargetOptions {
3018
abi: Abi::Eabi,
3119
llvm_floatabi: Some(FloatAbi::Soft),
32-
// extra args passed to the external assembler (assuming `arm-none-eabi-as`):
33-
// * activate t32/a32 interworking
34-
// * use arch ARMv5TE
35-
// * use little-endian
3620
asm_args: cvs!["-mthumb-interwork", "-march=armv5te", "-mlittle-endian",],
37-
// minimum extra features, these cannot be disabled via -C
38-
// Also force-enable 32-bit atomics, which allows the use of atomic load/store only.
39-
// The resulting atomics are ABI incompatible with atomics backed by libatomic.
40-
features: "+soft-float,+strict-align,+atomics-32".into(),
41-
frame_pointer: FramePointer::MayOmit,
42-
main_needs_argc_argv: false,
43-
// don't have atomic compare-and-swap
21+
features: "+soft-float,+strict-align".into(),
4422
atomic_cas: false,
4523
has_thumb_interworking: true,
46-
47-
..base::thumb::opts()
24+
..base::arm_none::opts()
4825
},
4926
}
5027
}

compiler/rustc_target/src/spec/targets/thumbv6m_none_eabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub(crate) fn target() -> Target {
2626
// There are no atomic CAS instructions available in the instruction set of the ARMv6-M
2727
// architecture
2828
atomic_cas: false,
29-
..base::thumb::opts()
29+
..base::arm_none::opts()
3030
},
3131
}
3232
}

compiler/rustc_target/src/spec/targets/thumbv6m_nuttx_eabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub(crate) fn target() -> Target {
2525
// The ARMv6-M doesn't support hardware atomic operations, use atomic builtins instead.
2626
features: "+strict-align".into(),
2727
max_atomic_width: Some(32),
28-
..base::thumb::opts()
28+
..base::arm_none::opts()
2929
},
3030
}
3131
}

compiler/rustc_target/src/spec/targets/thumbv7a_nuttx_eabi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub(crate) fn target() -> Target {
2727
// Cortex-A7/A8/A9 with software floating point
2828
features: "+soft-float,-neon".into(),
2929
max_atomic_width: Some(64),
30-
..base::thumb::opts()
30+
..base::arm_none::opts()
3131
},
3232
}
3333
}

compiler/rustc_target/src/spec/targets/thumbv7a_nuttx_eabihf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub(crate) fn target() -> Target {
3131
// and NEON SIMD instructions
3232
features: "+vfp3,+neon".into(),
3333
max_atomic_width: Some(64),
34-
..base::thumb::opts()
34+
..base::arm_none::opts()
3535
},
3636
}
3737
}

0 commit comments

Comments
 (0)