static-haskell-nix: Explain linker warning
nh2 opened this issue · 1 comments
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.
Good point! I have updated the blog post.