Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 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 | // non-existent 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. |
| 29 | |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 30 | use crate::spec::TargetOptions; |
| 31 | use crate::spec::{FramePointer, LinkerFlavor, LldFlavor, PanicStrategy, RelocModel}; |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 32 | |
| 33 | pub fn opts() -> TargetOptions { |
| 34 | // See rust-lang/rfcs#1645 for a discussion about these defaults |
| 35 | TargetOptions { |
ThiƩbaud Weksteen | 5bd94c1 | 2021-01-06 15:18:42 +0100 | [diff] [blame] | 36 | linker_flavor: LinkerFlavor::Lld(LldFlavor::Ld), |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 37 | // In most cases, LLD is good enough |
Charisee | 341341c | 2022-05-20 05:14:50 +0000 | [diff] [blame] | 38 | linker: Some("rust-lld".into()), |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 39 | // Because these devices have very little resources having an unwinder is too onerous so we |
| 40 | // default to "abort" because the "unwind" strategy is very rare. |
| 41 | panic_strategy: PanicStrategy::Abort, |
| 42 | // Similarly, one almost always never wants to use relocatable code because of the extra |
| 43 | // costs it involves. |
Jeff Vander Stoep | 247d86b | 2020-08-11 14:27:44 +0200 | [diff] [blame] | 44 | relocation_model: RelocModel::Static, |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 45 | // When this section is added a volatile load to its start address is also generated. This |
| 46 | // volatile load is a footgun as it can end up loading an invalid memory address, depending |
| 47 | // on how the user set up their linker scripts. This section adds pretty printer for stuff |
| 48 | // like std::Vec, which is not that used in no-std context, so it's best to left it out |
| 49 | // until we figure a way to add the pretty printers without requiring a volatile load cf. |
| 50 | // rust-lang/rust#44993. |
| 51 | emit_debug_gdb_scripts: false, |
Matthew Maurer | 15a6560 | 2020-04-24 14:05:21 -0700 | [diff] [blame] | 52 | // LLVM is eager to trash the link register when calling `noreturn` functions, which |
| 53 | // breaks debugging. Preserve LR by default to prevent that from happening. |
Chris Wailes | 54272ac | 2021-09-09 16:08:13 -0700 | [diff] [blame] | 54 | frame_pointer: FramePointer::Always, |
Chris Wailes | bcf972c | 2021-10-21 11:03:28 -0700 | [diff] [blame] | 55 | // ARM supports multiple ABIs for enums, the linux one matches the default of 32 here |
| 56 | // but any arm-none or thumb-none target will be defaulted to 8 on GCC and clang |
| 57 | c_enum_min_bits: 8, |
Matthew Maurer | 859223d | 2020-03-27 12:47:38 -0700 | [diff] [blame] | 58 | ..Default::default() |
Inna Palant | ff3f07a | 2019-07-11 16:15:26 -0700 | [diff] [blame] | 59 | } |
| 60 | } |