Skip to content

[AVR] Replace broken 'avr-unknown-unknown' target with 'avr-unknown-gnu-atmega328' target #74941

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged

Conversation

dylanmckay
Copy link
Contributor

The avr-unknown-unknown target has never worked correctly, always trying to invoke
the host linker and failing. It aimed to be a mirror of AVR-GCC's
default handling of the `avr-unknown-unknown' triple (assume bare
minimum chip features, silently skip linking runtime libraries, etc).
This behaviour is broken-by-default as it will cause a miscompiled executable
when flashed.

This patch improves the AVR builtin target specifications to instead
expose only a 'avr-unknown-gnu-atmega328' target. This target system is
gnu, as it uses the AVR-GCC frontend along with avr-binutils. The
target triple ABI is 'atmega328'.

In the future, it should be possible to replace the dependency on
AVR-GCC and binutils by using the in-progress AVR LLD and compiler-rt support.
Perhaps at that point it would make sense to add an
'avr-unknown-unknown-atmega328' target as a better default when
implemented.

There is no current intention to add in-tree AVR target specifications for other
AVR microcontrollers - this one can serve as a reference implementation
for other devices via rustc --print target-spec-json avr-unknown-gnu-atmega328p.

There should be no users of the existing 'avr-unknown-unknown' Rust
target as a custom target specification JSON has always been
recommended, and the avr-unknown-unknown target could never pass the
linking step anyway.

@rust-highfive
Copy link
Contributor

r? @oli-obk

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 30, 2020
@dylanmckay dylanmckay force-pushed the replace-broken-avr-unknown-unknown-target branch from ed8e34f to 2ec4b70 Compare July 30, 2020 11:30
@oli-obk
Copy link
Contributor

oli-obk commented Jul 30, 2020

cc @shepmaster @japaric

cc @rust-lang/compiler this PR replaces a Tier 3 target that apparently never worked anyway with a controller specific tier 3 target that mostly serves as a reference target for others to copy and reuse

@bors
Copy link
Collaborator

bors commented Aug 3, 2020

☔ The latest upstream changes (presumably #75070) made this pull request unmergeable. Please resolve the merge conflicts.

@Rahix Rahix mentioned this pull request Aug 3, 2020
4 tasks
@nikomatsakis
Copy link
Contributor

Sounds good to me, I say land it.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 6, 2020

@dylanmckay can you rebase and fix the conflicts? Then we can move to merging this

@LeSeulArtichaut LeSeulArtichaut added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 22, 2020
@LeSeulArtichaut
Copy link
Contributor

Ping from triage: @dylanmckay it looks like this PR can be merged when the conflicts are resolved. Could you rebase your branch? Thanks!

…nu-atmega328' target

The `avr-unknown-unknown` target has never worked correctly, always trying to invoke
the host linker and failing. It aimed to be a mirror of AVR-GCC's
default handling of the `avr-unknown-unknown' triple (assume bare
minimum chip features, silently skip linking runtime libraries, etc).
This behaviour is broken-by-default as it will cause a miscompiled executable
when flashed.

This patch improves the AVR builtin target specifications to instead
expose only a 'avr-unknown-gnu-atmega328' target. This target system is
`gnu`, as it uses the AVR-GCC frontend along with avr-binutils. The
target triple ABI is 'atmega328'.

In the future, it should be possible to replace the dependency on
AVR-GCC and binutils by using the in-progress AVR LLD and compiler-rt support.
Perhaps at that point it would make sense to add an
'avr-unknown-unknown-atmega328' target as a better default when
implemented.

There is no current intention to add in-tree AVR target specifications for other
AVR microcontrollers - this one can serve as a reference implementation
for other devices via `rustc --print target-spec-json
avr-unknown-gnu-atmega328p`.

There should be no users of the existing 'avr-unknown-unknown' Rust
target as a custom target specification JSON has always been
recommended, and the avr-unknown-unknown target could never pass the
linking step anyway.
In general, linking with libc is not required, only libgcc is needed.
As suggested in the code review, a better option for libc support is by
building it into rust-lang/libc directly.

This also removes the '-Os' argument to the linker, which is a NOP.
…spec

The 'freestanding' module was only ever used for AVR. It was an
unnecessary layer of abstraction. This commit merges the
'freestanding_base' module into 'avr_gnu_base'.
@dylanmckay dylanmckay force-pushed the replace-broken-avr-unknown-unknown-target branch from 60bd312 to a0905ce Compare August 24, 2020 06:50
@dylanmckay
Copy link
Contributor Author

