Skip to content

haskell.compiler.ghc{948,967,984,9102,9103,9121,9122}: backport patches for LLVM support#440774

Merged
sternenseemann merged 4 commits intoNixOS:stagingfrom
emilazy:push-xkqwxxymmwyt
Oct 18, 2025
Merged

haskell.compiler.ghc{948,967,984,9102,9103,9121,9122}: backport patches for LLVM support#440774
sternenseemann merged 4 commits intoNixOS:stagingfrom
emilazy:push-xkqwxxymmwyt

Conversation

@emilazy
Copy link
Member

@emilazy emilazy commented Sep 6, 2025

The rebuild‐heavy portion of #440271. Only the last commit is relevant here, and is all that this one will contain, once the previous PR is merged. See the commit message for details.

I have not built all of these GHCs again on top of the LLVM 20 bump; some amount of re‐verification would be appreciated.

Not sure whether this should target staging or haskell-updates; I’ll defer to @NixOS/haskell on that one.

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

@emilazy emilazy requested a review from a team September 6, 2025 21:21
@emilazy emilazy force-pushed the push-xkqwxxymmwyt branch 5 times, most recently from fde3479 to 7201db4 Compare September 6, 2025 21:47
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 6.topic: haskell General-purpose, statically typed, purely functional programming language labels Sep 6, 2025
@wolfgangwalther
Copy link
Contributor

Not sure whether this should target staging or haskell-updates; I’ll defer to @NixOS/haskell on that one.

My personal opinion: haskell-updates, I'm not worried about these being marked broken one staging cycle more or less.

@nixpkgs-ci nixpkgs-ci bot added the 2.status: merge conflict This PR has merge conflicts with the target branch label Sep 7, 2025
@emilazy
Copy link
Member Author

emilazy commented Sep 7, 2025

Gotcha. To be merged after the current haskell-updates lands, I assume?

@wolfgangwalther
Copy link
Contributor

I'd merge them as soon as we have another rebuild coming up. Either after it lands or before, if a hackage bump causes another rebuild (I think it has twice in a row now...).

@wolfgangwalther
Copy link
Contributor

haskell-updates now has all the drops in case you want to rebase.

@emilazy
Copy link
Member Author

emilazy commented Sep 7, 2025

I will rebase after it has #440273, since the LLVM bumps are moving there.

@sternenseemann
Copy link
Member

Would be nice to get this done now, we've unfortunately missed another staging-next iteration.

@wolfgangwalther
Copy link
Contributor

I think the idea was to wait for #444249. What's your idea on progressing with that first?

@sternenseemann
Copy link
Member

All I see is mention of #440273?!

@wolfgangwalther
Copy link
Contributor

We discussed this as part of the other PRs, without giving this an explicit PR-number-mention. The basic idea is simple: Drop GHCs first, then do the LLVM patches, because this requires far fewer GHC builds this way.

@wolfgangwalther
Copy link
Contributor

There is another one that would ideally be done before, that is #440976. I think we can do both of these and have a significantly simpler bootstrap story.

@wolfgangwalther
Copy link
Contributor

@emilazy you can rebase here now, the two drop PRs have been merged.

This string is not present in GHC 9.4.8’s `configure` script.
This matches the Hadrian build, and will be required for the LLVM
support backports.
`autoreconfHook` will handle the latter now.
@emilazy
Copy link
Member Author

emilazy commented Oct 13, 2025

Yep, doing so. Will run another round of tests too.

@emilazy emilazy changed the title haskell.compiler.ghc{948,963,967,984,9101,9102,9121,9122}: backport patches for LLVM support haskell.compiler.ghc{948,967,984,9102,9103,9121,9122}: backport patches for LLVM support Oct 14, 2025
@emilazy
Copy link
Member Author

emilazy commented Oct 14, 2025

Done. See the updated commit message for the details of the verification I did this time around. From my POV this should be good to go now.

@nixpkgs-ci nixpkgs-ci bot removed the 2.status: merge conflict This PR has merge conflicts with the target branch label Oct 14, 2025
…es for LLVM support

LLVM 12–17 have been dropped for Nixpkgs 25.11. As discussed recently
on Matrix, this backports upstream changes to allow the use of
LLVM 20 for all GHC versions from 9.4.8 onward.

I looked over GHC commits mentioning LLVM since the release of 9.4.8,
and read the discussions and issues around the relevant bumps, and
attempted to be quite thorough, but I obviously cannot guarantee that
this is wholly comprehensive. It seems like upstream generally bumps
the upper bound on the basis of “it builds successfully for me”,
with specific adaptations for new versions being fairly uncommon and
only coming for obvious build blockers or reactively in response to
bug reports. I have backported both kinds of changes here.

