Conversation
92bb632 to
247d563
Compare
Previously Cabal would rely on its own object-merge logic to produce GHCi libraries. This was not ideal as it meant that this logic was replicated in both GHC and Cabal. Moreover, Cabal's implementation historically hasn't handled the more subtle aspects of interacting with the linker, resulting in issues like haskell#7828. In GHC 7.4 we have introduced a new compiler mode, `--merge-objs`, which exposes GHC's object merging mechanism. Here we teach Cabal to take advantage of this mechanism when it is available.
247d563 to
280faa9
Compare
|
@bgamari I am currently working on something similar. How does your solution work with a version of GHC, < From reading the code, I ask because in CI jobs it is common for people to run a bunch of compilers with a single (latest) version of |
|
For context: recently we also had #9220 which wanted to restore being able to use That PR wouldn't fly by itself but #9229 added the appropriate feature detection to I admit my ignorance on the topic but I am bit confused. #8071 was submitted to support GHC 9.4's new Windows toolchain, but it disabled ghci libs because Can ghc merge object files on Windows too? I feel we need a coherent picture. |
|
As @andreabedini highlighted, we do need merged objects for the linker performance on windows. We also do not use |
In Haskell we use object merging for two different purposes:
Since GHC requires (1), we implemented object merging on Windows by simply building a static archive of the merged objects. This can be passed to the linker just as a merged object resulting from Furthermore, even if we had the ability to use
GHC's merge-object mode will work on any platform for which the toolchain supports object merging. However, LLD on Windows (which is the only configuration we can support) does not support object merging. I would strongly recommend against using
However, I think @angerman and I agree that object merging logic should be in GHC, not Cabal, and I would be fine with allowing Cabal to use
|
|
@bgamari I still disagree that
From my observations, loading pre-linked object files into the linker is significantly faster than loading the archives. If we had proper dynamic lining on windows this would look quite differently. |
|
@bgamari can you share a link for
Also of note: as usual, I'm primarily focused on cross compilation, not that much on compilation on windows; but for. |
|
Also in light of #9301, do we have a consensus on how to proceed on this? In general terms I belive cabal should ask GHC do to what the user wants to do and it is up to GHC to warn or error when it cannot do what it is asked. |
|
@angerman, one example is |
|
@bgamari which only happens for >4GB images? MSYS2 mingw64 and even ucrt64 environments still use the gnu toolchain. Only the clang64 env uses the llvm toolchain. So msys still seems to consider the gcc toolchain to be good enough. In any case, my view is that these features should be gated by feature availability, and not by proxy. If we have a gcc toolchain GHC we can have merge objects. If not, we can't. And as it stands we can still build GHC with a different toolchain even if that's not the one we officially ship with the binary distributions. Therefor if $ld supports -r, we should support --merge-objects if the user requests. |
No, it occurs for images mapped above >4GB, which is now the default.
Sure, I don't disagree. I would simply advise caution relying on the gnu toolchain for PE targets. There are good reasons why GHC moved away from it. |
|
Cross-reference: #12333 is fixing the |
Cabal used to run ld -r itself to merge a library's object files into the
GHCi object, finding ld from the ghc settings and probing it for -r and -x
support. When ghc supports --merge-objs, delegate the merging to it: GHC
uses the merge tool and flags it was configured with, deals with long
argument lists, and its choice is by construction the one GHCi can load.
Whether a GHCi library can be built at all is then decided by whether GHC
has a merge tool configured ("Merge objects command" in the settings)
instead of by probing ld --help. The ld -r path is kept for GHCs without
--merge-objs.
This revives haskell#9226 with feature detection instead of a version gate.
Refs haskell#7828, haskell#9301, haskell#12332.
We used to run `ld -r` ourselves, finding ld from the ghc settings and probing it for -r and -x. When ghc has --merge-objs, let it do the merging: it uses the tool and flags it was configured with and handles long argument lists. Whether a GHCi library can be built at all then follows from "Merge objects command" being set, not from probing `ld --help`. GHCs without --merge-objs keep the ld path. Revives haskell#9226 with feature detection instead of a version gate. Refs haskell#7828, haskell#9301, haskell#12332. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
We used to run `ld -r` ourselves, finding ld from the ghc settings and probing it for -r and -x. When ghc has --merge-objs, let it do the merging: it uses the tool and flags it was configured with and handles long argument lists. Whether a GHCi library can be built at all then follows from "Merge objects command" being set, not from probing `ld --help`. GHCs without --merge-objs keep the ld path. Revives haskell#9226 with feature detection instead of a version gate. Refs haskell#7828, haskell#9301, haskell#12332. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
|
I revived this PR as #12358 |
We used to run `ld -r` ourselves, finding ld from the ghc settings and probing it for -r and -x. When ghc has --merge-objs, let it do the merging: it uses the tool and flags it was configured with and handles long argument lists. Whether a GHCi library can be built at all then follows from "Merge objects command" being set, not from probing `ld --help`. GHCs without --merge-objs keep the ld path. Revives haskell#9226 with feature detection instead of a version gate. Refs haskell#7828, haskell#9301, haskell#12332. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
We used to run `ld -r` ourselves, finding ld from the ghc settings and probing it for -r and -x. When ghc has --merge-objs, let it do the merging: it uses the tool and flags it was configured with and handles long argument lists. Whether a GHCi library can be built at all then follows from "Merge objects command" being set, not from probing `ld --help`. GHCs without --merge-objs keep the ld path. Revives haskell#9226 with feature detection instead of a version gate. Refs haskell#7828, haskell#9301, haskell#12332. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Previously Cabal would rely on its own object-merge logic to produce
GHCi libraries. This was not ideal as it meant that this logic was
replicated in both GHC and Cabal. Moreover, Cabal's implementation
historically hasn't handled the more subtle aspects of interacting with
the linker, resulting in issues like #7828.
In GHC 9.4 we have introduced a new compiler mode,
--merge-objs, whichexposes GHC's object merging mechanism. Here we teach Cabal to take
advantage of this mechanism when it is available. This ensures that the
platform-dependent process of object merging remains squarely in GHC's
court, preventing issues like #7828.
This is a rebase of #7960, which we previously decided not to merge as GHC
was able to find another way around the proximate problem. However, in light
of recent issues turned up by GHC's
ghc-toolchainwork, I think we should againconsider merging this for GHC 9.10.