cargo: i686-unknown-linux-gnu/bin/cargo: error while loading shared libraries: libatomic.so.1

Maintainer’s note:

In Rust 1.87, Cargo in the official Rust distribution will have a hard dependency on libatomic on 32-bit platforms.

For more, see


When running cargo in a quay.io/pypa/manylinux2014_i686:latest Docker container, it gives the following error

/root/.rustup/toolchains/nightly-i686-unknown-linux-gnu/bin/cargo: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory

Is libatomic.so.1 a hard requirement for cargo now?

Meta

rustc --version --verbose:

rustc 1.78.0-nightly (d18480b84 2024-03-04)

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 2
  • Comments: 24 (14 by maintainers)

Commits related to this issue

Most upvoted comments

The Cargo team has discussed this issue in today’s meeting. The root cause is convoluted, but can be seen as a bad interaction between Clang not providing built-in libatomic, and a bug in OpenSSL v3 that it doesn’t use aligned intergers on 32-bit platforms.

Folks on Zulip have evaluated some possible solutions, and agree with that the most straightforward solution is requiring libatomic on 32-bit platforms when running Cargo.

libatomic is generally available in major Linux distributions. If you’re seeing an error like this:

i686-unknown-linux-gnu/bin/cargo: error while loading shared libraries: libatomic.so.1

You could install libatomic through your system package manager. See the list of libatomic on every distros: https://pkgs.org/search/?q=libatomic.

Better get it reverted before it reaches stable I think?

is it possible to temporarily pin openssl to 1.0.66?

I don’t think so. openssl@1.0.66 has a hard requirement of OpenSSL v3, and just one comment above you can see how convoluted it is for the bump (or how dumb I am 😞).

In Cargo we only call openssl::version::version(). None of our dependencies require openssl (only openssl-sys through libgit2-sys/libssh2-sys), so I doubt Cargo is affected.

is it possible to temporarily pin openssl to 1.0.66? openssl has a vulnerability prior to 1.0.66, i don’t know if this affect the cargo code base.

Let me jot down what I’ve found so far, for building OpenSSL v3.4[^0] into Cargo with rust-lang CI.

  • Similar to sfackler/rust-openssl#2163 and openssl/openssl#23376, the dist-i686-linux build job from rust-lang/rust CI produces the cargo executable that dynamically links to libatomic.so.1. The ldd output looks like
    ldd obj/dist-i686-linux/build/i686-unknown-linux-gnu/stage2-tools-bin/cargo
          linux-gate.so.1 (0xf7fb6000)
          libdl.so.2 => /lib/libdl.so.2 (0xf583d000)
          libatomic.so.1 => not found
          libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xf5822000)
          librt.so.1 => /lib/librt.so.1 (0xf5819000)
          libpthread.so.0 => /lib/libpthread.so.0 (0xf57fb000)
          libm.so.6 => /lib/libm.so.6 (0xf573e000)
          libc.so.6 => /lib/libc.so.6 (0xf55b0000)
          /lib/ld-linux.so.2 (0xf7fb8000)
    
    On some distributions there is no libatomic available, so it failed.
  • Setting -DBROKEN_CLANG_ATOMICS in openssl-src build didn’t help.
  • Removing -latomic (cargo:rustc-link-lib=atomic) from rust-openssl didn’t help.
  • In contrast, cargo from the dist-x86_64-linux job doesn’t dynamically link to libatomic at all. The ldd output is like
    ldd obj/dist-x86_64-linux/build/x86_64-unknown-linux-gnu/stage2-tools-bin/cargo
          linux-vdso.so.1 (0x00007ffe9d249000)
          libdl.so.2 => /lib64/libdl.so.2 (0x00007f250d26d000)
          libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x00007f250d057000)
          librt.so.1 => /lib64/librt.so.1 (0x00007f250ce4f000)
          libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f250cc31000)
          libm.so.6 => /lib64/libm.so.6 (0x00007f250c8f1000)
          libc.so.6 => /lib64/libc.so.6 (0x00007f250c544000)
          /lib64/ld-linux-x86-64.so.2 (0x00007f250f507000)
    
  • Switching CC to gcc eliminates the dynamic links. The ldd output looks like
    ldd obj/dist-i686-linux/build/i686-unknown-linux-gnu/stage2-tools-bin/cargo
          linux-gate.so.1 (0xf7f79000)
          libdl.so.2 => /lib/libdl.so.2 (0xf574f000)
          libgcc_s.so.1 => /lib/libgcc_s.so.1 (0xf5734000)
          librt.so.1 => /lib/librt.so.1 (0xf572b000)
          libpthread.so.0 => /lib/libpthread.so.0 (0xf570d000)
          libm.so.6 => /lib/libm.so.6 (0xf5650000)
          libc.so.6 => /lib/libc.so.6 (0xf54c2000)
          /lib/ld-linux.so.2 (0xf7f7b000)
    