For some commits, trivial conflict resolutions and adaptations
were required. It would be possible to pass the affected files to
`fetchpatch` as `excludes` and keep smaller fix‐up patches in tree in
some cases, but I opted to keep it simple and vendor complete backport
patches instead. I did not attempt to backport every single change to
the LLVM backend, only those that seemed directly relevant to support
for newer versions; if you’d get the same issue with the older LLVM,
that’s just a GHC bug.

These changes should actually make it easier to cross‐compile for
new architectures, as more recent LLVMs will have better support for
newer platforms, and it will be easier to backport GHC changes to
enable new platforms with less drift in the backend.

These patches do result in two breaking changes. Firstly, the minimum
LLVM version is bumped to 13 across the board. This is irrelevant for
Nixpkgs as we pin a specific LLVM version anyway, and versions below
LLVM 18 will be removed imminently. Secondly, support for the hidden
`-fno-llvm-tbaa` flag is dropped. This can be replaced with custom
`-optlo` flags to control the passes more directly, but the main
use of this undocumented flag appears to have been to [work around]
the lack of support for newer LLVM versions, anyway.

[work around]: <https://gitlab.haskell.org/ghc/ghc/-/issues/22220>

I successfully built the following on `aarch64-linux`:

* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc948`
* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc967`
* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc984`
* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc9102`
* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc9121`
* `pkgsCross.armv7l-hf-multiplatform.buildPackages.haskell.compiler.ghc9122`
* `pkgsCross.riscv64.haskell.compiler.ghc948`

The GHC 9.4.8 with an ARMv7 host platform segfaults when I try to run
GHC, though e.g. `ghc-pkg --help` runs successfully. The GHC 9.10.3
build targeting ARMv7 crashed inside `llc(1)`, so I tried RISC‐V,
which has some platform mismatch issue relating to `libffi`, so I
tried z/Architecture, which failed with an invalid floating point
constant in the LLVM IR, so I tried 64‐bit MIPS, which failed with
a different `libffi` issue, so I tried 32‐bit MIPS, which failed
to compile `compiler-rt`, so I gave up. I confirmed that both of the
ARMv7 issues reproduce with 944e8fd,
the revision before they were bumped from their old versions of LLVM,
so these are not regressions.

I built a test program with the ARMv7 cross‐compilers and
confirmed that they run on the AArch64 builder. I also confirmed
that the cross‐compiled RISC‐V GHC successfully runs under
`qemu-riscv64(1)`. It will only try to build programs via the C
backend, though, as that is the only option for unregisterised™
targets, so it’s not clear to me how useful LLVM support in 9.4.8
really is for bootstrapping new platforms; I guess even RISC‐V
would require more backporting work to produce a cross‐compiled
GHC that will use LLVM to compile its own input. I didn’t bother
setting up all the binfmt machinery to get it through compiling and
running a test program, but it at least makes the attempt.
Copy link
Contributor

@wolfgangwalther wolfgangwalther left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not check all the patches themselves.

IIRC, @sternenseemann you already did that in the original PR, is that right? Do you want to have another look?

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 1 This PR was reviewed and approved by one person. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages. labels Oct 16, 2025
Copy link
Member

@sternenseemann sternenseemann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be in order. Assuming I did review this properly before, I diffed this PR's diff with 24abdec...5c5a469 which I reviewed before (I don't think GitHub (nor git?) offers better tooling for this, really.)

(
# The upstream backport of !13763 in 9.6.7 removed an unused import
# that is required by the next series.
if lib.versionOlder version "9.6" then null else ./ghc-9.6-llvm-restore-import.patch
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This versionOlder could be floated in the condition above like it used to be?!

Copy link
Member Author

@emilazy emilazy Oct 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I switched it because this was the only lib.optionals with a dual condition – everything else is just a plain “version is older” – and we have some existing if lib.versionOlder … then … else … cases, including another one with null, so this seemed more consistent. But I’m ambivalent.

@nixpkgs-ci nixpkgs-ci bot added 12.approvals: 2 This PR was reviewed and approved by two persons. and removed 12.approvals: 1 This PR was reviewed and approved by one person. labels Oct 18, 2025
@emilazy
Copy link
Member Author

emilazy commented Oct 18, 2025

nor git?

git range-diff may be what you are looking for.

@sternenseemann sternenseemann added this pull request to the merge queue Oct 18, 2025
Merged via the queue into NixOS:staging with commit 3bd7971 Oct 18, 2025
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: haskell General-purpose, statically typed, purely functional programming language 10.rebuild-darwin: 501+ This PR causes many rebuilds on Darwin and should normally target the staging branches. 10.rebuild-darwin: 5001+ This PR causes many rebuilds on Darwin and must target the staging branches. 10.rebuild-linux: 501+ This PR causes many rebuilds on Linux and should normally target the staging branches. 10.rebuild-linux: 5001+ This PR causes many rebuilds on Linux and must target the staging branches. 12.approvals: 2 This PR was reviewed and approved by two persons. 12.approved-by: package-maintainer This PR was reviewed and approved by a maintainer listed in any of the changed packages.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants