From 11ff61c1ba94f8cd0ec05ee3b100a25b5470577a Mon Sep 17 00:00:00 2001 From: tegwick Date: Sat, 2 May 2026 11:11:07 +0200 Subject: [PATCH] fix(build): route TH to ghc-iserv-dyn to bypass truncated libHSghc.a MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Root cause: libHSghc-9.10.3-5702.a (287,768,576 bytes) has its last AR entry (Expr.o) claiming 517,544 bytes but only 82,258 bytes remain — the archive is truncated. GHC's internal readAr (Data.Binary.Get) panics at position 287,686,318 when it tries to read the full claimed size. The truncated .a is read lazily: IHP's TH splices queue a dependency on the ghc package, which flushes to readAr after all 477 modules compile. This explains the invariant crash at [477 of 477] WidgetVersionInclude. ghc-iserv-dyn is not exposed in ghc-with-packages/bin/ (why -fexternal-interpreter alone silently fell back to the internal linker). Use -pgmi with the absolute path in the unwrapped GHC store to force iserv-dyn, which uses dlopen on libHSghc.so (intact, 110 MB) instead of readAr on the truncated .a. No crash. Co-Authored-By: Claude Sonnet 4.6 --- flake.nix | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/flake.nix b/flake.nix index eabd9e7..0961922 100644 --- a/flake.nix +++ b/flake.nix @@ -127,6 +127,18 @@ "--disable-split-sections" "--ghc-option=-j1" "--disable-shared" + # GHC 9.10.3 bug: libHSghc-9.10.3-5702.a is truncated (last AR + # entry Expr.o claims 517544 bytes but only 82258 remain). + # GHC's internal static linker (readAr via Data.Binary.Get) panics + # after all 477 modules compile when it flushes deferred symbol + # loads from IHP's TH splices that transitively need the ghc pkg. + # Fix: delegate TH evaluation to ghc-iserv-dyn, which uses dlopen + # on libHSghc.so (intact) instead of readAr on the truncated .a. + # ghc-iserv-dyn is not in ghc-with-packages/bin/, so use -pgmi + # with the absolute path in the unwrapped GHC store path. + "--ghc-option=-fexternal-interpreter" + "--ghc-option=-pgmi" + "--ghc-option=${hprev.ghc}/lib/ghc-9.10.3/bin/ghc-iserv-dyn" ]; postUnpack = (old.postUnpack or "") + '' _actual="$sourceRoot/build/Generated/ActualTypes.hs"