Skip to content

Link against LLVM libunwind (statically) instead of libgcc_s (dynamically) on Linux targets #119504

@vadorovsky

Description

@vadorovsky

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:

Error loading shared library libgcc_s.so.1: No such file or directory (needed by /home/vadorovsky/.rustup/toolchains/stable-x86_64-unknown-linux-musl/bin/cargo)

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:

ln -s /usr/lib/libunwind.so.1 /usr/lib/libgcc_s.so.1
ln -s /usr/lib/libunwind.so /usr/lib/libgcc_s.so

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).

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-discussionCategory: Discussion or questions that doesn't represent real issues.O-muslTarget: The musl libcT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions