From 41c64eb5db50c80e110e47b7ab1c1ee18dada46b Mon Sep 17 00:00:00 2001 From: Ben Gamari Date: Mon, 23 Nov 2020 15:20:39 -0500 Subject: rts/linker: Use m32 to allocate symbol extras in PEi386 --- rts/Linker.c | 5 +++-- rts/LinkerInternals.h | 2 +- rts/linker/M32Alloc.h | 2 +- rts/linker/PEi386.c | 44 +++++++++++++++----------------------------- 4 files changed, 20 insertions(+), 33 deletions(-) (limited to 'rts') diff --git a/rts/Linker.c b/rts/Linker.c index 57c76510d7..176127da24 100644 --- a/rts/Linker.c +++ b/rts/Linker.c @@ -1206,8 +1206,9 @@ void munmapForLinker (void *addr, size_t bytes, const char *caller) * Note that the m32 allocator handles protection of its allocations. For this * reason the caller to m32_alloc() must tell the allocator whether the * allocation needs to be executable. The caller must then ensure that they - * call m32_flush() after they are finished filling the region, which will - * cause the allocator to change the protection bits to PROT_READ|PROT_EXEC. + * call m32_allocator_flush() after they are finished filling the region, which + * will cause the allocator to change the protection bits to + * PROT_READ|PROT_EXEC. * */ diff --git a/rts/LinkerInternals.h b/rts/LinkerInternals.h index cf8017a12f..695f65dbdb 100644 --- a/rts/LinkerInternals.h +++ b/rts/LinkerInternals.h @@ -173,7 +173,7 @@ typedef struct _Segment { * We use the m32 allocator for symbol extras on Windows and other mmap-using * platforms. */ -#if RTS_LINKER_USE_MMAP +#if RTS_LINKER_USE_MMAP || defined(mingw32_HOST_ARCH) #define NEED_M32 1 #endif diff --git a/rts/linker/M32Alloc.h b/rts/linker/M32Alloc.h index 8a349a3b3e..331958614c 100644 --- a/rts/linker/M32Alloc.h +++ b/rts/linker/M32Alloc.h @@ -12,7 +12,7 @@ * We use the m32 allocator for symbol extras on Windows and other mmap-using * platforms. */ -#if RTS_LINKER_USE_MMAP +#if RTS_LINKER_USE_MMAP || defined(mingw32_HOST_OS) #define NEED_M32 1 #endif diff --git a/rts/linker/PEi386.c b/rts/linker/PEi386.c index b660ceba1f..917a641310 100644 --- a/rts/linker/PEi386.c +++ b/rts/linker/PEi386.c @@ -1788,42 +1788,28 @@ ocGetNames_PEi386 ( ObjectCode* oc ) bool ocAllocateExtras_PEi386 ( ObjectCode* oc ) { - /* If the ObjectCode was unloaded we don't need a trampoline, it's likely - an import library so we're discarding it earlier. */ - if (!oc->info) - return false; + /* If the ObjectCode was unloaded we don't need a trampoline, it's likely + an import library so we're discarding it earlier. */ + if (!oc->info) + return false; - const int mask = default_alignment - 1; - size_t origin = oc->info->trampoline; - oc->symbol_extras - = (SymbolExtra*)((uintptr_t)(oc->info->image + origin + mask) & ~mask); - oc->first_symbol_extra = 0; - COFF_HEADER_INFO *info = oc->info->ch_info; - oc->n_symbol_extras = info->numberOfSymbols; + // These are allocated on-demand from m32 by makeSymbolExtra_PEi386 + oc->first_symbol_extra = 0; + oc->n_symbol_extras = 0; + oc->symbol_extras = NULL; - return true; + return true; } static size_t -makeSymbolExtra_PEi386( ObjectCode* oc, uint64_t index, size_t s, char* symbol ) +makeSymbolExtra_PEi386( ObjectCode* oc, uint64_t index STG_UNUSED, size_t s, char* symbol STG_UNUSED ) { - unsigned int curr_thunk; - SymbolExtra *extra; - curr_thunk = oc->first_symbol_extra + index; - if (index >= oc->n_symbol_extras) { - IF_DEBUG(linker, debugBelch("makeSymbolExtra first:%d, num:%lu, member:%" PATH_FMT ", index:%llu\n", curr_thunk, oc->n_symbol_extras, oc->archiveMemberName, index)); - barf("Can't allocate thunk for `%s' in `%" PATH_FMT "' with member `%" PATH_FMT "'", symbol, oc->fileName, oc->archiveMemberName); - } - - extra = oc->symbol_extras + curr_thunk; + SymbolExtra *extra = m32_alloc(oc->rx_m32, sizeof(SymbolExtra), 8); - if (!extra->addr) - { - // jmp *-14(%rip) - static uint8_t jmp[] = { 0xFF, 0x25, 0xF2, 0xFF, 0xFF, 0xFF }; - extra->addr = (uint64_t)s; - memcpy(extra->jumpIsland, jmp, 6); - } + // jmp *-14(%rip) + static uint8_t jmp[] = { 0xFF, 0x25, 0xF2, 0xFF, 0xFF, 0xFF }; + extra->addr = (uint64_t)s; + memcpy(extra->jumpIsland, jmp, 6); return (size_t)extra->jumpIsland; } -- cgit v1.2.1