Skip to content

Commit 1dd59ff

Browse files
authored
Rollup merge of rust-lang#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 2f688ac + 8abbd0b commit 1dd59ff

File tree

5 files changed

+93
-0
lines changed

5 files changed

+93
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ 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
163164

164165
# riscv targets currently do not need a C compiler, as compiler_builtins
165166
# doesn't currently have it enabled, and the riscv gcc compiler is not
@@ -173,6 +174,10 @@ ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \
173174
CC_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-gcc \
174175
AR_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-ar \
175176
CXX_thumbv7neon_unknown_linux_gnueabihf=arm-linux-gnueabihf-g++ \
177+
CC_armv7a_none_eabi=arm-none-eabi-gcc \
178+
CC_armv7a_none_eabihf=arm-none-eabi-gcc \
179+
CFLAGS_armv7a_none_eabi=-march=armv7-a \
180+
CFLAGS_armv7a_none_eabihf=-march=armv7-a+vfpv3 \
176181
CC_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-gcc \
177182
AR_riscv64gc_unknown_linux_gnu=riscv64-unknown-linux-gnu-ar \
178183
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

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ static TARGETS: &[&str] = &[
6969
"thumbv7neon-linux-androideabi",
7070
"armv7-unknown-linux-gnueabi",
7171
"armv7-unknown-linux-gnueabihf",
72+
"armv7a-none-eabi",
7273
"thumbv7neon-unknown-linux-gnueabihf",
7374
"armv7-unknown-linux-musleabi",
7475
"armv7-unknown-linux-musleabihf",

0 commit comments

Comments
 (0)