summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2020-11-23 15:20:39 -0500
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-12-01 19:58:18 -0500
commit41c64eb5db50c80e110e47b7ab1c1ee18dada46b (patch)
tree1c9329cbe7ddaac22819854769ec8182b4089b7b
parentc35d0e03514ce111ff8265426a7b911456984f50 (diff)
downloadhaskell-41c64eb5db50c80e110e47b7ab1c1ee18dada46b.tar.gz
rts/linker: Use m32 to allocate symbol extras in PEi386
-rw-r--r--rts/Linker.c5
-rw-r--r--rts/LinkerInternals.h2
-rw-r--r--rts/linker/M32Alloc.h2
-rw-r--r--rts/linker/PEi386.c44
4 files changed, 20 insertions, 33 deletions
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;
}