rust-lang/compiler-builtins

multiple rlib candidates for `compiler_builtins` found

tomaka opened this issue · 9 comments

Sorry if this is not the right place to report this issue.

After upgrading to the latest nightly, my no_std project suddenly stopped compiling with this error:

error[E0465]: multiple rlib candidates for `compiler_builtins` found
  |
  = note: candidate #1: /home/pierre/Projets/os/target/arm-freestanding/release/deps/libcompiler_builtins-26c139968e75b8d8.rlib
  = note: candidate #2: /home/pierre/Projets/os/target/arm-freestanding/release/deps/libcompiler_builtins-1ff647597e07803f.rlib

error[E0463]: can't find crate for `compiler_builtins`

I'm following the instructions in README.md which ask you to add compiler_builtins as a dependency and add extern crate compiler_builtins;.

It seems that Rust indeed passes compiler_builtins twice when compiling the crate. Here's a fragment of the invocation of rustc:

--extern 'noprelude:compiler_builtins=/home/pierre/Projets/os/target/arm-freestanding/release/deps/libcompiler_builtins-1ff647597e07803f.rlib' --extern compiler_builtins=/home/pierre/Projets/os/target/arm-freestanding/release/deps/libcompiler_builtins-26c139968e75b8d8.rlib

Interestingly, if I do that in Cargo.toml:

compiler_builtins_under_a_different_name = { package = "compiler_builtins", git = "https://github.com/rust-lang/compiler-builtins" }

And then extern crate compiler_builtins_under_a_different_name;, then everything works fine on some platforms but gives linking errors for memcpy for memcmp on some others.

Are you using -Zbuild-std? In that case, you should not add compiler_builtins as dependency yourself. cargo will build it automatically for you.

Are you using -Zbuild-std? In that case, you should not add compiler_builtins as dependency yourself. cargo will build it automatically for you.

Yes I'm using -Zbuild-std! I'm doing -Zbuild-std=core,compiler_builtins,alloc

Not adding compiler_builtins as a dependency leads to ld.lld: error: undefined symbol: memcmp.
(these linking errors are the reason I've added compiler_builtins as a dependency in the first place)

It seems that the mem feature of compiler-builtins is not enabled by default. By the way compiler_builtins is enabled by default when core is enabled: https://github.com/rust-lang/cargo/blob/86134e7666a088682f20b76278c3ee096a315218/src/cargo/core/compiler/standard_lib.rs#L25-L27

Rust actually pins 0.1.22 in Cargo.lock: https://github.com/rust-lang/rust/blob/f6dca76be55dd6bb8d0d7d3b6bc39ae8373db506/Cargo.lock#L571-L573. I wonder if -Zbuild-std uses Cargo.lock. If so, you may be able to edit it to use compiler-builtins 0.1.22.

(sorry, I deleted a comment in-between, as I realized what you said)

I think my issue is rust-lang/wg-cargo-std-aware#15 and rust-lang/wg-cargo-std-aware#28

I don't really understand why the compiler-builtins-mem feature of the alloc crate is disabled by default.
It is unconditionally enabled by Rust when compiling: https://github.com/rust-lang/rust/blob/a916ac22b9f7f1f0f7aba0a41a789b3ecd765018/src/bootstrap/compile.rs#L204

I think this is likely a bug with -Zbuild-std rather than this crate itself, so mind reopening this on the std-aware repository?

Hi

is there a solution for this already? I face a similar issue when building for a custom target with -Zbuild-std=core,alloc and providing compiler_builtins as dependency in Cargo.toml file.

Any help much appreciated. Thanks

@AthiraRamakrishna this has been closed for a long time. Could you open a new issue describing what you are trying and what problem you are experiencing?