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

HLS is broken with some TH code: "Error dynamically loading libm.so.6" #1601

Closed
sonowz opened this issue Mar 21, 2021 · 4 comments
Closed

HLS is broken with some TH code: "Error dynamically loading libm.so.6" #1601

sonowz opened this issue Mar 21, 2021 · 4 comments
Labels
can-workaround component: ghcide os: nixos type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@sonowz
Copy link

sonowz commented Mar 21, 2021

Your environment

  • VSCode
  • NixOS 20.09, with either remote-SSH or remote-WSL
  • haskell-language-server version: 1.0.0.0
  • stack : 2.3.3

The error

[INFO] Making new HscEnv[main]
Error dynamically loading libm.so.6:
libm.so.6: cannot open shared object file: No such file or directory

The cause

res <- loadDLL hscEnv "libm.so.6"
case res of
Nothing -> pure ()
Just err -> hPutStrLn stderr $
"Error dynamically loading libm.so.6:\n" <> err

Related PR: haskell/ghcide#723

The cause is straightforward: by default NixOS does not have libm.so.6 nor glibc in its system environment. Thus HLS literally can't load libm.so.6.

The workaround

Setting LD_LIBRARY_PATH to the path which libm.so.6 lives works and the error is gone. XD

with import <nixpkgs> {};
stdenv.mkDerivation {
  name = "glibc-patch";
  buildInputs = [ glibc ];
  LD_LIBRARY_PATH = "${glibc}/lib/";
}

Long description

For NixOS, it seems like the error is raised every time I use HLS.
Generally, HLS works as normal, and the error doesn't affect anything. Just error message above (Error dynamically loading libm.so.6).
However, if the source code uses some TemplateHaskell, almost every HLS feature is broken and produces error below. No code highlighting, no type hints.
image

I think HLS is broken only when system calls in libm.so.6 really gets called.

@jneira jneira added can-workaround os: nixos type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Mar 21, 2021
@jneira
Copy link
Member

jneira commented Mar 21, 2021

@sonowz wow, this is a almost perfect bug report, many thanks 😄

Not sure what could be a definitive solution, pinging @pepeiborra just in case.

@jneira jneira changed the title NixOS: HLS is broken with some TH code HLS is broken with some TH code: "Error dynamically loading libm.so.6" Mar 21, 2021
@pepeiborra
Copy link
Collaborator

The best solution is probably to build HLS with Nix, and not reuse the pre-built binaries

@sonowz
Copy link
Author

sonowz commented Mar 23, 2021

I came up with something like this:

res <- loadDLL hscEnv "libm.so.6" 
case res of 
  Nothing -> pure () 
  Just err -> downloadLibM >> loadDLL hscEnv "libm.so.6"

Is this possible? I have no expertise in these OS-level thingy..

@jneira
Copy link
Member

jneira commented Jan 31, 2022

I am gonna close this issue as all compiler crashes seems to have the same root cause:

If any of you think the issue should not be included generically feel free to reopen it (with a brief explanation if possible)
Thanks all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
can-workaround component: ghcide os: nixos type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

3 participants