Inconsistent use of `ld-options`
- Dominant language
- Haskell
- Stars
- 1.7k
- Forks
- 750
- Avg merge
- 4d 3h
- Merged PRs (30d)
- 28
Description
**Describe the bug**
I like having these in my cabal config to suppress some warnings:
```
gcc-options: -Wl,--allow-multiple-definition
ld-options: -Wl,--allow-multiple-definition
```
This produces (silenced by default) errors on cabal build:
```
$ cabal build -v3 | grep allow
...
Running: "C:\ghcup\ghc\9.6.6\lib\../mingw/bin\ld.lld.exe" "--help" "-Wl,--allow-multiple-definition"
lld: error: unknown argument: -Wl,--allow-multiple-definition
...
➜ $(cygpath -m 'C:\ghcup\ghc\9.6.6\lib\../mingw/bin\ld.lld.exe') --help | grep allow
--allow-multiple-definition
...
```
The output seems to indicate we should remove the `-Wl,` from `ld-options`. However, if done so we get a different error in another command:
```
➜ cabal repl -v3 | grep -v "with environment"
...
Running: "C:\ghcup\bin\ghc.exe" "--interactive" "-fbuilding-cabal-package" "-O0" "-outputdir" "dist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build" "-odir" "dist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build" "-hidir" "dist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build" "-hiedir" "dist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build\extra-compilation-artifacts\hie" "-stubdir" "dist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build" "-i" "-i." "-idist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build" "-idist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build\autogen" "-idist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build\global-autogen" "-Idist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build\autogen" "-Idist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build\global-autogen" "-Idist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build" "-optP-include" "-optPdist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\build\autogen\cabal_macros.h" "-optl--allow-multiple-definition" "-this-unit-id" "fake-package-0-inplace" "-hide-all-packages" "-Wmissing-home-modules" "-no-user-package-db" "-package-db" "C:\Users\Javier\AppData\Local\cabal\store\ghc-9.6.6\package.db" "-package-db" "C:\msys64\tmp\cabal-repl.-23488\dist-newstyle\packagedb\ghc-9.6.6" "-package-db" "dist-newstyle\build\x86_64-windows\ghc-9.6.6\fake-package-0\package.conf.inplace" "-package-id" "base-4.18.2.1" "-XHaskell2010" "-ghci-scriptC:\msys64\tmp\cabal-repl.-23488\setcwd.ghci" "-hide-all-packages"
with working directory: "C:\\msys64\\tmp\\cabal-repl.-23488"
GHCi, version 9.6.6: https://www.haskell.org/ghc/ :? for help
clang: error: unsupported option '--allow-multiple-definition'
`clang.exe' failed in phase `gcc'. (Exit code: 1)
C:\ghcup\bin\ghc.exe returned ExitFailure 1
C:\ghcup\bin\cabal-3.15.0.0.exe returned ExitFailure 1
...
```
Notice how ld-options are passed as `-optl` flags to GHC which gives them to `clang`, but previously we were passing them to `lld` ourselves.
For my case this is not particularly important because the `lld` errors in the first case won't change depending on this flag, as my `lld` does not support `-x` but for users whose `lld` does support `-x`, if they specify `ld-options` with `-Wl`, the command will fail and Cabal will think that `-x` is not supported.
Cabal used: 3.14
Contributor guide
Assessment
This issue has not been assessed yet.