The potential reason is that we set CC in the dist-i686-linux job image, so it builds a cargo linking to libatomic.so instead of statically linkage. And clang doesn’t provide built-in atomic lib, according to its doc. It has also be discussed in https://github.com/llvm/llvm-project/issues/73361 and https://github.com/mstorsjo/llvm-mingw/issues/384. I’ve tried adding -DCOMPILER_RT_EXCLUDE_ATOMIC_BUILTIN=OFF[^1] and -DCOMPILER_RT_USE_ATOMIC_LIBRARY=ON when bootstrapping the first clang in the dist-i686-linudex job. Nothing changed.

It has been more than one year since OpenSSL v1.1.1 EOL (2023-09-11), we should take action on this, either try harder upgrading to OpenSSL v3, or find an alternative like rustls or aws-lc. See also how rustup struggles to upgrade OpenSSL https://github.com/rust-lang/rustup/issues/3790.

[^0]: openssl@0.10.68, openssl-sys@0.9.104, and openssl-src@300.4.0+3.4.0 respectively [^1]: requires gcc10 to fix preprocessor errors and -DCOMPILER_RT_HAS_WBUILTIN_DECLARATION_MISMATCH_FLAG=OFF to surpress some errors.

@messense should have been fixed via rust-lang/cargo#14391 and rust-lang/rust#129066. (Sorry I should have paid more attention to manual cargo update 🙇🏾‍♂️ )

This seems to happen again in rust version 1.79.0-nightly (8b2459c1f 2024-04-09)

 info: downloading installer
  Warning: Not enforcing strong cipher suites for TLS, this is potentially less secure
  info: profile set to 'minimal'
  info: default host triple is i686-unknown-linux-gnu
  info: syncing channel updates for 'nightly-i686-unknown-linux-gnu'
  info: latest update on 2024-04-10, rust version 1.79.0-nightly (8b2459c1f 2024-04-09)
  info: downloading component 'cargo'
  info: downloading component 'rust-std'
  info: downloading component 'rustc'
  info: installing component 'cargo'
  info: installing component 'rust-std'
  info: installing component 'rustc'
  
  info: default toolchain set to 'nightly-i686-unknown-linux-gnu'
    nightly-i686-unknown-linux-gnu installed - rustc 1.79.0-nightly (8b2459c1f 2024-04-09)
  
  
  Rust is installed now. Great!
  
  To get started you may need to restart your current shell.
  This would reload your PATH environment variable to include
  Cargo's bin directory ($HOME/.cargo/bin).
  
  To configure your current shell, you need to source
  the corresponding env file under $HOME/.cargo.
  
  This is usually done by running one of the following (note the leading DOT):
  . "$HOME/.cargo/env"            # For sh/bash/zsh/ash/dash/pdksh
  source "$HOME/.cargo/env.fish"  # For fish
  Install Rust toolchain nightly
  info: override toolchain for '/home/runner/work/rjsonnet-py/rjsonnet-py' set to 'nightly-i686-unknown-linux-gnu'
  info: downloading component 'llvm-tools'
  info: installing component 'llvm-tools'
/root/.rustup/toolchains/nightly-i686-unknown-linux-gnu/bin/cargo: error while loading shared libraries: libatomic.so.1: cannot open shared object file: No such file or directory