1
Fork 0

Rollup merge of #131651 - Patryk27:avr-unknown-unknown, r=tgross35

Create a generic AVR target: avr-none

This commit removes the `avr-unknown-gnu-atmega328` target and replaces it with a more generic `avr-none` variant that must be specialized using `-C target-cpu` (e.g. `-C target-cpu=atmega328p`).

Seizing the day, I'm adding myself as the maintainer of this target - I've been already fixing the bugs anyway, might as well make it official 🙂

Related discussions:
- https://github.com/rust-lang/rust/pull/131171
- https://github.com/rust-lang/compiler-team/issues/800

try-job: x86_64-gnu-debug
This commit is contained in:
Jubilee 2025-02-20 14:58:15 -08:00 committed by GitHub
commit 9de94b4f8f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 160 additions and 60 deletions

View file

@ -1,45 +1,5 @@
use object::elf;
use crate::spec::{Cc, LinkerFlavor, Lld, RelocModel, Target, TargetOptions};
/// A base target for AVR devices using the GNU toolchain.
///
/// Requires GNU avr-gcc and avr-binutils on the host system.
/// FIXME: Remove the second parameter when const string concatenation is possible.
pub(crate) fn target(target_cpu: &'static str, mmcu: &'static str) -> Target {
Target {
arch: "avr".into(),
metadata: crate::spec::TargetMetadata {
description: None,
tier: None,
host_tools: None,
std: None,
},
data_layout: "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8".into(),
llvm_target: "avr-unknown-unknown".into(),
pointer_width: 16,
options: TargetOptions {
env: "gnu".into(),
c_int_width: "16".into(),
cpu: target_cpu.into(),
exe_suffix: ".elf".into(),
linker: Some("avr-gcc".into()),
eh_frame_header: false,
pre_link_args: TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[mmcu]),
late_link_args: TargetOptions::link_args(
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
&["-lgcc"],
),
max_atomic_width: Some(16),
atomic_cas: false,
relocation_model: RelocModel::Static,
..TargetOptions::default()
},
}
}
/// Resolve the value of the EF_AVR_ARCH field for AVR ELF files, given the
/// name of the target CPU / MCU.
///

View file

@ -1,7 +1,7 @@
pub(crate) mod aix;
pub(crate) mod android;
pub(crate) mod apple;
pub(crate) mod avr_gnu;
pub(crate) mod avr;
pub(crate) mod bpf;
pub(crate) mod cygwin;
pub(crate) mod dragonfly;

View file

@ -60,7 +60,7 @@ pub mod crt_objects;
mod base;
mod json;
pub use base::avr_gnu::ef_avr_arch;
pub use base::avr::ef_avr_arch;
/// Linker is called through a C/C++ compiler.
#[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)]
@ -1797,7 +1797,7 @@ supported_targets! {
("riscv64gc-unknown-fuchsia", riscv64gc_unknown_fuchsia),
("x86_64-unknown-fuchsia", x86_64_unknown_fuchsia),
("avr-unknown-gnu-atmega328", avr_unknown_gnu_atmega328),
("avr-none", avr_none),
("x86_64-unknown-l4re-uclibc", x86_64_unknown_l4re_uclibc),
@ -3062,7 +3062,10 @@ impl Target {
&self.post_link_args,
] {
for (&flavor, flavor_args) in args {
check!(!flavor_args.is_empty(), "linker flavor args must not be empty");
check!(
!flavor_args.is_empty() || self.arch == "avr",
"linker flavor args must not be empty"
);
// Check that flavors mentioned in link args are compatible with the default flavor.
match self.linker_flavor {
LinkerFlavor::Gnu(..) => {

View file

@ -0,0 +1,32 @@
use crate::spec::{Cc, LinkerFlavor, Lld, RelocModel, Target, TargetOptions};
pub(crate) fn target() -> Target {
Target {
arch: "avr".into(),
metadata: crate::spec::TargetMetadata {
description: None,
tier: None,
host_tools: None,
std: None,
},
data_layout: "e-P1-p:16:8-i8:8-i16:8-i32:8-i64:8-f32:8-f64:8-n8-a:8".into(),
llvm_target: "avr-unknown-unknown".into(),
pointer_width: 16,
options: TargetOptions {
c_int_width: "16".into(),
exe_suffix: ".elf".into(),
linker: Some("avr-gcc".into()),
eh_frame_header: false,
pre_link_args: TargetOptions::link_args(LinkerFlavor::Gnu(Cc::Yes, Lld::No), &[]),
late_link_args: TargetOptions::link_args(
LinkerFlavor::Gnu(Cc::Yes, Lld::No),
&["-lgcc"],
),
max_atomic_width: Some(16),
atomic_cas: false,
relocation_model: RelocModel::Static,
need_explicit_cpu: true,
..TargetOptions::default()
},
}
}

View file

@ -1,5 +0,0 @@
use crate::spec::{Target, base};
pub(crate) fn target() -> Target {
base::avr_gnu::target("atmega328", "-mmcu=atmega328")
}