|
| 1 | +use crate::spec::{LinkerFlavor, Target, TargetOptions, TargetResult}; |
| 2 | + |
| 3 | +/// A base target for AVR devices using the GNU toolchain. |
| 4 | +/// |
| 5 | +/// Requires GNU avr-gcc and avr-binutils on the host system. |
| 6 | +pub fn target(target_cpu: String) -> TargetResult { |
| 7 | + Ok(Target { |
| 8 | + arch: "avr".to_string(), |
| 9 | + data_layout: "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8".to_string(), |
| 10 | + llvm_target: "avr-unknown-unknown".to_string(), |
| 11 | + target_endian: "little".to_string(), |
| 12 | + target_pointer_width: "16".to_string(), |
| 13 | + linker_flavor: LinkerFlavor::Gcc, |
| 14 | + target_os: "unknown".to_string(), |
| 15 | + target_env: "".to_string(), |
| 16 | + target_vendor: "unknown".to_string(), |
| 17 | + target_c_int_width: 16.to_string(), |
| 18 | + options: TargetOptions { |
| 19 | + cpu: target_cpu.clone(), |
| 20 | + exe_suffix: ".elf".to_string(), |
| 21 | + |
| 22 | + linker: Some("avr-gcc".to_owned()), |
| 23 | + dynamic_linking: false, |
| 24 | + executables: true, |
| 25 | + linker_is_gnu: true, |
| 26 | + has_rpath: false, |
| 27 | + position_independent_executables: false, |
| 28 | + eh_frame_header: false, |
| 29 | + pre_link_args: vec![( |
| 30 | + LinkerFlavor::Gcc, |
| 31 | + vec![ |
| 32 | + format!("-mmcu={}", target_cpu), |
| 33 | + // We want to be able to strip as much executable code as possible |
| 34 | + // from the linker command line, and this flag indicates to the |
| 35 | + // linker that it can avoid linking in dynamic libraries that don't |
| 36 | + // actually satisfy any symbols up to that point (as with many other |
| 37 | + // resolutions the linker does). This option only applies to all |
| 38 | + // following libraries so we're sure to pass it as one of the first |
| 39 | + // arguments. |
| 40 | + "-Wl,--as-needed".to_string(), |
| 41 | + ], |
| 42 | + )] |
| 43 | + .into_iter() |
| 44 | + .collect(), |
| 45 | + late_link_args: vec![(LinkerFlavor::Gcc, vec!["-lgcc".to_owned()])] |
| 46 | + .into_iter() |
| 47 | + .collect(), |
| 48 | + ..TargetOptions::default() |
| 49 | + }, |
| 50 | + }) |
| 51 | +} |
0 commit comments