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

enabling "time" feature under -Ctarget-feature=+crt-static and -Zbuild-std=std,panic_abort causes a linker error #5376

Closed
littzhch opened this issue Jan 14, 2023 · 1 comment
Labels
A-tokio Area: The main tokio crate

Comments

@littzhch
Copy link

Version
tokio v1.24.1
rustc 1.68.0-nightly (0b90256ad 2023-01-13)

Platform
Linux 6.1.4-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 07 Jan 2023 15:10:07 +0000 x86_64 GNU/Linux

Description
enabling "time" feature under -Ctarget-feature=+crt-static and -Zbuild-std=std,panic_abort causes a linker error. It seems that there are conflict symbols between libgcc.a and libcompiler_builtins.rlib.

I tried this code:

# Cargo.toml
[dependencies]
tokio = {version = "1", features = ["rt", "time"]}
// main.rs
fn main() {
    let _ = tokio::runtime::Builder::new_current_thread().build();
}

build command:

RUSTFLAGS="-Ctarget-feature=+crt-static" cargo +nightly build -Z build-std=std,panic_abort --target x86_64-unknown-linux-gnu

I expected to see this happen: successfully compiled
Instead, this happened:

error: linking with `cc` failed: exit status: 1
  |
  = note: LC_ALL="C" PATH="/home/littzhch/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/bin:/usr/local/sbin:/usr/local/bin:/usr/bin:/usr/lib/jvm/default/bin:/usr/bin/site_perl:/usr/bin/vendor_perl:/usr/bin/core_perl:/home/littzhch/.local/bin:/home/littzhch/.cargo/bin" VSLANG="1033" "cc" "-m64" "/tmp/rustctGj6UT/symbols.o" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/rtest-bd3374c760284bbe.1tr20zrqvjebqake.rcgu.o" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/rtest-bd3374c760284bbe.45tnj5lua2phsytt.rcgu.o" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/rtest-bd3374c760284bbe.4cpvu8nv56qqistx.rcgu.o" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/rtest-bd3374c760284bbe.5g2s7jcu83zw8ymk.rcgu.o" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/rtest-bd3374c760284bbe.5umyh4jlsmtl621.rcgu.o" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/rtest-bd3374c760284bbe.vqm1kclou91r0zy.rcgu.o" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/rtest-bd3374c760284bbe.42t89alsc76u1n3u.rcgu.o" "-Wl,--as-needed" "-L" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps" "-L" "/home/littzhch/Documents/code/CLionProjects/rtest/target/debug/deps" "-L" "/home/littzhch/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libtokio-1ffd24c4c408a3bb.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libpin_project_lite-6a5e4cbd6e8abf29.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libstd-8a33c92b99e4130e.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libpanic_unwind-766d1fc1fbc06b5f.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libobject-d4101cdc877ba69d.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libmemchr-9cd65cbae8c183b6.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libaddr2line-eac2fc6a6d56c6c8.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libgimli-59c0ff6b4a7a390d.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/librustc_demangle-4a186183a14df028.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libstd_detect-59cb4ddef704fd10.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libhashbrown-90f9596124847c34.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libminiz_oxide-7291f4f58c1e436b.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libadler-9bd49e147e9550b0.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/librustc_std_workspace_alloc-83ae7ef5a5d3a9a6.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libunwind-d73dc230b5fe36a0.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libcfg_if-5293756c4695c9d1.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/liblibc-19794c4b50d5a0a1.rlib" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc" "-lgcc_eh" "-lgcc" "-lc" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/liballoc-3a03e904b8b6318c.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/librustc_std_workspace_core-e70dffcab5345a99.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libcore-ccc1e2b7bfcb0eff.rlib" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libcompiler_builtins-1fba6df7def69afa.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-znoexecstack" "-L" "/home/littzhch/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-o" "/home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/rtest-bd3374c760284bbe" "-Wl,--gc-sections" "-static-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs"
  = note: /usr/bin/ld: /home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libstd-8a33c92b99e4130e.rlib(std-8a33c92b99e4130e.std.9d21884c-cgu.6.rcgu.o): in function `std::sys::unix::os::home_dir::fallback':
          /home/littzhch/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys/unix/os.rs:626: warning: Using 'getpwuid_r' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
          /usr/bin/ld: /home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libstd-8a33c92b99e4130e.rlib(std-8a33c92b99e4130e.std.9d21884c-cgu.15.rcgu.o): in function `<std::sys_common::net::LookupHost as core::convert::TryFrom<(&str,u16)>>::try_from::{{closure}}':
          /home/littzhch/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/sys_common/net.rs:206: warning: Using 'getaddrinfo' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking
          /usr/bin/ld: /home/littzhch/Documents/code/CLionProjects/rtest/target/x86_64-unknown-linux-gnu/debug/deps/libcompiler_builtins-1fba6df7def69afa.rlib(compiler_builtins-1fba6df7def69afa.compiler_builtins.372063ae-cgu.9.rcgu.o): in function `__umodti3':
          /home/littzhch/.cargo/registry/src/mirrors.ustc.edu.cn-61ef6e0cd06fb9b8/compiler_builtins-0.1.85/src/macros.rs:394: multiple definition of `__umodti3'; /usr/lib/gcc/x86_64-pc-linux-gnu/12.2.0/libgcc.a(_umoddi3.o):(.text+0x0): first defined here
          collect2: error: ld returned 1 exit status
          

error: could not compile `rtest` due to previous error
@littzhch littzhch added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Jan 14, 2023
@taiki-e
Copy link
Member

taiki-e commented Jan 15, 2023

glibc does not support static linking well enough and It is known that even simple examples using only the standard library do not work well (e.g., rust-lang/rust#100711). if you want to use static linking in linux, it is recommended to use musl.

I will close this because I don't think this is a tokio problem.

@taiki-e taiki-e closed this as completed Jan 15, 2023
@taiki-e taiki-e removed the C-bug Category: This is a bug. label Jan 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate
Projects
None yet
Development

No branches or pull requests

2 participants