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

static-haskell-nix: Explain linker warning #5

Closed
nh2 opened this issue Jun 12, 2018 · 1 comment
Closed

static-haskell-nix: Explain linker warning #5

nh2 opened this issue Jun 12, 2018 · 1 comment

Comments

@nh2
Copy link

nh2 commented Jun 12, 2018

From https://vaibhavsagar.com/blog/2018/01/03/static-haskell-nix/

"Using '<function>' in statically linked applications requires at runtime the shared libraries from the glibc version used for linking"

but these don’t seem to cause any issues in practice

I think that isn't quite accurate -- you are probably just lucky and ran the compiled program on a machine that happened to have the same (or compatible) version of glibc as your build system has.

glibc is not really compatible with static linking. It loads stuff dynamically at run time and assumes to find the same glibc version as on the machine the was compiled. You'll get hard errors if that isn't the case.

See https://stackoverflow.com/questions/8657908/deploying-yesod-to-heroku-cant-build-statically#answer-8658468 for some details.

As it's said there:

Contrary to popular belief, static linking [of glibc] produces less, not more, portable executables on Linux.

To be really more portable, you have to link against a libc that doesn't force dynamic behaviour as glibc does. For example, the musl libc. That's what Alpine Linux uses, and the reason that in the past stack supported building statically linked binaries in an Alpine Docker image (but this is currently broken with the latest Alpine and GHC releases).

You may want to update the article with this info, otherwise people will get some bad surprises.

Hopefully that will also motivate more people to improve the static linking situation, e.g. by making musl work nicely to solve the issue.

@vaibhavsagar
Copy link
Owner

Good point! I have updated the blog post.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants