Skip to content

Commit

Permalink
Rollup merge of #100244 - Lokathor:add-armv4t-none-eabi-take2, r=jack…
Browse files Browse the repository at this point in the history
…h726

Add armv4t-none-eabi take2

This is the same as the previous PR (#99226) but i just made a fresh branch without a merge commit in it.

---

### armv4t-none-eabi target quiz

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target.

That's me!

> Targets must use naming consistent with any existing targets

We're using the existing name as recognized by LLVM and GCC

> Tier 3 targets may have unusual requirements to build or use, but must not create legal issues or impose onerous legal terms for the Rust project or for Rust developers or users.

No legal issues here.

>> The target must not introduce license incompatibilities.

No license requirements here.

>> Anything added to the Rust repository must be under the standard Rust license (MIT OR Apache-2.0).

check

>> The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy.

no new deps, we're just adding a rustc target description file for a target llvm already knows about.

>> Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries.

bare-metal target, doesn't rely on any libs at all.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate

`core` only here. You could build `alloc` too, but you'd have to bring your own global allocator.

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible.

LLVM knows how to do it, you just need the GNU Binutils linker because LLVM's linker doesn't work that far back. That's in the docs as part of this PR.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target.

No burdens, LLVM already knows how to do this. Further, because this is a cpu-feature variant of an existing tier3 target the `compiler-builtins` crate has already been updated as necessary to fix any missing builtin function gaps.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.

check.
  • Loading branch information
matthiaskrgr authored Aug 7, 2022
2 parents 5648add + b4a8299 commit 0f7fe9f
Show file tree
Hide file tree
Showing 3 changed files with 125 additions and 0 deletions.
54 changes: 54 additions & 0 deletions compiler/rustc_target/src/spec/armv4t_none_eabi.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! Targets the ARMv4T, with code as `a32` code by default.
//!
//! Primarily of use for the GBA, but usable with other devices too.
//!
//! Please ping @Lokathor if changes are needed.
//!
//! 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.
//!
//! **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.
use crate::spec::{cvs, LinkerFlavor, PanicStrategy, RelocModel, Target, TargetOptions};

pub fn target() -> Target {
Target {
llvm_target: "armv4t-none-eabi".into(),
pointer_width: 32,
arch: "arm".into(),
/* Data layout args are '-' separated:
* little endian
* stack is 64-bit aligned (EABI)
* pointers are 32-bit
* i64 must be 64-bit aligned (EABI)
* mangle names with ELF style
* native integers are 32-bit
* All other elements are default
*/
data_layout: "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64".into(),
options: TargetOptions {
abi: "eabi".into(),
linker_flavor: LinkerFlavor::Ld,
linker: Some("arm-none-eabi-ld".into()),
asm_args: cvs!["-mthumb-interwork", "-march=armv4t", "-mlittle-endian",],
features: "+soft-float,+strict-align".into(),
main_needs_argc_argv: false,
atomic_cas: false,
has_thumb_interworking: true,
relocation_model: RelocModel::Static,
panic_strategy: PanicStrategy::Abort,
// from thumb_base, rust-lang/rust#44993.
emit_debug_gdb_scripts: false,
// from thumb_base, apparently gcc/clang give enums a minimum of 8 bits on no-os targets
c_enum_min_bits: 8,
..Default::default()
},
}
}
1 change: 1 addition & 0 deletions src/doc/rustc/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- [aarch64-apple-ios-sim](platform-support/aarch64-apple-ios-sim.md)
- [\*-apple-watchos\*](platform-support/apple-watchos.md)
- [aarch64-nintendo-switch-freestanding](platform-support/aarch64-nintendo-switch-freestanding.md)
- [armv4t-none-eabi](platform-support/armv4t-none-eabi.md)
- [armv6k-nintendo-3ds](platform-support/armv6k-nintendo-3ds.md)
- [armv7-unknown-linux-uclibceabi](platform-support/armv7-unknown-linux-uclibceabi.md)
- [armv7-unknown-linux-uclibceabihf](platform-support/armv7-unknown-linux-uclibceabihf.md)
Expand Down
70 changes: 70 additions & 0 deletions src/doc/rustc/src/platform-support/armv4t_none_eabi.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# armv4t-none-eabi

Tier 3

Bare-metal target for any cpu in the ARMv4T architecture family, supporting
ARM/Thumb code interworking (aka `a32`/`t32`), with ARM code as the default code
generation.

In particular this supports the Gameboy Advance (GBA), but there's nothing GBA
specific with this target, so any ARMv4T device should work fine.

## Target Maintainers

* [@Lokathor](https://github.com/lokathor)

## Requirements

The target is cross-compiled, and uses static linking.

The linker that comes with rustc cannot link for this platform (the platform is
too old). You will need the `arm-none-eabi-ld` linker from a GNU Binutils
targeting ARM. This can be obtained for Windows/Mac/Linux from the [ARM
Developer Website][arm-dev], or possibly from your OS's package manager.

[arm-dev]: https://developer.arm.com/Tools%20and%20Software/GNU%20Toolchain

This target doesn't provide a linker script, you'll need to bring your own
according to the specific device you want to target. Pass
`-Clink-arg=-Tyour_script.ld` as a rustc argument to make the linker use
`your_script.ld` during linking.

## Building Rust Programs

Because it is Tier 3, rust does not yet ship pre-compiled artifacts for this target.

Just use the `build-std` nightly cargo feature to build the `core` library. You
can pass this as a command line argument to cargo, or your `.cargo/config.toml`
file might include the following lines:

```toml
[unstable]
build-std = ["core"]
```

Most of `core` should work as expected, with the following notes:
* the target is "soft float", so `f32` and `f64` operations are emulated in
software.
* integer division is also emulated in software.
* the target is old enough that it doesn't have atomic instructions.

Rust programs are output as ELF files.

For running on hardware, you'll generally need to extract the "raw" program code
out of the ELF and into a file of its own. The `objcopy` program provided as
part of the GNU Binutils can do this:

```shell
arm-none-eabi-objcopy --output-target binary [in_file] [out_file]
```

## Testing

This is a cross-compiled target that you will need to emulate during testing.

Because this is a device-agnostic target, and the exact emulator that you'll
need depends on the specific device you want to run your code on.

For example, when programming for the Gameboy Advance, the
[mgba-test-runner](https://github.com/agbrs/agb) program could be used to make a
normal set of rust tests be run within the `mgba` emulator.

0 comments on commit 0f7fe9f

Please sign in to comment.