Files
nixpkgs/pkgs/development/compilers/ghc/subopt.bash
Emily fb5a523d14 haskell.compiler.ghc902Binary: bump LLVM by wrapping opt(1)
Implement a wrapper script to translate the `opt(1)` arguments passed
by the GHC 9.0.2 binary distribution to the equivalent arguments
for the new LLVM pass manager passed by GHC ≥ 9.10 and our
soon‐to‐be‐patched compilers. This ensures that the bootstrap
of GHC 9.4 continues to work on AArch64.

On an earlier version of this change, I built `haskell.compiler.ghc948`
on both `aarch64-linux` and `aarch64-darwin`, and
`haskell.compiler.ghc924` on `aarch64-linux` only (it is already
broken on Darwin). I confirmed that we get functionally identical
store outputs before and after this change, modulo self‐references:

    $ cp -a result-before/ before
    $ cp -a result-after/ after
    $ chmod -R +w before after
    $ LANG=C find before -type f -exec \
        remove-references-to \
        -t $(readlink result-before) \
        -t $(readlink result-before-doc) \
        '{}' ';'
    $ LANG=C find after -type f -exec \
        remove-references-to \
        -t $(readlink result-after) \
        -t $(readlink result-after-doc) \
        '{}' ';'
    # Darwin only: normalize build user UIDs in the archive files…
    $ LANG=C find before -name '*.a' -exec \
        sed -i 's/ 360 / 351 /g' '{}' ';'
    $ diff -r before after
    # Linux only: the `package.cache` files differ, presumably due to
    # an unrelated reproducibility issue.

Therefore, bumping this LLVM dependency did not affect the end result
of the bootstrap for the only compilers it is used for.
2025-09-07 19:07:56 +01:00

81 lines
2.1 KiB
Bash

#!@shell@
# This script wraps the LLVM `opt(1)` executable and maps the options
# passed by old versions of GHC to the equivalents passed by newer
# versions that support recent versions of LLVM.
#
# It achieves the same effect as the following GHC change externally:
# <https://gitlab.haskell.org/ghc/ghc/-/merge_requests/8999>.
#
# This is used solely for bootstrapping newer GHCs from the GHC 9.0.2
# binary on AArch64, as that is the only architecture supported by that
# binary distribution that requires LLVM, and our later binary packages
# all use the native code generator for all supported platforms.
#
# No attempt is made to support custom LLVM optimization flags, or the
# undocumented flag to disable TBAA, or avoid
# <https://gitlab.haskell.org/ghc/ghc/-/issues/23870>, as these are not
# required to bootstrap GHC and at worst will produce an error message.
#
# It is called `subopt` to reflect the fact that it uses `opt(1)` as a
# subprocess, and the fact that the GHC build system situation
# requiring this hack is suboptimal.
set -e
expect() {
if [[ $1 != $2 ]]; then
printf >&2 'subopt: got %q; expected %q\n' "$1" "$2"
return 2
fi
}
if [[ $NIX_DEBUG -ge 1 ]]; then
printf >&2 'subopt: before:'
printf >&2 ' %q' "$@"
printf >&2 '\n'
fi
args=()
while [[ $# -gt 0 ]]; do
case "$1" in
-enable-new-pm=0)
shift 1
;;
-mem2reg)
expect "$2" -globalopt
expect "$3" -lower-expect
expect "$4" -enable-tbaa
expect "$5" -tbaa
args+=('-passes=function(require<tbaa>),function(mem2reg),globalopt,function(lower-expect)')
shift 5
;;
-O1)
expect "$2" -globalopt
expect "$3" -enable-tbaa
expect "$4" -tbaa
args+=('-passes=default<O1>')
shift 4
;;
-O2)
expect "$2" -enable-tbaa
expect "$3" -tbaa
args+=('-passes=default<O2>')
shift 3
;;
*)
args+=("$1")
shift 1
;;
esac
done
if [[ $NIX_DEBUG -ge 1 ]]; then
printf >&2 'subopt: after:'
printf >&2 ' %q' "${args[@]}"
printf >&2 '\n'
fi
exec @opt@ "${args[@]}"