The branch has now been rebased.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 26, 2020

@bors r+

@bors
Copy link
Collaborator

bors commented Aug 26, 2020

📌 Commit c9ead8c has been approved by oli-obk

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 26, 2020
@bors
Copy link
Collaborator

bors commented Aug 26, 2020

⌛ Testing commit c9ead8c with merge ca9f78dd98835a40aede3b7593cabf425c5bee21...

@bors
Copy link
Collaborator

bors commented Aug 26, 2020

💔 Test failed - checks-actions

@bors bors removed the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Aug 26, 2020
@bors bors added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 26, 2020
@dylanmckay
Copy link
Contributor Author

Strange, seemingly unrelated "command not found" error from bors https://github.com/rust-lang-ci/rust/runs/1032158434#step:23:22604 ([run-make] run-make-fulldeps\pgo-indirect-call-promotion)

@mati865
Copy link
Contributor

mati865 commented Aug 26, 2020

It's spurious failure.

@oli-obk
Copy link
Contributor

oli-obk commented Aug 27, 2020

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 27, 2020
@bors
Copy link
Collaborator

bors commented Aug 27, 2020

⌛ Testing commit c9ead8c with merge 3d0c847...

@bors
Copy link
Collaborator

bors commented Aug 27, 2020

☀️ Test successful - checks-actions, checks-azure
Approved by: oli-obk
Pushing 3d0c847 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 27, 2020
@bors bors merged commit 3d0c847 into rust-lang:master Aug 27, 2020
dylanmckay added a commit to avr-rust/book.avr-rust.com that referenced this pull request Sep 3, 2020
dylanmckay added a commit to avr-rust/book.avr-rust.com that referenced this pull request Sep 3, 2020
@sunfishcode
Copy link
Member

Since -gnu matches an existing environment type, does that imply that the -atmega328 in the triple here refers to a new object format type?

@dylanmckay
Copy link
Contributor Author

Since -gnu matches an existing environment type, does that imply that the -atmega328 in the triple here refers to a new object format type?

It does not - here it is only meant to indicate that this triple specificaly targets the GNU toolchain/linker/libraries.

@dylanmckay dylanmckay deleted the replace-broken-avr-unknown-unknown-target branch October 29, 2020 12:18
@dylanmckay dylanmckay restored the replace-broken-avr-unknown-unknown-target branch January 28, 2021 18:33
@cuviper cuviper added this to the 1.48.0 milestone May 2, 2024
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Oct 4, 2024
…rochenkov

Fix `target_env` in `avr-unknown-gnu-atmega328`

The target name itself contains GNU, we should probably reflect that as `target_env = "gnu"` as well? Or from my reading of rust-lang#74941 (comment), perhaps not, but then that should probably be documented somewhere?

There's no listed target maintainer, but the target was introduced in rust-lang#74941, so I'll ping the author of that: `@dylanmckay`

Relatedly, I wonder _why_ the recommendation is to [create separate target triples for each AVR](https://github.com/Rahix/avr-hal/tree/main/avr-specs), when `-Ctarget-cpu=...` would suffice, perhaps you could also elaborate on that? Was it just because `-Ctarget-cpu=...` didn't exist back then? If so, now that it does, should we now change the target back to e.g. `avr-unknown-none-gnu`, and require the user to set `-Ctarget-cpu=...` instead?
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Oct 5, 2024
Rollup merge of rust-lang#131171 - madsmtm:target-info-avr-env, r=petrochenkov

Fix `target_env` in `avr-unknown-gnu-atmega328`

The target name itself contains GNU, we should probably reflect that as `target_env = "gnu"` as well? Or from my reading of rust-lang#74941 (comment), perhaps not, but then that should probably be documented somewhere?

There's no listed target maintainer, but the target was introduced in rust-lang#74941, so I'll ping the author of that: `@dylanmckay`

Relatedly, I wonder _why_ the recommendation is to [create separate target triples for each AVR](https://github.com/Rahix/avr-hal/tree/main/avr-specs), when `-Ctarget-cpu=...` would suffice, perhaps you could also elaborate on that? Was it just because `-Ctarget-cpu=...` didn't exist back then? If so, now that it does, should we now change the target back to e.g. `avr-unknown-none-gnu`, and require the user to set `-Ctarget-cpu=...` instead?
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants