Description
Context
A few nights ago, CI started failing for some msp430 firmware I use to make sure that msp430 Rust code builds:
Compiling rustc-std-workspace-core v1.99.0 (/usr/share/rust/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/rustc-std-workspace-core)
LLVM ERROR: Cannot select: 0x7fbca0892c98: i16,ch = AtomicLoad<(load unordered (s16) from %ir.49)> 0x7fbca08313e8, 0x7fbca0893340
0x7fbca0893340: i16,ch = CopyFromReg 0x7fbca08313e8, Register:i16 %19
0x7fbca08a1c30: i16 = Register %19
In function: memcpy
error: could not compile `compiler_builtins`
MSP430 doesn't have meaningful atomic support, so I'm not sure why code using atomics is being generated.
Bisecting rustc
Using cargo-bisect-rustc
, I found the range of commits where compilation started failing.
searched nightlies: from nightly-2021-11-18 to nightly-2021-11-19
regressed nightly: nightly-2021-11-19
searched commits: from rust-lang/rust@c9c4b5d to rust-lang/rust@cc946fc
regressed commit: rust-lang/rust@b6f580a
bisected with cargo-bisect-rustc v0.6.0
Host triple: x86_64-unknown-linux-gnu
Reproduce with:
cargo bisect-rustc --preserve-target --preserve --start=2021-11-18 --end=2021-11-19 --with-src
I further bisected manually, the actual last good commit in rust is rust-lang/rust@a3b9405 and the regression is rust-lang/rust@88f1bf7. Commit b6591c2 bumps compiler_builtins
to 0.1.52
.
Bisecting compiler_builtins
Using a nightly from before the failure started (see "Other Notes"), the first compile failure I get is with commit ce86d41. The error is quite similar to the one in the CI failures:
william@xubuntu-dtrain:~/Projects/toolchains/compiler-builtins$ cargo build --t[14/661]p430-none-elf -Zbuild-std=core
Compiling compiler_builtins v0.1.49 (/home/william/Projects/toolchains/compiler-builtins)
warning: an associated function with this name may be added to the standard library in the future
--> src/float/pow.rs:8:19
|
8 | let mut pow = i32::abs_diff(b, 0);
| ^^^^^^^^^^^^^
|
= note: `#[warn(unstable_name_collisions)]` on by default
= warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
= note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
= help: call with fully qualified syntax `Int::abs_diff(...)` to keep using the current method
= help: add `#![feature(int_abs_diff)]` to the crate attributes to enable `num::<impl i32>::abs_diff`
LLVM ERROR: Cannot select: 0x7f6cd2888208: i16,ch = AtomicLoad<(load unordered (s16) from %ir.188)> 0x7f6cd287aa28:1, 0x7f6cd287aa28, src/mem/impls.rs:65:29 @[ src/mem/impls.rs:109:13 @[ src/mem/mod.rs:25:5 ] ]
0x7f6cd287aa28: i16,ch = load<(dereferenceable load (s16) from %ir.28)> 0x7f6cd287b270, FrameIndex:i16<24>, undef:i16, src/mem/impls.rs:65:69 @[ src/mem/impls.rs:109:13 @[ src/mem/mod.rs:25:5 ] ]
0x7f6cd287de38: i16 = FrameIndex<24>
0x7f6cd28427b8: i16 = undef
In function: memcpy
warning: `compiler_builtins` (lib) generated 1 warning
error: could not compile `compiler_builtins`; 1 warning emitted
I believe fixing the failure in compiler_builtins
will fix the error I'm seeing when compiling rustc
, and I would need to test locally. That said, I'm not sure what is causing compiler_builtins
to be built anyway when I specify -Zbuild-std=core
. Doesn't core
have no dependencies?
Solution
I'm not sure what should be done here. Can there be a gate for targets whose maximum atomic width is 0
? Although it eventually needs to be done, implementing atomic support for msp430 is unlikely right now, as I don't have the bandwidth to do it. Additionally, AIUI, Rust does not actually mandate that targets implement atomics, and that they should become noops/not available on targets without them (not just msp430).
Other Notes
Environment
rustc
william@xubuntu-dtrain:~/Projects/toolchains/compiler-builtins$ rustc -Vv
rustc 1.58.0-nightly (ff0e14829 2021-10-31)
binary: rustc
commit-hash: ff0e14829e1806ca0d4226595f7fdf3e8658758f
commit-date: 2021-10-31
host: x86_64-unknown-linux-gnu
release: 1.58.0-nightly
LLVM version: 13.0.0
cargo
william@xubuntu-dtrain:~/Projects/toolchains/compiler-builtins$ cargo -Vv
cargo 1.58.0-nightly (6c1bc24b8 2021-10-24)
release: 1.58.0
commit-hash: 6c1bc24b8b49d4bc965f67d7037906dc199c72b7
commit-date: 2021-10-24
host: x86_64-unknown-linux-gnu
libgit2: 1.3.0 (sys:0.13.23 vendored)
libcurl: 7.79.1-DEV (sys:0.4.49+curl-7.79.1 vendored ssl:OpenSSL/1.1.1l)
os: Ubuntu 20.04 (focal) [64-bit]
Circular Dependency Problems
I have to compile on msp430 using -Zbuild-std=core
, since it's not built as part of a Rust release right now. Even if I have an older version of compiler_builtins
checked out, using a too-recent nightly/commit causes -Zbuild-std=core
to compile compiler_builtins
v0.1.52
anyway as a dependency of the older compiler_builtins
in a fun circular dependency!
william@xubuntu-dtrain:~/Projects/toolchains/compiler-builtins$ LD_LIBRARY_PATH[20/450]william/Projects/toolchains/build-llvm-toolchain/build-llvm/lib:/home/william/Projects/toolchains/build-llvm-toolchain/build-rust/build/x86_64-unknown-linux-gnu/stage1/lib" cargo +msp430-fix build --target=msp430-none-elf -Zbuild-std=core
Compiling compiler_builtins v0.1.52
Compiling core v0.0.0 (/home/william/Projects/toolchains/build-llvm-toolchain/build-rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/core)
Compiling compiler_builtins v0.1.49 (/home/william/Projects/toolchains/compiler-builtins)
Compiling rustc-std-workspace-core v1.99.0 (/home/william/Projects/toolchains/build-llvm-toolchain/build-rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/src/rust/library/rustc-std-workspace-core)
warning: an associated function with this name may be added to the standard library in the future
--> src/float/pow.rs:8:19
|
8 | let mut pow = i32::abs_diff(b, 0);
| ^^^^^^^^^^^^^
|
= note: `#[warn(unstable_name_collisions)]` on by default
= warning: once this associated item is added to the standard library, the ambiguity may cause an error or change in behavior!
= note: for more information, see issue #48919 <https://github.com/rust-lang/rust/issues/48919>
= help: call with fully qualified syntax `Int::abs_diff(...)` to keep using the current method
= help: add `#![feature(int_abs_diff)]` to the crate attributes to enable `num::<impl i32>::abs_diff`
LLVM ERROR: Cannot select: t14: i16,ch = AtomicLoad<(load unordered (s16) from %ir.188)> t13:1, t13, /home/william/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.52/src/mem/impls.rs:65:29 @[ /home/william/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.52/src/mem/impls.rs:109:13 @[ /home/william/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.52/src/mem/mod.rs:25:5 ] ]
t13: i16,ch = load<(dereferenceable load (s16) from %ir.28)> t12, FrameIndex:i16<24>, undef:i16, /home/william/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.52/src/mem/impls.rs:65:69 @[ /home/william/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.52/src/mem/impls.rs:109:13 @[ /home/william/.cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.52/src/mem/mod.rs:25:5 ] ]
t11: i16 = FrameIndex<24>
t5: i16 = undef
In function: memcpy
error: could not compile `compiler_builtins`
warning: build failed, waiting for other jobs to finish...
warning: `compiler_builtins` (lib) generated 1 warning
error: build failed