Configurable/overridable settings file
Motivation
I'm reopening #15319 (closed) in a new issue. The original motivation was overriding the GCC used by GHC is hard because GHC used to autodetect flags to pass to the linker during installation but those flags didn't always work with an arbitrary different GCC. The fix was to simply ignore the flags defined in the settings file when GCC is overridden. But it turns out that this causes other problems.
On recent Linux distributions, -pie
is implied when linking dynamic executables. GHC would rather it not be, so it explicitly passes -no-pie
. As a side effect of 8d008b71, and as noted in #17919 (closed), GHC no longer passes -no-pie
when GCC is overridden using -pgmc
. The workaround proposed there is to simply pass -optl-no-pie
explicitly, in addition to -pgmc
. However, while this works for binaries, this does not work for libraries, since -no-pie
to the linker seems to confuse the linker into thinking we actually want a binary.
This one change has caused a number of issues for rules_haskell users. See e.g. https://github.com/tweag/rules_haskell/issues/1418, https://github.com/tweag/rules_haskell/issues/1401, https://github.com/tweag/rules_haskell/issues/1413, https://github.com/tweag/rules_haskell/issues/1327. We eventually implemented a workaround in https://github.com/tweag/rules_haskell/pull/1424, which has to specifically detect whether GHC >= 8.10 or not. It's all quite the hack, it was hard to get exactly right, and all these problems would go away if we simply had a way to describe the C compiler at the same time as we are overriding it.
Proposal
Like #15319 (closed) originally proposed, it would be nice to be able to override the settings file on the command-line, e.g. have -settings <path/to/settings>
. This should be used whenever -pgmc
is also used.