Skip to content

library not found when building with TemplateHaskell: add additional search -rpath to "@loader_path/" #8704

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

Closed
kencu opened this issue Jan 27, 2023 · 2 comments

Comments

@kencu
Copy link

kencu commented Jan 27, 2023

Describe the bug
When building unicode-collation, a linker error occurs:

[ 8 of 10] Compiling Text.Collate.Tailorings [Text.Collate.Collation changed]
ghc: panic! (the 'impossible' happened)
  (GHC version 8.10.4:
	Loading temp shared object failed: dlopen(/var/folders/I0/I0fOotq3ErGZHYxrmmWiqU+++TI/-Tmp-/ghc85250_0/libghc_43.dylib, 5): Library not loaded: @rpath/libghc_21.dylib
  Referenced from: /var/folders/I0/I0fOotq3ErGZHYxrmmWiqU+++TI/-Tmp-/ghc85250_0/libghc_43.dylib
  Reason: image not found

both ghc85250_0/libghc_43.dylib and ghc85250_0/libghc_43.dylib exist in the same folder, but ghc85250_0/libghc_43.dylib does not look in it's local directory for ghc85250_0/libghc_43.dylib.

I would like to add an rpath search path to '.' to allow the dylib to search it's local directory as well as the rpath search paths it is already using ... that appears to be managed in this function I believe:

https://github.com/ghc/ghc/blob/e902d771197fd93488938b5eacb1ad6f23d408b7/compiler/GHC/Linker/MacOS.hs#L53

however I am not sure of the Haskell code to use to do that, exactly.

I tried various flags for ghc, gcc, and cabal but I could not find a way to add this rpath entry to the generated dylib using a flag.

The build system is officially not supported -- macOS 10.6.8 using a very slightly modified ghc 8.10.4 (https://github.com/kencu/ghc-for-older-darwin-systems/releases/) with trivial patch for missing strnlen in 10.6.8's libSystem, cabal 3.8.1.0, with clang-11 as the compiler and ld64-450 as the linker. The dyld is stock 10.6.8. I have tried other ghc versions (9.2.5, for example) with the same outcome.

I realize the system is not officially supported, but there has been very solid success building with this toolchain until this linker error in this one dependency needed for pandoc, and we're hoping it might build.

link to original ticket report is here:

jgm/unicode-collation#13

Thanks for any consideration, and in particular perhaps for the bit of code I might use to add the rpath matching -Wl,-rpath,.

@kencu kencu changed the title TemplateHaskell: add -rpath to "." during link library not found when building with TemplateHaskell: add additional search -rpath to "." Jan 27, 2023
@kencu
Copy link
Author

kencu commented Feb 4, 2023

Ah, finally. Adding this to .cabal/config worked, after much trial and error:

 ghc-options: -optl-rpath -optl@loader_path/

@kencu kencu changed the title library not found when building with TemplateHaskell: add additional search -rpath to "." library not found when building with TemplateHaskell: add additional search -rpath to "@loader_path/" Feb 4, 2023
@alt-romes
Copy link
Collaborator

I've tried to reproduce this with cabal 3.10.1.0 and GHC 9.2.7 but it succeeded to compile without problems.

A lot of improvements have been made to dynamic linking (especially on macos) recently, so it is likely that this has been fixed in the meantime.

I'm going to close this optimistically, feel free to re-open if the issue re-surfaces. Thanks for posting the workaround too!

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