]> git.proxmox.com Git - rustc.git/blob - src/librustc_back/target/thumb_base.rs
New upstream version 1.14.0+dfsg1
[rustc.git] / src / librustc_back / target / thumb_base.rs
1 // Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // These 4 `thumbv*` targets cover the ARM Cortex-M family of processors which are widely used in
12 // microcontrollers. Namely, all these processors:
13 //
14 // - Cortex-M0
15 // - Cortex-M0+
16 // - Cortex-M1
17 // - Cortex-M3
18 // - Cortex-M4(F)
19 // - Cortex-M7(F)
20 //
21 // We have opted for 4 targets instead of one target per processor (e.g. `cortex-m0`, `cortex-m3`,
22 // etc) because the differences between some processors like the cortex-m0 and cortex-m1 are almost
23 // non-existent from the POV of codegen so it doesn't make sense to have separate targets for them.
24 // And if differences exist between two processors under the same target, rustc flags can be used to
25 // optimize for one processor or the other.
26 //
27 // Also, we have not chosen a single target (`arm-none-eabi`) like GCC does because this makes
28 // difficult to integrate Rust code and C code. Targeting the Cortex-M4 requires different gcc flags
29 // than the ones you would use for the Cortex-M0 and with a single target it'd be impossible to
30 // differentiate one processor from the other.
31 //
32 // About arm vs thumb in the name. The Cortex-M devices only support the Thumb instruction set,
33 // which is more compact (higher code density), and not the ARM instruction set. That's why LLVM
34 // triples use thumb instead of arm. We follow suit because having thumb in the name let us
35 // differentiate these targets from our other `arm(v7)-*-*-gnueabi(hf)` targets in the context of
36 // build scripts / gcc flags.
37
38 use PanicStrategy;
39 use std::default::Default;
40 use target::TargetOptions;
41
42 pub fn opts() -> TargetOptions {
43 // See rust-lang/rfcs#1645 for a discussion about these defaults
44 TargetOptions {
45 executables: true,
46 // In 99%+ of cases, we want to use the `arm-none-eabi-gcc` compiler (there aren't many
47 // options around)
48 linker: "arm-none-eabi-gcc".to_string(),
49 // Because these devices have very little resources having an unwinder is too onerous so we
50 // default to "abort" because the "unwind" strategy is very rare.
51 panic_strategy: PanicStrategy::Abort,
52 // Similarly, one almost always never wants to use relocatable code because of the extra
53 // costs it involves.
54 relocation_model: "static".to_string(),
55 abi_blacklist: super::arm_base::abi_blacklist(),
56 .. Default::default()
57 }
58 }