You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Cabal should probably add extra-lib-dirs to RPATH #7339
Describe the bug
In GHC #19350 it was noted that dynamic libraries findable via extra-lib-dirs are not found in GHCi on POSIX platforms. While in principle GHC has the information that it needs to find these libraries from the package database registration, due to limitations of the the POSIX dynamic linking interface, it is not possible for GHC to do better here.
I believe the solution here is to (on POSIX platforms) add Cabal's extra-lib-dirs paths to RPATH during the final link of libraries. This isn't a perfect solution (since it may result in spurious RPATH entries) but this seems to be the best we can do.
In #7094 we were essentially forced into placing more RPATH logic in GHC (specifically when targeting Darwin) since the patching we are forced to do in Darwin is rather involved. This was a pragmatic choice, but ultimately it was hack that meant conflating two distinct notions. Specifically, it means that GHC uses -L inconsistently with how other compilers treat that flag (since usually it merely affect the compile-time search path; in GHC it now also affects the run-time search behvaior).
To address GHC #19350 we could use a similar approach, teaching GHC to implicitly add -L directories to RPATH. However I think we should avoid this. -L and RPATH affect two distinct things; while on Darwin, due to the nature of the environment, we can conflate these, doing so on Linux would cause trouble for packagers (since you would almost certainly end up with redundant RPATH entries in some cases; e.g. when you are building a package in a temporary prefix for installation elsewhere). By keeping these two concepts distinct, GHC remains flexible enough to be usable in such cases.
In short, there is not appreciable interaction between #7094. #7094 is a pragmatic exception to the rule that -L and RPATH are orthogonal concerns. Here I am suggesting that the compiler continue considering them to be orthogonal but we add the policy logic for determining RPATH to Cabal.
Change extra-lib-dirs: directories to not generate -L flags, but -rpath ones? But on Darwin we won't as rpath support is not hasInstallNameTool, and then -rpath stuff is passed as -L anyway?
And to clarify. I'm just asking questions. I have no opinion on this, slightly worried that linking is becoming ad-hoc spagetti, but maybe it is just what it is.
Concretely, extra-lib-dirs should generate both -L flags and -rpath flags.
I'm not sure I agree, it should generate -L sure, but leave the rpath logic on darwin up to ghc. The whole idea that cabal takes care of rpathand ghc takes care of rpath is not very good. Ideally cabal would just delegate to hc, and hc would deal with the actual linking, let's not replicate linking logic in both.
I'm not sure I agree, it should generate -L sure, but leave the rpath logic on darwin up to ghc.
I don't believe that we are actually in disagreement. I agree that it is necessary for GHC to handle the invocation of the linker and post-processing of objects to realize the RUNPATH needed for a particular link.
However, I do not believe it is necessary for GHC to conflate static and runtime library search paths. Cabal currently uses GHC's -optl-Wl,-rpath and -L flags to precisely specify the compile-time and runtime library search paths needed for a particular install plan. From the perspective of Darwin (the issue fixed in #7094) this status quo is unfortunate since we do not benefit from the clever rpath handling introduced in ghc@4ff93292243888545da452ea4d4c1987f2343591.
However, this is not a fundamental issue: it can be easily avoided by introducing a -rpath flag in GHC's command-line interface, providing a reliable and precise way for the user to influence the runtime library search path. This would allow us to fix the issue pointed out in this ticket (that extra-lib-dirs don't make it into RPATH) while giving us a more robust way to address the Darwin issue addressed in #7094.
One question that remains is whether Cabal should make a distinction between compile-time and run-time library search paths. Arguably it should (e.g. by perhaps introducing extra-run-time-lib-dirs and extra-compile-time-lib-dirs fields in the .project syntax and LocalBuildInfo).
Activity
phadej commentedon Mar 21, 2021
How this interacts with change proposed in #7094
bgamari commentedon Mar 22, 2021
In #7094 we were essentially forced into placing more RPATH logic in GHC (specifically when targeting Darwin) since the patching we are forced to do in Darwin is rather involved. This was a pragmatic choice, but ultimately it was hack that meant conflating two distinct notions. Specifically, it means that GHC uses
-Linconsistently with how other compilers treat that flag (since usually it merely affect the compile-time search path; in GHC it now also affects the run-time search behvaior).To address GHC #19350 we could use a similar approach, teaching GHC to implicitly add
-Ldirectories toRPATH. However I think we should avoid this.-Land RPATH affect two distinct things; while on Darwin, due to the nature of the environment, we can conflate these, doing so on Linux would cause trouble for packagers (since you would almost certainly end up with redundant RPATH entries in some cases; e.g. when you are building a package in a temporary prefix for installation elsewhere). By keeping these two concepts distinct, GHC remains flexible enough to be usable in such cases.In short, there is not appreciable interaction between #7094. #7094 is a pragmatic exception to the rule that
-Land RPATH are orthogonal concerns. Here I am suggesting that the compiler continue considering them to be orthogonal but we add the policy logic for determining RPATH toCabal.phadej commentedon Mar 22, 2021
I don't understand what this issue suggests?
Change
extra-lib-dirs:directories to not generate-Lflags, but-rpathones? But on Darwin we won't as rpath support isnot hasInstallNameTool, and then-rpathstuff is passed as-Lanyway?bgamari commentedon Mar 22, 2021
Concretely,
extra-lib-dirsshould generate both-Lflags and-rpathflags.phadej commentedon Mar 22, 2021
I was also going to suggest
But you did it yourself.
phadej commentedon Mar 22, 2021
For the reference, as to me rpath is mystical thing: https://en.wikipedia.org/wiki/Rpath
phadej commentedon Mar 22, 2021
And to clarify. I'm just asking questions. I have no opinion on this, slightly worried that linking is becoming ad-hoc spagetti, but maybe it is just what it is.
bgamari commentedon Mar 22, 2021
Unfortunately it does tend to be quite platform specific. There was sadly a reason why
libtoolwas necessary for so many years.angerman commentedon Apr 29, 2021
I'm not sure I agree, it should generate
-Lsure, but leave therpathlogic on darwin up to ghc. The whole idea that cabal takes care ofrpathand ghc takes care ofrpathis not very good. Ideally cabal would just delegate tohc, andhcwould deal with the actual linking, let's not replicate linking logic in both.bgamari commentedon Jun 22, 2021
GHC #20026 is relevant here.
Mikolaj commentedon Jun 25, 2021
Also, #7382 seems related.
Mikolaj commentedon Jun 2, 2022
Please somebody with competence and a stake drive this issue. There is narrow window to get it into cabal 3.8.
bgamari commentedon Nov 14, 2023
I don't believe that we are actually in disagreement. I agree that it is necessary for GHC to handle the invocation of the linker and post-processing of objects to realize the RUNPATH needed for a particular link.
However, I do not believe it is necessary for GHC to conflate static and runtime library search paths. Cabal currently uses GHC's
-optl-Wl,-rpathand-Lflags to precisely specify the compile-time and runtime library search paths needed for a particular install plan. From the perspective of Darwin (the issue fixed in #7094) this status quo is unfortunate since we do not benefit from the clever rpath handling introduced in ghc@4ff93292243888545da452ea4d4c1987f2343591.However, this is not a fundamental issue: it can be easily avoided by introducing a
-rpathflag in GHC's command-line interface, providing a reliable and precise way for the user to influence the runtime library search path. This would allow us to fix the issue pointed out in this ticket (thatextra-lib-dirsdon't make it intoRPATH) while giving us a more robust way to address the Darwin issue addressed in #7094.One question that remains is whether Cabal should make a distinction between compile-time and run-time library search paths. Arguably it should (e.g. by perhaps introducing
extra-run-time-lib-dirsandextra-compile-time-lib-dirsfields in the.projectsyntax andLocalBuildInfo).A first fix for haskell#7339
Add extraLibDirs to runtime lib search paths of library
Add extraLibDirs to runtime lib search paths of library
Add extraLibDirs to runtime lib search paths of library
Add extraLibDirs to runtime lib search paths of library
Add extraLibDirs to runtime lib search paths of library
Add extraLibDirs to runtime lib search paths of library
Add extraLibDirs to runtime lib search paths of library
Add extraLibDirs to runtime lib search paths of library
Add extraLibDirs to runtime lib search paths of library
Add extraLibDirs to runtime lib search paths of library
Add extraLibDirs to runtime lib search paths of library