Skip to content

Commit 754ffaf

Browse files
committed
Add more 9.6 patches 🤦
1 parent b98a468 commit 754ffaf

7 files changed

+674
-0
lines changed

overlays/bootstrap.nix

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,13 @@ in {
284284
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.9" && (final.stdenv.targetPlatform.isAndroid && final.stdenv.targetPlatform.is32bit || final.stdenv.targetPlatform.isMusl)) ./patches/ghc/ghc-9.6-missing-symbols-deadbeef.patch
285285
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.9" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-linker-pool-allocator.patch
286286
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.9" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-linker-pool-allocator-2.patch
287+
288+
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.9" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-0001-Refactor-IServ.hs.patch
289+
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.9" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-0002-Drop-spurious-8-byte-offset-from-elf_plt.patch
290+
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.9" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-0003-Better-pool-alignment.-We-still-hardcode-section-ali.patch
291+
# these two are abit questionable. They are pretty rough, and assume static binary as well as posix.
292+
# ++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.9" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-0004-ghcidladdr.patch
293+
# ++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.9" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-0005-Better-interpreter-debugging.-Needs-ghcidladdr.patch
287294
# These two patches are needed for libblst, which has now hidden symbols, which the linker doesn't know how to deal with.
288295
++ final.lib.optional (versionAtLeast "8.10" && versionLessThan "8.11") ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols.patch
289296
++ final.lib.optional (versionAtLeast "8.10" && versionLessThan "8.11") ./patches/ghc/ghc-8.10-0006-Adds-support-for-Hidden-symbols-2.patch
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
1+
diff --git a/rts/linker/InitFini.c b/rts/linker/InitFini.c
2+
index 6c787fe552..bdb134b274 100644
3+
--- a/rts/linker/InitFini.c
4+
+++ b/rts/linker/InitFini.c
5+
@@ -103,55 +103,82 @@ void freeInitFiniList(struct InitFiniList *slist)
6+
7+
static bool runInitFini(struct InitFiniList **head)
8+
{
9+
+ IF_DEBUG(linker, debugBelch ("runInitFini on %p; sorting...\n", head));
10+
int argc, envc;
11+
char **argv, **envv;
12+
13+
+ IF_DEBUG(linker, debugBelch ("runInitFini gettingProgArgv...\n"));
14+
getProgArgv(&argc, &argv);
15+
getProgEnvv(&envc, &envv);
16+
17+
+ IF_DEBUG(linker, debugBelch ("runInitFini iterating over the list...\n"));
18+
for (struct InitFiniList *slist = *head;
19+
slist != NULL;
20+
slist = slist->next)
21+
{
22+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini getting section...\n"));
23+
Section *section = slist->section;
24+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini getting section...\n"));
25+
switch (slist->kind) {
26+
case INITFINI_INIT: {
27+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini INIT...\n"));
28+
init_t *init = (init_t*)section->start;
29+
(*init)(argc, argv, envv);
30+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini INIT...done\n"));
31+
break;
32+
}
33+
case INITFINI_FINI: {
34+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini FINI...\n"));
35+
fini_t *fini = (fini_t*)section->start;
36+
(*fini)();
37+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini FINI...done\n"));
38+
break;
39+
}
40+
case INITFINI_CTORS: {
41+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini CTORS...\n"));
42+
uint8_t *init_startC = section->start;
43+
init_t *init_start = (init_t*)init_startC;
44+
init_t *init_end = (init_t*)(init_startC + section->size);
45+
46+
// ctors are run *backwards*!
47+
for (init_t *init = init_end - 1; init >= init_start; init--) {
48+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini CTORS init...\n"));
49+
if ((intptr_t) *init == 0x0 || (intptr_t)*init == -1) {
50+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini CTORS init is ignored...\n"));
51+
continue;
52+
}
53+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini CTORS running init=%p, *init=%p, **init=%p...\n", init, *init, **init));
54+
+ IF_DEBUG(linker, {
55+
+ unsigned char* p = (unsigned char*)(*init);
56+
+ for(size_t i = 0; i < 128; i++)
57+
+ { printf("%02x ", p[i]); if ((i + 1) % 16 == 0) { printf("\n"); }}
58+
+ });
59+
(*init)(argc, argv, envv);
60+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini CTORS running init done\n"));
61+
}
62+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini CTORS...done\n"));
63+
break;
64+
}
65+
case INITFINI_DTORS: {
66+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini DTORS...\n"));
67+
char *fini_startC = section->start;
68+
fini_t *fini_start = (fini_t*)fini_startC;
69+
fini_t *fini_end = (fini_t*)(fini_startC + section->size);
70+
for (fini_t *fini = fini_start; fini < fini_end; fini++) {
71+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini DTORS init...\n"));
72+
if ((intptr_t) *fini == 0x0 || (intptr_t) *fini == -1) {
73+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini DTORS init is ignored...\n"));
74+
continue;
75+
}
76+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini DTORS running init...\n"));
77+
(*fini)();
78+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini DTORS running init done\n"));
79+
}
80+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini DTORS...done\n"));
81+
break;
82+
}
83+
case INITFINI_INIT_ARRAY: {
84+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini INIT_ARRAY...\n"));
85+
char *init_startC = section->start;
86+
init_t *init_start = (init_t*)init_startC;
87+
init_t *init_end = (init_t*)(init_startC + section->size);
88+
@@ -159,9 +186,11 @@ static bool runInitFini(struct InitFiniList **head)
89+
CHECK(0x0 != *init);
90+
(*init)(argc, argv, envv);
91+
}
92+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini INIT_ARRAY...done\n"));
93+
break;
94+
}
95+
case INITFINI_FINI_ARRAY: {
96+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini FINI_ARRAY...\n"));
97+
char *fini_startC = section->start;
98+
fini_t *fini_start = (fini_t*)fini_startC;
99+
fini_t *fini_end = (fini_t*)(fini_startC + section->size);
100+
@@ -170,15 +199,19 @@ static bool runInitFini(struct InitFiniList **head)
101+
CHECK(0x0 != *fini);
102+
(*fini)();
103+
}
104+
+ IF_DEBUG(linker, debugBelch ("\trunInitFini FINI_ARRAY...done\n"));
105+
break;
106+
}
107+
default: barf("unknown InitFiniKind");
108+
}
109+
}
110+
+ IF_DEBUG(linker, debugBelch ("runInitFini freeingInitFiniList...\n"));
111+
freeInitFiniList(*head);
112+
*head = NULL;
113+
114+
+ IF_DEBUG(linker, debugBelch ("runInitFini freeingProgEnvv...\n"));
115+
freeProgEnvv(envc, envv);
116+
+ IF_DEBUG(linker, debugBelch ("runInitFini done\n"));
117+
return true;
118+
}
119+
120+
@@ -187,6 +220,7 @@ static bool runInitFini(struct InitFiniList **head)
121+
// See Note [Initializers and finalizers (PEi386/ELF)].
122+
bool runInit(struct InitFiniList **head)
123+
{
124+
+ IF_DEBUG(linker, debugBelch ("runInit on %p; sorting...\n", head));
125+
sortInitFiniList(head, INCREASING);
126+
return runInitFini(head);
127+
}
128+
diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c
129+
index c30957b750..6739e161c1 100644
130+
--- a/rts/linker/PEi386.c
131+
+++ b/rts/linker/PEi386.c
132+
@@ -2278,20 +2278,58 @@ ocResolve_PEi386 ( ObjectCode* oc )
133+
them using RtlDeleteFunctionTable.
134+
*/
135+
136+
+void dump_memory(unsigned char* pc) {
137+
+ printf("PC: %p\n", pc);
138+
+
139+
+ // Print 32 bytes before PC
140+
+ for (int i = 0; i < 64; i++) {
141+
+ if (i % 16 == 0) {
142+
+ if(i>0) printf("\n");
143+
+ printf("%p: ", pc-32+i);
144+
+ }
145+
+ printf("%02x ", pc[i-32]);
146+
+ }
147+
+ printf("\n");
148+
+}
149+
+
150+
+__attribute__((noreturn))
151+
+EXCEPTION_DISPOSITION
152+
+_except_handler(struct _EXCEPTION_RECORD* ExceptionRecord,
153+
+ void* EstablisherFrame,
154+
+ struct _CONTEXT* ContextRecord,
155+
+ void* DispatcherContext)
156+
+{
157+
+ unsigned char* pc = (unsigned char*)ContextRecord->Rip;
158+
+
159+
+ dump_memory(pc);
160+
+
161+
+ exit(1); // Exit the program after handling the exception
162+
+}
163+
+
164+
bool
165+
ocRunInit_PEi386 ( ObjectCode *oc )
166+
{
167+
- if (oc && oc->info && oc->info->init) {
168+
- return runInit(&oc->info->init);
169+
+ __try1(_except_handler) {
170+
+ if (oc && oc->info && oc->info->init) {
171+
+ IF_DEBUG(linker, debugBelch ("runInit for %" PATH_FMT "...\n", oc->fileName));
172+
+ return runInit(&oc->info->init);
173+
+ IF_DEBUG(linker, debugBelch ("...done\n"));
174+
+ }
175+
}
176+
+ __except1;
177+
return true;
178+
}
179+
180+
bool ocRunFini_PEi386( ObjectCode *oc )
181+
{
182+
- if (oc && oc->info && oc->info->fini) {
183+
- return runFini(&oc->info->fini);
184+
+ // __try1(_except_handler) {
185+
+ if (oc && oc->info && oc->info->fini) {
186+
+ IF_DEBUG(linker, debugBelch ("runFini for %" PATH_FMT "...\n", oc->fileName));
187+
+ return runFini(&oc->info->fini);
188+
+ IF_DEBUG(linker, debugBelch ("...done\n"));
189+
+ //}
190+
}
191+
+ // __except1;
192+
return true;
193+
}
194+
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
From 45624fed757dea6ad1e2dbc6840603092da5359a Mon Sep 17 00:00:00 2001
2+
From: Moritz Angermann <[email protected]>
3+
Date: Wed, 21 Feb 2024 02:56:21 +0000
4+
Subject: [PATCH 1/5] Refactor IServ.hs
5+
6+
---
7+
libraries/libiserv/src/IServ.hs | 12 ++++++------
8+
1 file changed, 6 insertions(+), 6 deletions(-)
9+
10+
diff --git a/libraries/libiserv/src/IServ.hs b/libraries/libiserv/src/IServ.hs
11+
index 6361a8c..7a4bd95 100644
12+
--- a/libraries/libiserv/src/IServ.hs
13+
+++ b/libraries/libiserv/src/IServ.hs
14+
@@ -30,8 +30,8 @@ serv verbose hook pipe restore = loop
15+
when verbose $ trace ("msg: " ++ (show msg))
16+
case msg of
17+
Shutdown -> return ()
18+
- RunTH st q ty loc -> wrapRunTH $ runTH pipe st q ty loc
19+
- RunModFinalizers st qrefs -> wrapRunTH $ runModFinalizerRefs pipe st qrefs
20+
+ RunTH st q ty loc -> wrapRunTH (runTH pipe st q ty loc) >>= reply
21+
+ RunModFinalizers st qrefs -> wrapRunTH (runModFinalizerRefs pipe st qrefs) >>= reply
22+
_other -> run msg >>= reply
23+
24+
reply :: forall a. (Binary a, Show a) => a -> IO ()
25+
@@ -44,7 +44,7 @@ serv verbose hook pipe restore = loop
26+
-- THMessage requests, and then finally send RunTHDone followed by a
27+
-- QResult. For an overview of how TH works with Remote GHCi, see
28+
-- Note [Remote Template Haskell] in libraries/ghci/GHCi/TH.hs.
29+
- wrapRunTH :: forall a. (Binary a, Show a) => IO a -> IO ()
30+
+ wrapRunTH :: forall a. (Binary a, Show a) => IO a -> IO (QResult a)
31+
wrapRunTH io = do
32+
when verbose $ trace "wrapRunTH..."
33+
r <- try io
34+
@@ -55,14 +55,14 @@ serv verbose hook pipe restore = loop
35+
Left e
36+
| Just (GHCiQException _ err) <- fromException e -> do
37+
when verbose $ trace ("QFail " ++ show err)
38+
- reply (QFail err :: QResult a)
39+
+ return (QFail err :: QResult a)
40+
| otherwise -> do
41+
str <- showException e
42+
when verbose $ trace ("QException " ++ str)
43+
- reply (QException str :: QResult a)
44+
+ return (QException str :: QResult a)
45+
Right a -> do
46+
when verbose $ trace "QDone"
47+
- reply (QDone a)
48+
+ return (QDone a)
49+
50+
-- carefully when showing an exception, there might be other exceptions
51+
-- lurking inside it. If so, we return the inner exception instead.
52+
--
53+
2.33.0
54+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
From e3bf7ebed5a6a1ea00408ca42b4090e056bbbe5a Mon Sep 17 00:00:00 2001
2+
From: Moritz Angermann <[email protected]>
3+
Date: Wed, 21 Feb 2024 03:05:11 +0000
4+
Subject: [PATCH 2/5] Drop spurious 8 byte offset from elf_plt.
5+
6+
---
7+
rts/linker/elf_plt.c | 2 +-
8+
1 file changed, 1 insertion(+), 1 deletion(-)
9+
10+
diff --git a/rts/linker/elf_plt.c b/rts/linker/elf_plt.c
11+
index 9cd42ef..b5acb29 100644
12+
--- a/rts/linker/elf_plt.c
13+
+++ b/rts/linker/elf_plt.c
14+
@@ -56,7 +56,7 @@ makeStub(Section * section,
15+
s->target = *addr;
16+
s->flags = flags;
17+
s->next = NULL;
18+
- s->addr = (uint8_t *)section->info->stub_offset + 8
19+
+ s->addr = (uint8_t *)section->info->stub_offset
20+
+ STUB_SIZE * section->info->nstubs;
21+
22+
if((*_makeStub)(s))
23+
--
24+
2.33.0
25+

0 commit comments

Comments
 (0)