Skip to content

Commit 814577b

Browse files
committed
Fix alignment
1 parent d431278 commit 814577b

File tree

2 files changed

+103
-0
lines changed

2 files changed

+103
-0
lines changed

overlays/bootstrap.nix

+1
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ in {
282282
++ final.lib.optional (versionAtLeast "9.6.1" && versionLessThan"9.10" && (final.stdenv.targetPlatform != final.stdenv.hostPlatform)) ./patches/ghc/f8beb54a1d5725bd0d8a4b0a909d1b41d742b50b.patch
283283
++ 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
284284
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.9" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-linker-pool-allocator.patch
285+
++ final.lib.optional (versionAtLeast "9.6" && versionLessThan "9.9" && final.stdenv.targetPlatform.isMusl) ./patches/ghc/ghc-9.6-linker-pool-allocator-2.patch
285286
;
286287
in ({
287288
ghc865 = final.callPackage ../compiler/ghc (traceWarnOld "8.6" {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
diff --git a/rts/Linker.c b/rts/Linker.c
2+
index ad76b30..d5ea12e 100644
3+
--- a/rts/Linker.c
4+
+++ b/rts/Linker.c
5+
@@ -1832,6 +1832,8 @@ static HsInt resolveObjs_ (void)
6+
#endif
7+
8+
IF_DEBUG(linker, debugBelch("resolveObjs: done\n"));
9+
+ IF_DEBUG(linker, printPoolInfo());
10+
+
11+
return 1;
12+
}
13+
14+
diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h
15+
index 271611a..6cadaa8 100644
16+
--- a/rts/LinkerInternals.h
17+
+++ b/rts/LinkerInternals.h
18+
@@ -136,7 +136,8 @@ typedef
19+
enum { SECTION_NOMEM,
20+
SECTION_M32,
21+
SECTION_MMAP,
22+
- SECTION_MALLOC
23+
+ SECTION_MALLOC,
24+
+ SECTION_POOL
25+
}
26+
SectionAlloc;
27+
28+
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c
29+
index 4b5a506..fe3406e 100644
30+
--- a/rts/linker/Elf.c
31+
+++ b/rts/linker/Elf.c
32+
@@ -144,6 +144,18 @@ void memPoolProtect( void ) {
33+
}
34+
}
35+
36+
+StgWord poolAlign(StgWord size) {
37+
+ return (size + 0xff) & ~0xff;
38+
+}
39+
+
40+
+void * printPoolInfo( void ) {
41+
+ printf("Pool size: %ldM\n", ((uintptr_t)__pool_rx_offset - (uintptr_t)__pool_rw_offset)/(1024*1024));
42+
+ printf("RW: %p -- %p\n", __pool_rw_offset, (void*)((uintptr_t)__pool + 512*1024*1024));
43+
+ printf("RX: %p -- %p\n", (void*)((uintptr_t)__pool + 512*1024*1024), __pool_rx_offset);
44+
+ fflush(stdout);
45+
+ return NULL;
46+
+}
47+
+
48+
void * memPoolAlloc(SectionKind kind, StgWord size) {
49+
if(__pool == NULL) {
50+
// allocate 1 GB of virtual memory.
51+
@@ -157,7 +169,7 @@ void * memPoolAlloc(SectionKind kind, StgWord size) {
52+
__pool_rx_offset = __pool_rw_offset;
53+
}
54+
// align to 64 bytes
55+
- StgWord alignedSize = (size + 0x3f) & ~0x3f;
56+
+ StgWord alignedSize = poolAlign(size);
57+
void * ret = NULL;
58+
59+
if(kind == SECTIONKIND_CODE_OR_RODATA) {
60+
@@ -862,7 +874,7 @@ ocGetNames_ELF ( ObjectCode* oc )
61+
/* Use mmapForLinker to allocate .bss, otherwise the malloced
62+
* address might be out of range for sections that are mmaped.
63+
*/
64+
- alloc = SECTION_MMAP;
65+
+ alloc = SECTION_POOL;
66+
start = memPoolAlloc(kind, size);
67+
// mmapAnonForLinker(size);
68+
if (start == NULL) {
69+
@@ -871,7 +883,7 @@ ocGetNames_ELF ( ObjectCode* oc )
70+
}
71+
mapped_start = start;
72+
mapped_offset = 0;
73+
- mapped_size = roundUpToPage(size);
74+
+ mapped_size = poolAlign(size);
75+
}
76+
CHECK(start != 0x0);
77+
#else
78+
@@ -924,10 +936,10 @@ ocGetNames_ELF ( ObjectCode* oc )
79+
*/
80+
memcpy( mem, oc->image + offset, size );
81+
82+
- alloc = SECTION_MMAP;
83+
+ alloc = SECTION_POOL;
84+
85+
mapped_offset = 0;
86+
- mapped_size = roundUpToPage(size+stub_space);
87+
+ mapped_size = poolAlign(size+stub_space);
88+
start = mem;
89+
mapped_start = mem;
90+
#else
91+
diff --git a/rts/linker/Elf.h b/rts/linker/Elf.h
92+
index cf7a541..fb8fbfb 100644
93+
--- a/rts/linker/Elf.h
94+
+++ b/rts/linker/Elf.h
95+
@@ -17,5 +17,7 @@ int ocAllocateExtras_ELF ( ObjectCode *oc );
96+
void freeNativeCode_ELF ( ObjectCode *nc );
97+
void *loadNativeObj_ELF ( pathchar *path, char **errmsg );
98+
void memPoolProtect ( void );
99+
+void * printPoolInfo ( void );
100+
+StgWord poolAlign ( StgWord size );
101+
102+
#include "EndPrivate.h"

0 commit comments

Comments
 (0)