Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

[AVR] Failure to compile libcore on nightly #76833

Closed
abusch opened this issue Sep 17, 2020 · 4 comments
Closed

[AVR] Failure to compile libcore on nightly #76833

abusch opened this issue Sep 17, 2020 · 4 comments
Labels
C-bug Category: This is a bug. O-AVR Target: AVR processors (ATtiny, ATmega, etc.) requires-nightly This issue requires a nightly compiler in some way. T-libs Relevant to the library team, which will review and decide on the PR/issue.

Comments

@abusch
Copy link

abusch commented Sep 17, 2020

I've been playing a bit with rust on an Arduino Uno with an atmega328p chip and since upgrading to the latest nightly, I am getting failures when it tries to compile libcore:

cargo build --release --bin pr02
   Compiling compiler_builtins v0.1.35
   Compiling core v0.0.0 (/home/abusch/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core)
   Compiling proc-macro2 v1.0.21
   Compiling unicode-xid v0.2.1
   Compiling syn v1.0.41
   Compiling semver-parser v0.7.0
   Compiling proc-macro-hack v0.5.18
   Compiling paste v1.0.1
   Compiling semver v0.9.0
   Compiling rustc_version v0.2.3
   Compiling quote v1.0.7
   Compiling bare-metal v0.2.5
error[E0527]: pattern requires 0 elements but array has 1
   --> /home/abusch/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:861:13
    |
861 |         let [] = [(); align_of::<AtomicPtr<()>>() - align_of::<*mut ()>()];
    |             ^^ expected 1 element

error[E0527]: pattern requires 0 elements but array has 1
    --> /home/abusch/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/sync/atomic.rs:1312:25
     |
1312 |                       let [] = [(); align_of::<Self>() - align_of::<$int_type>()];
     |                           ^^ expected 1 element
...
1998 | / atomic_int! {
1999 | |     cfg(target_has_atomic = "16"),
2000 | |     stable(feature = "integer_atomics_stable", since = "1.34.0"),
2001 | |     stable(feature = "integer_atomics_stable", since = "1.34.0"),
...    |
2013 | |     i16 AtomicI16 ATOMIC_I16_INIT
2014 | | }
     | |_- in this macro invocation
     |
     = note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)

This with the latest nightly:

❯ rustc --verbose --version
rustc 1.48.0-nightly (285fc7d70 2020-09-16)
binary: rustc
commit-hash: 285fc7d704fcdd7b2a37d475d04d5d955490e000
commit-date: 2020-09-16
host: x86_64-unknown-linux-gnu
release: 1.48.0-nightly
LLVM version: 11.0

I am using this target file: https://github.com/Rahix/avr-hal/blob/1c74cfca30de2fb8007d23d81540924e54d18cc8/chips/atmega328p-hal/avr-atmega328p.json

@abusch abusch added the C-bug Category: This is a bug. label Sep 17, 2020
@jonas-schievink jonas-schievink added T-libs Relevant to the library team, which will review and decide on the PR/issue. O-AVR Target: AVR processors (ATtiny, ATmega, etc.) labels Sep 17, 2020
@nagisa
Copy link
Member

nagisa commented Sep 19, 2020

Deciphering the failing expression it looks like we're trying to assert that the alignment of an AtomicPtr is equivalent to that of *mut ().

As per the data-layout of the linked target file (p:16:8) the pointer alignment is indeed set to 1 byte and we explicitly set the alignment of the AtomicPtr to 2 here introduced in this commit many moons ago, hence the bug.

The assertion itself was added in this commit and makes sense for what the function does cc @m-ou-se.

I would check if you can adjust the data layout to specify pointers are aligned to 2 bytes (you probably cannot).

I suspect the correct fix is probably to figure out how to set repr(align(ptr)) for AtomicPtr.

@nagisa nagisa added the requires-nightly This issue requires a nightly compiler in some way. label Sep 19, 2020
@m-ou-se

This comment has been minimized.

@m-ou-se
Copy link
Member

m-ou-se commented Sep 20, 2020

Should be fixed by #76965, which uses the information from the target file to determine alignment.

@jonas-schievink
Copy link
Contributor

Closing as fixed. Please let us know if the issue persists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. O-AVR Target: AVR processors (ATtiny, ATmega, etc.) requires-nightly This issue requires a nightly compiler in some way. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants