summaryrefslogtreecommitdiff
path: root/rts/linker/SymbolExtras.c
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2019-10-28 13:37:39 -0400
committerBen Gamari <ben@smart-cactus.org>2019-10-30 21:47:05 -0400
commit4ac51fb9d7ac9120adee88aeb510973d47017e93 (patch)
treee7468d5861aefcab85fc0dfd2119f3be6a0f9d6d /rts/linker/SymbolExtras.c
parent5f7b29694f4658519f09cbfcaafcadce6a0a1cc7 (diff)
downloadhaskell-wip/linker-per-oc-m32.tar.gz
rts: Make m32 allocator per-ObjectCodewip/linker-per-oc-m32
MacOS Catalina is finally going to force our hand in forbidden writable exeutable mappings. Unfortunately, this is quite incompatible with the current global m32 allocator, which mixes symbols from various objects in a single page. The problem here is that some of these symbols may not yet be resolved (e.g. had relocations performed) as this happens lazily (and therefore we can't yet make the section read-only and therefore executable). The easiest way around this is to simply create one m32 allocator per ObjectCode. This may slightly increase fragmentation for short-running programs but I suspect will actually improve fragmentation for programs doing lots of loading/unloading since we can always free all of the pages allocated to an object when it is unloaded (although this ability will only be implemented in a later patch).
Diffstat (limited to 'rts/linker/SymbolExtras.c')
-rw-r--r--rts/linker/SymbolExtras.c9
1 files changed, 5 insertions, 4 deletions
diff --git a/rts/linker/SymbolExtras.c b/rts/linker/SymbolExtras.c
index 4149522ba0..04a678898f 100644
--- a/rts/linker/SymbolExtras.c
+++ b/rts/linker/SymbolExtras.c
@@ -53,6 +53,7 @@
int ocAllocateExtras(ObjectCode* oc, int count, int first, int bssSize)
{
void* oldImage = oc->image;
+ const size_t extras_size = sizeof(SymbolExtra) * count;
if (count > 0 || bssSize > 0) {
if (!RTS_LINKER_USE_MMAP) {
@@ -64,7 +65,7 @@ int ocAllocateExtras(ObjectCode* oc, int count, int first, int bssSize)
oc->image -= misalignment;
oc->image = stgReallocBytes( oc->image,
misalignment +
- aligned + sizeof (SymbolExtra) * count,
+ aligned + extras_size,
"ocAllocateExtras" );
oc->image += misalignment;
@@ -73,7 +74,7 @@ int ocAllocateExtras(ObjectCode* oc, int count, int first, int bssSize)
/* Keep image, bssExtras and symbol_extras contiguous */
size_t n = roundUpToPage(oc->fileSize);
bssSize = roundUpToAlign(bssSize, 8);
- size_t allocated_size = n + bssSize + (sizeof(SymbolExtra) * count);
+ size_t allocated_size = n + bssSize + extras_size;
void *new = mmapForLinker(allocated_size, MAP_ANONYMOUS, -1, 0);
if (new) {
memcpy(new, oc->image, oc->fileSize);
@@ -92,13 +93,13 @@ int ocAllocateExtras(ObjectCode* oc, int count, int first, int bssSize)
return 0;
}
} else {
- oc->symbol_extras = m32_alloc(sizeof(SymbolExtra) * count, 8);
+ oc->symbol_extras = m32_alloc(oc->m32, extras_size, 8);
if (oc->symbol_extras == NULL) return 0;
}
}
if (oc->symbol_extras != NULL) {
- memset( oc->symbol_extras, 0, sizeof (SymbolExtra) * count );
+ memset( oc->symbol_extras, 0, extras_size );
}
// ObjectCodeFormatInfo contains computed addresses based on offset to