Skip to content
This repository has been archived by the owner on Jan 2, 2021. It is now read-only.

Dynamically load libm on Linux for each new session #723

Merged
merged 1 commit into from
Sep 3, 2020

Conversation

lukel97
Copy link
Collaborator

@lukel97 lukel97 commented Aug 6, 2020

This fixes the issue on Linux where the binary was statically linked and Template Haskell (or the eval plugin on haskell-language-server) tried to evaluate some code. It would previously fail to load ghc-prim because it couldn't lookup symbols from libm which are usually dynamically linked in.

See haskell/haskell-language-server#221

Unfortunately we can't just statically link in libm and have the binary dlsym on itself apparently: https://stackoverflow.com/questions/14289488/use-dlsym-on-a-static-binary

So now the statically linked binary actually dynamically links in libm on a "best-effort" case: From what I can tell if libm is not available this will just print an error to stderr and carry on as usual (albeit it will trip up on Template Haskell), and if the binary dynamically linked then this will have no effect.

cc @pepeiborra

Copy link
Collaborator

@pepeiborra pepeiborra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is the best solution, but in any case it buys some time until we can figure it out. Thanks for the continued digging on this @bubba !

@pepeiborra
Copy link
Collaborator

A fair point to make is that currently this is only relevant for HLS, and therefore maybe it belongs in the HLS Main module

@lukel97
Copy link
Collaborator Author

lukel97 commented Aug 9, 2020

There was a way I saw originally to load in libm without the HscEnv which we could do, I'm not 100% sure what the difference is though. At some point we should also revisit this and see what is the correct way to fix this in the long term

@pepeiborra
Copy link
Collaborator

Can you rebase or otherwise retrigger CI somehow? I need a green light to merge!

@cocreature
Copy link
Collaborator

@pepeiborra /azp run should work for anyone with write access to the repo I believe.

@lukel97
Copy link
Collaborator Author

lukel97 commented Sep 2, 2020

/azp run

@azure-pipelines
Copy link

No pipelines are associated with this pull request.

This fixes the issue on Linux where the binary was statically linked and
Template Haskell (or the eval plugin on haskell-language-server) tried
to evaluate some code. It would previously fail to load ghc-prim because
it couldn't lookup symbols from libm which are usually dynamically
linked in.
@cocreature
Copy link
Collaborator

hm /azp run probably got lost in the repo transfer. Try it out on new PRs.

@pepeiborra pepeiborra merged commit f8889c7 into haskell:master Sep 3, 2020
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
This fixes the issue on Linux where the binary was statically linked and
Template Haskell (or the eval plugin on haskell-language-server) tried
to evaluate some code. It would previously fail to load ghc-prim because
it couldn't lookup symbols from libm which are usually dynamically
linked in.
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
This fixes the issue on Linux where the binary was statically linked and
Template Haskell (or the eval plugin on haskell-language-server) tried
to evaluate some code. It would previously fail to load ghc-prim because
it couldn't lookup symbols from libm which are usually dynamically
linked in.
pepeiborra pushed a commit to pepeiborra/ide that referenced this pull request Dec 29, 2020
This fixes the issue on Linux where the binary was statically linked and
Template Haskell (or the eval plugin on haskell-language-server) tried
to evaluate some code. It would previously fail to load ghc-prim because
it couldn't lookup symbols from libm which are usually dynamically
linked in.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants