Skip to content

Commit 6eb8ee8

Browse files
committed
Auto merge of #68253 - japaric:bare-metal-cortex-a, r=alexcrichton
add bare metal ARM Cortex-A targets to rustc -> `rustc --target armv7a-none-eabi` will work also build rust-std (rustup) components for them -> `rustup target add armv7a-none-eabi` will work this completes our bare-metal support of ARMv7 cores on stable Rust (by 1.42 or 1.43) (these target specifications have been tested on a real (no emulation / QEMU) [Cortex-A7 core](https://github.com/iqlusioninc/usbarmory.rs/))
2 parents 900811e + a3a0776 commit 6eb8ee8

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

src/ci/docker/dist-various-1/Dockerfile

+4
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ ENV TARGETS=$TARGETS,armebv7r-none-eabihf
160160
ENV TARGETS=$TARGETS,armv7r-none-eabi
161161
ENV TARGETS=$TARGETS,armv7r-none-eabihf
162162
ENV TARGETS=$TARGETS,thumbv7neon-unknown-linux-gnueabihf
163+
ENV TARGETS=$TARGETS,armv7a-none-eabi
164+
ENV TARGETS=$TARGETS,armv7a-none-eabihf
163165

164166
# riscv targets currently do not need a C compiler, as compiler_builtins
165167
# doesn't currently have it enabled, and the riscv gcc compiler is not
@@ -173,6 +175,8 @@ ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \
173175
CC_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \
174176
AR_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-ar \
175177
CXX_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \
178+
CC_armv7a_none_eabi=arm-none-eabi-gcc \
179+
CC_armv7a_none_eabihf=arm-none-eabi-gcc \
176180
CC_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-gcc \
177181
AR_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-ar \
178182
CXX_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-g++ \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Generic ARMv7-A target for bare-metal code - floating point disabled
2+
//
3+
// This is basically the `armv7-unknown-linux-gnueabi` target with some changes
4+
// (listed below) to bring it closer to the bare-metal `thumb` & `aarch64`
5+
// targets:
6+
//
7+
// - `TargetOptions.features`: added `+strict-align`. rationale: unaligned
8+
// memory access is disabled on boot on these cores
9+
// - linker changed to LLD. rationale: C is not strictly needed to build
10+
// bare-metal binaries (the `gcc` linker has the advantage that it knows where C
11+
// libraries and crt*.o are but it's not much of an advantage here); LLD is also
12+
// faster
13+
// - `target_os` set to `none`. rationale: matches `thumb` targets
14+
// - `target_{env,vendor}` set to an empty string. rationale: matches `thumb`
15+
// targets
16+
// - `panic_strategy` set to `abort`. rationale: matches `thumb` targets
17+
// - `relocation-model` set to `static`; also no PIE, no relro and no dynamic
18+
// linking. rationale: matches `thumb` targets
19+
20+
use super::{LinkerFlavor, LldFlavor, PanicStrategy, Target, TargetOptions};
21+
22+
pub fn target() -> Result<Target, String> {
23+
let opts = TargetOptions {
24+
linker: Some("rust-lld".to_owned()),
25+
features: "+v7,+thumb2,+soft-float,-neon,+strict-align".to_string(),
26+
executables: true,
27+
relocation_model: "static".to_string(),
28+
disable_redzone: true,
29+
max_atomic_width: Some(64),
30+
panic_strategy: PanicStrategy::Abort,
31+
abi_blacklist: super::arm_base::abi_blacklist(),
32+
emit_debug_gdb_scripts: false,
33+
..Default::default()
34+
};
35+
Ok(Target {
36+
llvm_target: "armv7a-none-eabi".to_string(),
37+
target_endian: "little".to_string(),
38+
target_pointer_width: "32".to_string(),
39+
target_c_int_width: "32".to_string(),
40+
target_os: "none".to_string(),
41+
target_env: String::new(),
42+
target_vendor: String::new(),
43+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
44+
arch: "arm".to_string(),
45+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
46+
options: opts,
47+
})
48+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Generic ARMv7-A target for bare-metal code - floating point enabled (assumes
2+
// FPU is present and emits FPU instructions)
3+
//
4+
// This is basically the `armv7-unknown-linux-gnueabihf` target with some
5+
// changes (list in `armv7a_none_eabi.rs`) to bring it closer to the bare-metal
6+
// `thumb` & `aarch64` targets.
7+
8+
use super::{LinkerFlavor, LldFlavor, PanicStrategy, Target, TargetOptions};
9+
10+
pub fn target() -> Result<Target, String> {
11+
let opts = TargetOptions {
12+
linker: Some("rust-lld".to_owned()),
13+
features: "+v7,+vfp3,-d32,+thumb2,-neon,+strict-align".to_string(),
14+
executables: true,
15+
relocation_model: "static".to_string(),
16+
disable_redzone: true,
17+
max_atomic_width: Some(64),
18+
panic_strategy: PanicStrategy::Abort,
19+
abi_blacklist: super::arm_base::abi_blacklist(),
20+
emit_debug_gdb_scripts: false,
21+
..Default::default()
22+
};
23+
Ok(Target {
24+
llvm_target: "armv7a-none-eabihf".to_string(),
25+
target_endian: "little".to_string(),
26+
target_pointer_width: "32".to_string(),
27+
target_c_int_width: "32".to_string(),
28+
target_os: "none".to_string(),
29+
target_env: String::new(),
30+
target_vendor: String::new(),
31+
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".to_string(),
32+
arch: "arm".to_string(),
33+
linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld),
34+
options: opts,
35+
})
36+
}

src/librustc_target/spec/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,9 @@ supported_targets! {
472472
("thumbv8m.main-none-eabi", thumbv8m_main_none_eabi),
473473
("thumbv8m.main-none-eabihf", thumbv8m_main_none_eabihf),
474474

475+
("armv7a-none-eabi", armv7a_none_eabi),
476+
("armv7a-none-eabihf", armv7a_none_eabihf),
477+
475478
("msp430-none-elf", msp430_none_elf),
476479

477480
("aarch64-unknown-cloudabi", aarch64_unknown_cloudabi),

src/tools/build-manifest/src/main.rs

+2
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ static TARGETS: &[&str] = &[
6969
"thumbv7neon-linux-androideabi",
7070
"armv7-unknown-linux-gnueabi",
7171
"armv7-unknown-linux-gnueabihf",
72+
"armv7a-none-eabi",
73+
"armv7a-none-eabihf",
7274
"thumbv7neon-unknown-linux-gnueabihf",
7375
"armv7-unknown-linux-musleabi",
7476
"armv7-unknown-linux-musleabihf",

0 commit comments

Comments
 (0)