Skip to content

Commit 9016458

Browse files
authored
Rollup merge of #74419 - Lokathor:gba-target, r=jonas-schievink
Add a thumbv4t-none-eabi target (cc @ketsuban, one of the few other Rust users who programs for GBA.) --- **EDIT:** This is now a more general `thumbv4t-none-eabi` PR! See [this comment](#74419 (comment)) --- Now that the PSP officially has an official target within Rust, well as the lead of the `gba` crate I can't _not_ add a GBA target as well. I know that the [target tier policy](rust-lang/rfcs#2803) isn't ratified and official, but I'll use it as an outline (cc @joshtriplett): * Designated Developer: Lokathor * Naming consistent with any existing targets * Doesn't create Rust project legal issues. * No license issues * Uses the standard Apache/mit license. * Rust tooling users don't have to accept any new licensing requirements * Does not support hosting rust tooling. * Doesn't require linking in proprietary code to obtain a functional binary. However, you will need to do some post-build steps to turn the ELF file into a usable GBA ROM (either for an emulator or for the actual hardware). * This is a `no_std` environment, without even a standard global allocator, so this adds no new code to `alloc` or `std`. * The process of building for this target is documented in the `gba` crate ([link](https://rust-console.github.io/gba/development-setup.html)). Well, the docs there are currently a little out of date, they're back on using `cargo-xbuild`, but the crate docs there will get updated once this target is available. * This places no new burden on any other targets * Does not break any existing targets. I'm not fully confident in specifying the same linker script for all possible projects, so I'm currently just not giving a linker script at all, and users can continue to select their own linker script by using `-C` to provide a linker arg. I added the file, and added it to the `supported_targets!` macro usage, and I think that's all there is to do.
2 parents cc4e880 + ec9c8d8 commit 9016458

File tree

2 files changed

+63
-0
lines changed

2 files changed

+63
-0
lines changed

src/librustc_target/spec/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,7 @@ supported_targets! {
676676
("powerpc64-wrs-vxworks", powerpc64_wrs_vxworks),
677677

678678
("mipsel-sony-psp", mipsel_sony_psp),
679+
("thumbv4t-none-eabi", thumbv4t_none_eabi),
679680
}
680681

681682
/// Everything `rustc` knows about how to compile for a specific target.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
//! Targets the ARMv4T, with code as `t32` code by default.
2+
//!
3+
//! Primarily of use for the GBA, but usable with other devices too.
4+
//!
5+
//! Please ping @Lokathor if changes are needed.
6+
//!
7+
//! This target profile assumes that you have the ARM binutils in your path (specifically the linker, `arm-none-eabi-ld`). They can be obtained for free for all major OSes from the ARM developer's website, and they may also be available in your system's package manager. Unfortunately, the standard linker that Rust uses (`lld`) only supports as far back as `ARMv5TE`, so we must use the GNU `ld` linker.
8+
//!
9+
//! **Important:** This target profile **does not** specify a linker script. You just get the default link script when you build a binary for this target. The default link script is very likely wrong, so you should use `-Clink-arg=-Tmy_script.ld` to override that with a correct linker script.
10+
11+
use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult};
12+
13+
pub fn target() -> TargetResult {
14+
Ok(Target {
15+
llvm_target: "thumbv4t-none-eabi".to_string(),
16+
target_endian: "little".to_string(),
17+
target_pointer_width: "32".to_string(),
18+
target_c_int_width: "32".to_string(),
19+
target_os: "none".to_string(),
20+
target_env: "".to_string(),
21+
target_vendor: "".to_string(),
22+
arch: "arm".to_string(),
23+
/* Data layout args are '-' separated:
24+
* little endian
25+
* stack is 64-bit aligned (EABI)
26+
* pointers are 32-bit
27+
* i64 must be 64-bit aligned (EABI)
28+
* mangle names with ELF style
29+
* native integers are 32-bit
30+
* All other elements are default
31+
*/
32+
data_layout: "e-S64-p:32:32-i64:64-m:e-n32".to_string(),
33+
linker_flavor: LinkerFlavor::Ld,
34+
options: TargetOptions {
35+
linker: Some("arm-none-eabi-ld".to_string()),
36+
linker_is_gnu: true,
37+
38+
// extra args passed to the external assembler (assuming `arm-none-eabi-as`):
39+
// * activate t32/a32 interworking
40+
// * use arch ARMv4T
41+
// * use little-endian
42+
asm_args: vec![
43+
"-mthumb-interwork".to_string(),
44+
"-march=armv4t".to_string(),
45+
"-mlittle-endian".to_string(),
46+
],
47+
48+
// minimum extra features, these cannot be disabled via -C
49+
features: "+soft-float,+strict-align".to_string(),
50+
51+
main_needs_argc_argv: false,
52+
53+
// No thread-local storage (just use a static Cell)
54+
has_elf_tls: false,
55+
56+
// don't have atomic compare-and-swap
57+
atomic_cas: false,
58+
59+
..super::thumb_base::opts()
60+
},
61+
})
62+
}

0 commit comments

Comments
 (0)