-
Notifications
You must be signed in to change notification settings - Fork 13.2k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Link against LLVM libunwind (statically) instead of libgcc_s (dynamically) on Linux targets #119504
Comments
Systems without a GNU userland shouldn't use the *-linux-unknown-gnu toolchains, which explicitly require a GNU userland. Your supposed to use *-linux-unknown-musl. |
The same problem happens on *-linux-unknown-musl toolchains - it still requires libgcc_s. The error I pasted is from a musl toolchain installed with rustup. |
Ah, I see. The host tools for x86_64-unknown-linux musl are built with |
That will break linking against C++ code. There can only be a single unwinder runtime in the entire program if you want to be able to unwind across dynamic library boundaries, which we support using rust/library/unwind/src/lib.rs Line 56 in e51e98d
|
LLVM libunwind is not a drop-in replacement for They are different because libgcc_s (and llvm-libgcc) provide more symbols than libunwind.
As the doc of llvm-libgcc say, libgcc_s.so is a required dependency in the Linux standard base, so we should assume it's installed. And as @bjorn3 say, rustc will load both If |
The libstd.so that rustc itself is linked against is compiled while building the previous bootstrap stage, so that is not the issue. What is an issue however is that libLLVM doesn't link against libstd and much more importantly that proc macros (which rustc dlopen's) don't link against libstd.so either but statically link it.
In the case of pure rust code we only use libgcc_s for the unwind runtime. The compiler intrinsics are defined by the compiler_builtins crate (unless libgcc or compiler-rt is statically linked and takes precedence). For the C code that is shipped with rustc (LLVM, lld, ...) it is indeed a potential problem though. |
Follow up for the issue rust-lang/rustup#2213, which is probably more accurate to be discussed and potentially fixed in rustc rather than rustup.
Problem
The default Rust builds (like the ones shipped in rustup) are dynamically linked against libgcc_s, which forces users to install GCC-related packages even on distributions which don't ship the GNU userland by default (Alpine, Gentoo with llvm-musl profile etc.). Without libgcc installed, users face the following error:
Potential solution
LLVM libunwind can be just used as a drop-in replacement for libgcc_s without causing any issues. In fact, I did the following as a workaround on my Gentoo (llvm-musl profile) installation, which doesn't have GCC nor glibc installed:
and it works. I'm daily driving Rust on that machine without any issues.
So to make it easier for everyone, we could probably just link libunwind statically for all Linux targets (or at least the musl ones) by default, since the LLVM backend is the default one anyway. One thing to consider could be an opt-in way to use libgcc_s (which would make a lot of sense when using GCC backend).
The text was updated successfully, but these errors were encountered: