The ghc-options are not passed to the linker
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
While fixing a bug that turned out to be another case of #7339, I realized that the `ghc-options` field is not being passed to a linker invocation of `ghc` after having compiled the haskell modules and extra build sources (see `buildOrReplLib`).
You can see that the linker options e.g. start from `mempty` instead of `baseOpts` (where `baseOpts` has already added to `ghcOptExtra` the `ghc-options` specified in the cabal file or flags). This happens for `ghcSharedOpts`, however, the `ghcOptExtra` seems to be added in that case. I haven't further diagnosed.
```diff
linkerOpts =
+ -- (Shouldn't this be `baseOpts` as well? If not,
+ -- then ghcOptsExtra is not being considered in the linker invocation.)
- mempty
+ baseOpts
{ ghcOptLinkOptions =
PD.ldOptions libBi
++ [ "-static"
| withFullyStaticExe lbi
```
The initial attempted fix (that turned out to be fixed by the patch that fixed #7339) was to add
```
ghc-options: -optc-Wl,-rpath,/path...
```
which did not work because, even though it gets passed to the `ghc --make` invocation that compiles haskell modules, it does not get passed on to the linker invocation that links them together.
Contributor guide
Research direction
Start in buildOrReplLib and compare the linkerOpts initialization with ghcSharedOpts, particularly the use of mempty versus baseOpts and how ghcOptExtra is added. Reproduce the case with a ghc-options linker flag such as -optc-Wl,-rpath,/path; done means the flag reaches the linker invocation after the Haskell modules and extra build sources are compiled.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- haskell
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100