|
| 1 | +diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c |
| 2 | +index 96b93ba..fca17ff 100644 |
| 3 | +--- a/rts/linker/Elf.c |
| 4 | ++++ b/rts/linker/Elf.c |
| 5 | +@@ -137,10 +137,12 @@ void * __pool = NULL; |
| 6 | + void * __pool_rw_offset = NULL; |
| 7 | + void * __pool_rx_offset = NULL; |
| 8 | + |
| 9 | ++#define POOL_SIZE 512 |
| 10 | ++ |
| 11 | + void memPoolProtect( void ) { |
| 12 | + if(__pool != NULL) { |
| 13 | +- mprotect(__pool, 256*1024*1024, PROT_READ | PROT_WRITE); |
| 14 | +- mprotect((void*)((uintptr_t)__pool + 256*1024*1024), 256*1024*1024, PROT_READ | PROT_WRITE | PROT_EXEC); |
| 15 | ++ mprotect(__pool, (POOL_SIZE>>2)*1024*1024, PROT_READ | PROT_WRITE); |
| 16 | ++ mprotect((void*)((uintptr_t)__pool + (POOL_SIZE>>2)*1024*1024), (POOL_SIZE-(POOL_SIZE>>2))*1024*1024, PROT_READ | PROT_WRITE | PROT_EXEC); |
| 17 | + } |
| 18 | + } |
| 19 | + |
| 20 | +@@ -150,8 +152,8 @@ StgWord poolAlign(StgWord align, StgWord size) { |
| 21 | + |
| 22 | + void * printPoolInfo( void ) { |
| 23 | + printf("Pool size: %ldM\n", ((uintptr_t)__pool_rx_offset - (uintptr_t)__pool_rw_offset)/(1024*1024)); |
| 24 | +- printf("RW: %p -- %p\n", __pool_rw_offset, (void*)((uintptr_t)__pool + 256*1024*1024)); |
| 25 | +- printf("RX: %p -- %p\n", (void*)((uintptr_t)__pool + 256*1024*1024), __pool_rx_offset); |
| 26 | ++ printf("RW: %p -- %p; %ldM\n", __pool_rw_offset, (void*)((uintptr_t)__pool + (POOL_SIZE>>2)*1024*1024), (((uintptr_t)__pool + (POOL_SIZE>>2)*1024*1024) - (uintptr_t)__pool_rw_offset)/(1024*1024)); |
| 27 | ++ printf("RX: %p -- %p; %ldM\n", (void*)((uintptr_t)__pool + (POOL_SIZE>>2)*1024*1024), __pool_rx_offset, ((uintptr_t)__pool_rx_offset - ((uintptr_t)__pool + (POOL_SIZE>>2)*1024*1024))/(1024*1024)); |
| 28 | + fflush(stdout); |
| 29 | + return NULL; |
| 30 | + } |
| 31 | +@@ -160,13 +162,13 @@ void * memPoolAlloc(SectionKind kind, StgWord align, StgWord size) { |
| 32 | + ASSERT(0x0 == (size & align)); |
| 33 | + if(__pool == NULL) { |
| 34 | + // allocate 1 GB of virtual memory. |
| 35 | +- __pool = mmapAnonForLinker(512*1024*1024); |
| 36 | ++ __pool = mmapAnonForLinker(POOL_SIZE*1024*1024); |
| 37 | + if(__pool == NULL) { |
| 38 | + printf("Failed to allocate memory pool\n"); |
| 39 | + fflush(stdout); |
| 40 | + return NULL; |
| 41 | + } |
| 42 | +- __pool_rw_offset = (void*)((uintptr_t)__pool + 256*1024*1024); |
| 43 | ++ __pool_rw_offset = (void*)((uintptr_t)__pool + (POOL_SIZE>>2)*1024*1024); |
| 44 | + __pool_rx_offset = __pool_rw_offset; |
| 45 | + } |
| 46 | + // align to 64 bytes |
| 47 | +@@ -177,8 +179,9 @@ void * memPoolAlloc(SectionKind kind, StgWord align, StgWord size) { |
| 48 | + ret = __pool_rx_offset; |
| 49 | + // printf("Allocated RX %p\n", ret); |
| 50 | + __pool_rx_offset = (void*)((uintptr_t)__pool_rx_offset + alignedSize); |
| 51 | +- if((uintptr_t)__pool_rx_offset > (uintptr_t)__pool + 512*1024*1024) { |
| 52 | +- printf("Out of memory pool\n"); |
| 53 | ++ if((uintptr_t)__pool_rx_offset > (uintptr_t)__pool + POOL_SIZE*1024*1024) { |
| 54 | ++ printf("Out of memory pool, for RX, trying to allocate %ld\n", alignedSize); |
| 55 | ++ printPoolInfo(); |
| 56 | + fflush(stdout); |
| 57 | + return NULL; |
| 58 | + } |
| 59 | +@@ -187,7 +190,8 @@ void * memPoolAlloc(SectionKind kind, StgWord align, StgWord size) { |
| 60 | + ret = __pool_rw_offset; |
| 61 | + // printf("Allocated RW %p\n", ret); |
| 62 | + if((uintptr_t)__pool_rw_offset < (uintptr_t)__pool) { |
| 63 | +- printf("Out of memory pool\n"); |
| 64 | ++ printf("Out of memory pool, for RW, trying to allocate %ld\n", alignedSize); |
| 65 | ++ printPoolInfo(); |
| 66 | + fflush(stdout); |
| 67 | + return NULL; |
| 68 | + } |
| 69 | +@@ -876,7 +880,7 @@ ocGetNames_ELF ( ObjectCode* oc ) |
| 70 | + * address might be out of range for sections that are mmaped. |
| 71 | + */ |
| 72 | + alloc = SECTION_POOL; |
| 73 | +- start = memPoolAlloc(kind, 0x3f, poolAlign(0x3f, size)); |
| 74 | ++ start = memPoolAlloc(kind, 0xf, poolAlign(0xf, size)); |
| 75 | + // mmapAnonForLinker(size); |
| 76 | + if (start == NULL) { |
| 77 | + barf("failed to mmap memory for bss. " |
| 78 | +@@ -884,7 +888,7 @@ ocGetNames_ELF ( ObjectCode* oc ) |
| 79 | + } |
| 80 | + mapped_start = start; |
| 81 | + mapped_offset = 0; |
| 82 | +- mapped_size = poolAlign(0x3f, size); |
| 83 | ++ mapped_size = poolAlign(0xf, size); |
| 84 | + } |
| 85 | + CHECK(start != 0x0); |
| 86 | + #else |
| 87 | +@@ -921,7 +925,7 @@ ocGetNames_ELF ( ObjectCode* oc ) |
| 88 | + * break up the section itself. |
| 89 | + */ |
| 90 | + unsigned stub_align = 0x7; |
| 91 | +- unsigned section_align = 0x3f; |
| 92 | ++ unsigned section_align = 0xf; |
| 93 | + |
| 94 | + unsigned nstubs = numberOfStubsForSection(oc, i); |
| 95 | + unsigned stub_space = poolAlign(stub_align, STUB_SIZE * nstubs); |
| 96 | +@@ -1035,7 +1039,7 @@ ocGetNames_ELF ( ObjectCode* oc ) |
| 97 | + void * common_mem = NULL; |
| 98 | + if(common_size > 0) { |
| 99 | + common_mem = // mmapAnonForLinker(common_size); |
| 100 | +- memPoolAlloc(SECTIONKIND_RWDATA, 0x3f, poolAlign(0x3f,common_size)); |
| 101 | ++ memPoolAlloc(SECTIONKIND_RWDATA, 0xf, poolAlign(0xf,common_size)); |
| 102 | + if (common_mem == NULL) { |
| 103 | + barf("ocGetNames_ELF: Failed to allocate memory for SHN_COMMONs"); |
| 104 | + } |
0 commit comments