GHC driver inadequately reverses C/C++ compiler flag order from settings file
Context: I tried to add -Xclang -target-abi -Xclang experimental-mv
to CONF_CC_OPTS_STAGE2
when doing a GHC build targeting wasm32
, and these flags do end up correctly in the settings
file, and the GHC driver is supposed to pass them to clang
. However, rts
would fail to configure with: clang: error: no such file or directory: 'experimental-mv'
. So I took a look at the process creation logs and discovered that, wasm32-wasi-ghc
would actually pass "experimental-mv","-Xclang","-target-abi","-Xclang"
to clang
!
The culprit seems to be https://gitlab.haskell.org/ghc/ghc/-/blob/master/compiler/GHC/SysTools/Tasks.hs?ref_type=heads#L178. getOpts
would actually reverse opt_c
, which contains a mixture of C compiler flags parsed from settings
and also from -optc
. So the whole thing works when the C compiler flags in settings
happen to be commutative, but this assumption does not always hold.
This looks like a bug worth fixing for me. The C/C++ compiler flag order from settings
should be preserved, a simple reversal is a bad way to ensure user supplied -optc
flags override the default flags.