rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
96.97k stars 12.53k forks source link

Link error when compiling reqwest with -C prefer-dynamic #82972

Closed davidlattimore closed 1 year ago

davidlattimore commented 3 years ago

I gather that prefer-dynamic isn't the preferred mode of compiling, but I use it in Evcxr to try and keep memory usage down when compiling and loading lots of .so files with similar dependencies.

Cargo.toml:

[package]
name = "foo"
version = "1.0.0"
edition = "2018"

[dependencies]
reqwest = "0.11"
tokio = {version = "1.2.0", features = ["full"]}

main.rs:

fn main() {
    let _ = tokio::runtime::Runtime::new()
        .unwrap()
        .block_on(async { reqwest::get("https://www.rust-lang.org") });
}

cargo build succeeds, however cargo rustc -- -C prefer-dynamic fails to link with lots of missing symbols. e.g.:

/usr/bin/ld: /home/david/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-channel-0.3.13/src/oneshot.rs:224: undefined reference to `core::mem::drop'
/usr/bin/ld: /home/david/.cargo/registry/src/github.com-1ecc6299db9ec823/futures-channel-0.3.13/src/oneshot.rs:233: undefined reference to `core::ptr::drop_in_place<futures_channel::lock::TryLock<core::option::Option<core::task::wake::Waker>>>'

Meta

Got this behavior on nightly 2021-03-09 as well as stable versions back as far as 1.44. Prior that the code doesn't compile due to missing features.

rustc +nightly --version --verbose:

rustc 1.52.0-nightly (3a5d45f68 2021-03-09) binary: rustc commit-hash: 3a5d45f68cadc8fff4fbb557780f92b403b19c19 commit-date: 2021-03-09 host: x86_64-unknown-linux-gnu release: 1.52.0-nightly LLVM version: 12.0.0

Original report: https://github.com/google/evcxr/issues/156

BGR360 commented 2 years ago

See also https://github.com/rust-lang/rust/issues/82151#issuecomment-779368017