Repository navigation
Rustup should warn if libgcc is not installed on Alpine #2213
Copy link
Copy link
Open
Labels
O-containersNot really OS-related, but container-specificNot really OS-related, but container-specificO-linuxLinux relatedLinux relatedenhancement
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
O-containersNot really OS-related, but container-specificNot really OS-related, but container-specificO-linuxLinux relatedLinux relatedenhancement
Activity
kinnison commentedon Jan 25, 2020
Currently we have only Windows-specific information about toolchains and the like because it's semi-assumed that Linux and Mac OS people will know what they're doing to get their particular local distro's toolchains. It might be interesting for us to smoke-test components after installation and warn, but I'm not sure we can properly detect and diagnose this kind of issue across all our Linuxy targets.
Does
rustcwork? Is it onlycargowhich is failing like this? Ifrustcsimilarly fails, then we could could possibly add a message if we can't getrustc's version after install/update.thedrow commentedon Jan 26, 2020
rustcdoes not work as well.In fact, all the executables installed by rustup do not work without
libgccon Alpine.rbtcollins commentedon Jan 27, 2020
thedrow commentedon Jan 27, 2020
Indeed.
tesuji commentedon Jan 27, 2020
Is this intended that cargo on musl target depend on libgcc dynamically and cannot be
replaced? I ping @pietroalbini as he may know the answer or who else know that.
emilyalbini commentedon Jan 28, 2020
Hmm, I don't really know who to ask.
thedrow commentedon Jan 28, 2020
That's a very good question. I haven't thought of that.
tesuji commentedon Jan 28, 2020
Thank pietroalbini. I ping @ehuss as another change to get answer for #2213 (comment) .
ehuss commentedon Jan 28, 2020
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).
mati865 commentedon Jan 28, 2020
It's not specific to musl.
Similar error will appear when you try to run Cargo on glibc based distro without
libgcc_s.so.1installed.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).
kinnison commentedon Jan 28, 2020
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
rustupknow 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.
thedrow commentedon Jan 28, 2020
Assuming that the user knows the platform they are using is a bad idea. What if they are a junior developer with no prior experience with Docker or with Alpine?
kinnison commentedon Jan 28, 2020
I feel it's a really tough call to make @thedrow -- is it our place to know all the possible targets and the possible dependencies our users might have or not have? Or is it our place to recommend that platforms document what's needed to get Rust working? If we assume it's the responsibility of the rust-lang org in some sense, then what's the right thing to do? Something specific to Alpine? Something where we guess that if you're unable to run rustc and the host and build are musl then you can run whatever this
apkis? We don't instruct Ubuntu/Debian people toapt install binutilsor for Fedora people to play withyum. Where is the cutoff and where does the documentation go, and who is responsible for ensuring it's correct and kept up to date?I really want to do the right thing here, but we need to work out what that is.
tesuji commentedon Jan 30, 2020
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.
10 remaining items
workingjubilee commentedon Apr 29, 2021
@rustbot label: +O-linux
12101111 commentedon May 19, 2021
crt is a different thing, see the doc at https://github.com/rust-lang/rust/blob/master/compiler/rustc_target/src/spec/crt_objects.rs
But it's possible to bootstrap such toolchain that don't need
libgcc_s.soorlibunwind.so: rust-lang/rust#85600workingjubilee commentedon May 21, 2021
@rustbot label: +O-containers
rinarakaki commentedon Aug 31, 2023
What is the current recommended approach for this? Just
apk add libgccor any better toolchain?vadorovsky commentedon Dec 31, 2023
Couldn't this issue be solved by linking LLVM libunwind statically in the binary builds used for Rustup?
Even dynamic libunwind.so works as a drop-in replace replacing libgcc_s for me. I'm running Gentoo (with llvm+musl profile), I don't have GCC installed and all I had to do to fix the issue locally is:
That's it. I'm pretty sure it would work on Alpine too. Rustup toolchains work and I didn't have to install GCC, my environment pretty much stays non-GNU. I'm using Rust daily for pretty much all of my programming work and I didn't notice any issues.
But I think that the right thing to do would be just linking libunwind statically. Any objections against that? I think that would make everyone happy:
From what @12101111 says, it should be already possible. I can try building rustc myself and I will follow up with a config and options that need to be passed, if you are open for going with this solution.
workingjubilee commentedon Jan 1, 2024
It is unlikely that rustup's build will be significantly special-cased compared to the default build for that platform. If the appropriate thing to change here is to change the linkage of programs, then it is a problem that should probably be addressed upstream with rustc. I recommend that this issue be closed, because it incorrectly asks for rustup to have a special behavior regarding issuing warnings instead of simply solving the damn problem.
vadorovsky commentedon Jan 1, 2024
I totally agree, I created rust-lang/rust#119504 to discuss the problem there.
ehuss commentedon Jan 4, 2024
@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 rust-lang/rust#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.
djc commentedon Jan 9, 2024
@ehuss I mostly thought @workingjubilee made a compelling argument. If we think rustc doesn't have enough information to do a good job here, I'm open to considering adding a warning in rustup.
vadorovsky commentedon Jan 12, 2024
@ehuss After discussing with rustc folks (rust-lang/rust#119504), the conclusions are:
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.
rbtcollins commentedon Jan 13, 2024
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