Skip to content

Commit 1ac3cd9

Browse files
committed
1 parent f5f4e8c commit 1ac3cd9

File tree

3 files changed

+86
-0
lines changed

3 files changed

+86
-0
lines changed

overlays/bootstrap.nix

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,12 @@ in {
346346

347347
++ onWasm (until "9.13" ./patches/ghc/ghc-9.12-wasm-shared-libs.patch)
348348
++ onWasm (until "9.13" ./patches/ghc/ghc-9.12-wasm-keep-cafs.patch)
349+
350+
# See https://github.com/IntersectMBO/plutus/issues/7415#issuecomment-3531989244
351+
++ fromUntil "9.6" "9.9" ./patches/ghc/ghc-profiling-fix.patch
352+
353+
# See https://gitlab.haskell.org/ghc/ghc/-/merge_requests/15096
354+
++ fromUntil "9.6" "9.13" ./patches/ghc/ghc-16bit-elf-section-header-overflow.patch
349355
;
350356
in ({
351357
ghc8107 = traceWarnOld "8.10" (final.callPackage ../compiler/ghc {
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
From e90e136c16ef10fc47d339cf8964255a5131c9c9 Mon Sep 17 00:00:00 2001
2+
From: Luite Stegeman <stegeman@gmail.com>
3+
Date: Sat, 22 Nov 2025 15:05:37 +0100
4+
Subject: [PATCH] rts: Handle 16-bit overflow of ELF section header string
5+
table
6+
7+
If the section header string table is stored in a section greater
8+
than 65535, the 16-bit value e_shstrndx in the ELF header does not
9+
contain the section number, but rather an overflow value SHN_XINDEX
10+
indicating that we need to look elsewhere.
11+
12+
This fixes the linker by not using e_shstrndx directly but calling
13+
elf_shstrndx, which correctly handles the overflow value.
14+
15+
Fixes #26603
16+
---
17+
rts/linker/Elf.c | 2 +-
18+
1 file changed, 1 insertion(+), 1 deletion(-)
19+
20+
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
21+
index 85a56c120d49..0314abb0c68c 100644
22+
--- a/rts/linker/Elf.c
23+
+++ b/rts/linker/Elf.c
24+
@@ -205,7 +205,7 @@ ocInit_ELF(ObjectCode * oc)
25+
oc->info->sectionHeader = (Elf_Shdr *) ((uint8_t*)oc->image
26+
+ oc->info->elfHeader->e_shoff);
27+
oc->info->sectionHeaderStrtab = (char*)((uint8_t*)oc->image +
28+
- oc->info->sectionHeader[oc->info->elfHeader->e_shstrndx].sh_offset);
29+
+ oc->info->sectionHeader[elf_shstrndx(oc->info->elfHeader)].sh_offset);
30+
31+
oc->n_sections = elf_shnum(oc->info->elfHeader);
32+
33+
--
34+
GitLab
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
diff --git a/compiler/GHC/Core/Utils.hs b/compiler/GHC/Core/Utils.hs
2+
index 0453fb93af..84d2d9cfe5 100644
3+
--- a/compiler/GHC/Core/Utils.hs
4+
+++ b/compiler/GHC/Core/Utils.hs
5+
@@ -79,7 +79,7 @@ import GHC.Core.Reduction
6+
import GHC.Core.TyCon
7+
import GHC.Core.Multiplicity
8+
9+
-import GHC.Builtin.Names ( makeStaticName, unsafeEqualityProofIdKey )
10+
+import GHC.Builtin.Names ( makeStaticName, unsafeEqualityProofIdKey, unsafeReflDataConKey )
11+
import GHC.Builtin.PrimOps
12+
13+
import GHC.Types.Var
14+
@@ -328,6 +328,10 @@ mkTick t orig_expr = mkTick' id id orig_expr
15+
-> CoreExpr
16+
mkTick' top rest expr = case expr of
17+
18+
+ Case scrut bndr ty alts@[Alt ac abs _rhs]
19+
+ | Just rhs <- isUnsafeEqualityCase scrut bndr alts
20+
+ -> top $ mkTick' (\e -> Case scrut bndr ty [Alt ac abs e]) rest rhs
21+
+
22+
-- Cost centre ticks should never be reordered relative to each
23+
-- other. Therefore we can stop whenever two collide.
24+
Tick t2 e
25+
@@ -2676,3 +2680,21 @@ isUnsafeEqualityProof e
26+
= v `hasKey` unsafeEqualityProofIdKey
27+
| otherwise
28+
= False
29+
+
30+
+isUnsafeEqualityCase :: CoreExpr -> Id -> [CoreAlt] -> Maybe CoreExpr
31+
+-- See (U3) and (U4) in
32+
+-- Note [Implementing unsafeCoerce] in base:Unsafe.Coerce
33+
+isUnsafeEqualityCase scrut bndr alts
34+
+ | [Alt ac _ rhs] <- alts
35+
+ , DataAlt dc <- ac
36+
+ , dc `hasKey` unsafeReflDataConKey
37+
+ , isDeadBinder bndr
38+
+ -- We can only discard the case if the case-binder is dead
39+
+ -- It usually is, but see #18227
40+
+ , Var v `App` _ `App` _ `App` _ <- scrut
41+
+ , v `hasKey` unsafeEqualityProofIdKey
42+
+ -- Check that the scrutinee really is unsafeEqualityProof
43+
+ -- and not, say, error
44+
+ = Just rhs
45+
+ | otherwise
46+
+ = Nothing

0 commit comments

Comments
 (0)