[Git][ghc/ghc][wip/win32-m32] rts/linker: Use m32 to allocate symbol extras in PEi386

Ben Gamari gitlab at gitlab.haskell.org
Mon Nov 23 20:36:06 UTC 2020



Ben Gamari pushed to branch wip/win32-m32 at Glasgow Haskell Compiler / GHC


Commits:
cc437472 by Ben Gamari at 2020-11-23T15:35:59-05:00
rts/linker: Use m32 to allocate symbol extras in PEi386

- - - - -


2 changed files:

- rts/LinkerInternals.h
- rts/linker/PEi386.c


Changes:

=====================================
rts/LinkerInternals.h
=====================================
@@ -149,7 +149,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
 


=====================================
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 )
 {
-    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;
 }



View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cc437472912dc7bce72db01964e6ca021cf0325c

-- 
View it on GitLab: https://gitlab.haskell.org/ghc/ghc/-/commit/cc437472912dc7bce72db01964e6ca021cf0325c
You're receiving this email because of your account on gitlab.haskell.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/ghc-commits/attachments/20201123/791f4e8b/attachment-0001.html>


More information about the ghc-commits mailing list