rustup: Rustup should warn if libgcc is not installed on Alpine

Describe the problem you are trying to solve

In Linux distributions which depend on musl libc, cargo crashes if libgcc is not present. This is the case in Alpine docker containers.

cargo
Error loading shared library libgcc_s.so.1: No such file or directory (needed by /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo)
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_GetIPInfo: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_GetDataRelBase: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_GetRegionStart: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_SetGR: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_FindEnclosingFunction: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_GetTextRelBase: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_Resume: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_DeleteException: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_RaiseException: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_GetIP: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_Backtrace: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_GetLanguageSpecificData: symbol not found
Error relocating /root/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo: _Unwind_SetIP: symbol not found

Unless you know what to install in order to resolve this issue, it is baffling. This problem will mainly affect beginners who want to learn rust.

Describe the solution you’d like

Rustup should warn on musl libc distributions (or maybe in any distribution) if it can’t find libgcc.

Notes

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 13
  • Comments: 35 (21 by maintainers)

Most upvoted comments

I think we need to document about using Rustc on Alpine in Rustup’s README file. The requirement is that Rustc needs gcc or clang pre-existing.

It’s not specific to musl. Similar error will appear when you try to run Cargo on glibc based distro without libgcc_s.so.1 installed.

The reason you can see it here but not on Ubuntu is because Alpine containers are stripped to the bare minimum and nothing has pulled libgcc as a dependency.

Generally you need linker (GCC or Clang) to use Rust and I’d be surprised if installing one of them haven’t pulled libgcc.

So the only issue here could be missing documentation (I haven’t checked).

rustc does not work as well. In fact, all the executables installed by rustup do not work without libgcc on Alpine.

I am trying to create a “No GNU” Rust toolchain stack on Alpine Linux. Any chance I can use compiler-rt from the llvm project in libgcc’s stead?

This issue is about libgcc_s which provide the same functions of llvm’s libunwind.

Functions of libgcc is provided by https://github.com/rust-lang/compiler-builtins/

@djc I’m curious why this was closed? Although it would be great if rust didn’t need libgcc_s on Alpine, it sounds like from https://github.com/rust-lang/rust/issues/119504 it is not feasible to avoid it? Although I’m not clear on the resolution there.

It seems like it would be helpful for rustup to let you know that there is more you need to install (similar to how it helps you with installing msvc). I’d agree that trying to validate everything about the user’s environment is correct is too much, but I think highlighting situations that are a frequent problem would be helpful.

So somewhere in README.md we should perhaps have a small section about how you most likely need gcc or clang in order to usefully build Rust applications, and how rustc and cargo itself is linked against libgcc on Linux platforms. Then instructions for a few common Linux platforms? That’d be a PR I’d very much consider merging.

I think such a warning belongs properly with either cargo or rustc : this sort of platform specific caveat is a moving target, and not really connected to the 'manage downloads of binaries and proxy calls to them to let different projects use different versions

@ehuss After discussing with rustc folks (rust-lang/rust#119504), the conclusions are:

  • rustc cannot link to libgcc_s (or libunwind) statically, it would break linking with C++.
  • There is a project called llvm-libgcc which adds additional symbols on top of libunwind, which provides 100% compatibility with libgcc_s .

So yeah, probably the best thing to do would be warning that either libgcc_s or llvm-libgcc (a better choice if you completely want to avoid using GNU userland) need to be installed.

Rustc uses GCC as the linker so users without GCC installed can only create static libs.

@mati865 while this is true with the default config, it’s possible to tell rustc to use rust-lld to link crates. In fact, this is done by default for certain targets (wasm comes to mind) and is used in a few projects to allow Rust to work standalone, without requiring additional software to be installed on the host.

My expectations for the musl toolchain binaries were for them to be entirely statically linked. After all, when you build a crate with the musl toolchain, it defaults to statically linking the libc and everything else. Is there a reason why libgcc-s cannot be statically linked?

Yes, I agree. While people could run rustc and cargo when having libgcc, missing C compiler prevents users from compiling libc, which is a huge loss anyway.

Rustc uses GCC as the linker so users without GCC installed can only create static libs.

So this is another example of “where does the documentation belong?” – for Windows we include instructions on getting the MSVC tooling installed, but we don’t include instructions really for other platforms. Where do we draw the line? Should the instructions be in the code or just the README, etc. There is at least some assumption that developers installing Rust with rustup know what they’re doing with respect to developing software on their host platform because otherwise they’re going to encounter many other interesting problems; but perhaps we (as an organisation) need to start documenting things more thoroughly so that newcomers are less surprised with the complexities?

I’m not sure that rustup can do anything programmatically to solve this, but perhaps more README docs are plausible.

I think the short answer is yes, libgcc_s.so is needed for now. I don’t know if it is possible (or desirable) to avoid.

But you’re also asking the wrong person, as I know next to nothing about musl. I think @mati865 is the expert here (rust-lang/rust#59302).

What is the right way to install libgcc here? apk?

Indeed.