Skip to content

-crt-static on musl links with libgcc_sΒ #82521

Open
@nitsky

Description

Hi, I am building dynamic libraries that I call from scripting languages (elixir nif, nodejs native addon, etc) on Alpine Linux. I have been successful using the x86_64-unknown-linux-musl target with -C target-feature=-crt-static to enable building cdylibs. However, I find that any cdylib produced this way links dynamically not only to musl but also to libgcc_s:

$ ldd target/release/libhello.so
/lib/ld-musl-x86_64.so.1 (0x7ffa2d2fb000)
libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x7ffa2d1cd000)
libc.musl-x86_64.so.1 => /lib/ld-musl-x86_64.so.1 (0x7ffa2d2fb000)

Unfortunately, the Alpine Linux docker image does not include the libgcc package by default, and the packages for most scripting languages do not depend on it, so users of my library will be required to explicitly install it, which is an inconvenience.

Below is the line in the unwind crate that dynamically links to libgcc_s on musl targets when crt-static is disabled:

#[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]

Is there a path to compiling cdylibs for musl without dynamically linking to libgcc_s? Perhaps while unwinding across FFI boundaries remains undefined behavior, -crt-static on musl could statically link the unwind functionality like it does with +crt-static?

Related issues:
#29527
#55120

rustc --version --verbose:

rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: x86_64-unknown-linux-musl
release: 1.50.0

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesC-bugCategory: This is a bug.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