Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

staticlib libgcc_s dependency requirement since 1.21.0 (nightly-2017-08-24) #55120

Open
tombruijn opened this issue Oct 16, 2018 · 3 comments
Open
Labels
A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@tombruijn
Copy link

tombruijn commented Oct 16, 2018

Hi Rust team!

Since Rust 1.21.0 and nightly-2017-08-24 a new dependency, libgcc_s, is needed for static libraries we're building for gnu, musl and freebsd targets.

This requirement slipped past us during a recent upgrade because the build process did not inform us of this new requirement. (I see this is an option --print=native-static-libs in the latest nightly (nightly-2018-10-10) and unreleased 1.22.0.)

The change was only visible to us upon linking to an Elixir app as a NIF during a two stage build process where on the second stage this particular library was absent. The error we see is:

Error loading shared library libgcc_s.so.1: No such file or directory (needed by /app/lib/elixir_package-0.0.1/priv/elixir_package_extension.so)

From what I can tell this commit and its parent PR (#40113) seem related to this issue. According to the commit and PR the libgcc_s link requirement gets added for the musl target/to support dynamically-linked musl targets.

However, we see this requirement listed on the latest nightly for the gnu and freebsd targets as well.

Was this libgcc_s link requirement intended for the gnu and freebsd targets as well? Or was this an unintended change?

Reproducible example project

To track the issue down I created an example project with a reproducible state. It allows building an example Rust staticlib for musl and link it to Elixir as a NIF. Instructions can be found in the README. I'm adding this to add context and show a scenario to show how this requirement breaks between versions.

https://github.com/tombruijn/rust-elixir-linking-issue-example-project

@jonas-schievink jonas-schievink added A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 6, 2019
@wader
Copy link

wader commented Nov 11, 2020

I think my alpine static package issue is related to this https://gitlab.alpinelinux.org/alpine/aports/-/issues/11806 (rustc --crate-type staticlib --print native-static-libs includes gcc_s)

@wader
Copy link

wader commented Sep 26, 2022

The alpine rust package now has a patch to fix this https://gitlab.alpinelinux.org/alpine/aports/-/merge_requests/36627/diffs

@xclaesse
Copy link

I think --print native-static-libs should only include libraries needed to use the produced staticlib. For example -lc I believe is not needed as that will always be added by default by linker. Likewise on Windows -lkernel32 should not be needed.

Typically on Linux it should correspond to flags we usually get from pkg-config --libs --static mylib.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-linkage Area: linking into static, shared libraries and binaries T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

4 participants