Skip to content

hls fails with linker error due to missing symbols (with ghc linked dinamically) #787

Closed

Description

@merijn

When trying to use ghcide in my codebase I run into a weird linker issue where Haskell symbols can't be loaded because libc symbols they refer to are missing, as per the following error:

ghcide: /home/mverstra/.cabal/store/ghc-8.6.5/persistent-sqlite-2.10.6.2-7f73d67da3642575ea84da1a97de2359947f3009597095d9e4a57c670f242398/lib/libHSpersistent-sqlite-2.10.6.2-7f73d67da3642575ea84da1a97de2359947f3009597095d9e4a57c670f242398.a: unknown symbol `stat64'
ghcide: /home/mverstra/.cabal/store/ghc-8.6.5/persistent-sqlite-2.10.6.2-7f73d67da3642575ea84da1a97de2359947f3009597095d9e4a57c670f242398/lib/libHSpersistent-sqlite-2.10.6.2-7f73d67da3642575ea84da1a97de2359947f3009597095d9e4a57c670f242398.a: unknown symbol `sqlite3_errmsg'
ghcide: ^^ Could not load 'persistentzmsqlitezm2zi10zi6zi2zm7f73d67da3642575ea84da1a97de2359947f3009597095d9e4a57c670f242398_DatabaseziSqlite_zdfShowError_closure', dependency unresolved. See top entry above.

File:     /home/mverstra/gpu/benchmark-analysis/src/Schema/Implementation.hs
Hidden:   no
Range:    1:0-100001:0
Source:   typecheck
Severity: DsError
Message:
  Program error:
  ByteCodeLink.lookupCE
  During interactive linking, GHCi couldn't find the following symbol:
  persistentzmsqlitezm2zi10zi6zi2zm7f73d67da3642575ea84da1a97de2359947f3009597095d9e4a57c670f242398_DatabaseziSqlite_zdfShowError_closure
  This may be due to you not asking GHCi to load extra object files,
  archives or DLLs needed by your current session. Restart GHCi, specifying
  the missing library using the -L/path/to/object/dir and -lmissinglibname
  flags, or simply by naming the relevant files on the GHCi command line.
  Alternatively, this link failure might indicate a bug in GHCi.
  If you suspect the latter, please send a bug report to:
  [email protected]

I've tried to debug this further, but I keep getting stuck. The codebase where it goes wrong can be found here: https://github.com/merijn/Belewitte

The C++ parts of the repo aren't relevant to Haskell code or error, running make in the benchmark-analysis directory is sufficient to build the Haskell bits of the repo. The code/makefile assumes GHC 8.6.5 and cabal-install >2.4. It can be build with GHC 8.10.1 too, if the Config.mk is edited to have PROJECTFILE:=cabal.project.ghc-8.10 (You can also point it at the right GHC and cabal-install binary if the wrong one is on PATH).

Running ghcide in the benchmark-analysis or any of the source files in it invariably triggers this error.

/CC @mpickering

Activity

  1. pepeiborra commented on May 9, 2020

    @pepeiborra
    Collaborator

    is ghcide built by the same version of ghc being used to build the codebase?

  2. merijn commented on May 9, 2020

    @merijn
    Author

    I'm using 8.6.5 for both. @mpickering was able to reproduce it before too. I suppose I could try what happens if I use 8.10 for both, but since the problem seems to be in the linking of libc I'm not sure whether it'd really affect anything.

  3. pepeiborra commented on May 10, 2020

    @pepeiborra
    Collaborator

    How do you build ghcide? If you are downloading a pre-built ghcide binary, it could have been linked to a different libc version.

  4. pepeiborra commented on May 10, 2020

    @pepeiborra
    Collaborator

    If you are embedding sqlite and using a statically linked build of ghc, or template haskell for that matter, you are probably running into this bug:

    https://gitlab.haskell.org/ghc/ghc/issues/7072

    Does ghci work?

    You can try to work around it by patching sqlite3.c as in https://github.com/IreneKnapp/direct-sqlite/pull/76/files

  5. merijn commented on May 10, 2020

    @merijn
    Author

    I'm building ghcide myself from digital-asset master and from mpickering's fork. Copying ghcide's flags and running ghci manually works fine.

  6. mpickering commented on May 10, 2020

    @mpickering
    Contributor

    Have you tried dynamically linking ghcide?

  7. merijn commented on May 10, 2020

    @merijn
    Author

    Not yet, is it as simple as dynamic: True in cabal.project or do I need to do something more involved?

  8. mpickering commented on May 10, 2020

    @mpickering
    Contributor

    You can add executable-dynamic: True to the cabal.project or pass --enable-execute-dynamic on the command line.

  9. merijn commented on May 11, 2020

    @merijn
    Author

    Ok, executable-dynamic: True seems fo fix this issue, so this appears to be the same as the ghc issue @pepeiborra linked, I'm not sure if this can be/should be fixed in GHC, ghcide or it's just a matter of "always link ghcide dynamically", though.

  10. pepeiborra commented on May 11, 2020

    @pepeiborra
    Collaborator

    I suspect the advice should indeed be "always link ghcide dynamically", just like ghc itself is built in most platforms.

  11. jneira commented on Oct 5, 2020

    @jneira
    Member

    Ok, maybe we should add the always link ghcide dynamically if ghc is to troubleshooting cause there are several issues here in hls about.

  12. changed the title [-]ghcide fails with linker error due to missing libc symbols[/-] [+]ghcide fails with linker error due to missing libc symbols (with ghc linked dinamically)[/+] on Oct 5, 2020
  13. transferred this issue fromhaskell/ghcideon Jan 1, 2021
  14. added
    type: bug
    on Jan 12, 2021
  15. changed the title [-]ghcide fails with linker error due to missing libc symbols (with ghc linked dinamically)[/-] [+]hls fails with linker error due to missing libc symbols (with ghc linked dinamically)[/+] on Jan 12, 2021
  16. jneira commented on Jan 12, 2021

    @jneira
    Member

    Afaik this applies to hls as well (and there are other issues very similar to this)
    Definitely we should add some section in the troubleshooting section.

  17. changed the title [-]hls fails with linker error due to missing libc symbols (with ghc linked dinamically)[/-] [+]hls fails with linker error due to missing symbols (with ghc linked dinamically)[/+] on Jan 12, 2021
  18. jneira commented on Jan 12, 2021

    @jneira
    Member

    As there is a newer issue with the workaround about the same problem (afaics) i am gonna close this one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    can-workaroundcomponent: ghcidetype: bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions