Fix loading of dlls on 32bit windows
authorSergey Vinokurov <serg.foo@gmail.com>
Sun, 20 Aug 2017 21:40:08 +0000 (00:40 +0300)
committerBen Gamari <ben@smart-cactus.org>
Tue, 22 Aug 2017 13:56:07 +0000 (09:56 -0400)
The point of fix is to handle case when loaded dll loads no
other dlls, i.e. it's import table is empty.

GHC Trac Issues: #14081

(cherry picked from commit 34bd43d9c24207a1897aaa4ee6cb70592a3f7acc)

rts/linker/PEi386.c

index c27dd31..bb10900 100644 (file)
@@ -156,6 +156,13 @@ static void addDLLHandle(pathchar* dll_name, HINSTANCE instance) {
         (PIMAGE_IMPORT_DESCRIPTOR)((BYTE *)instance + header->
         OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].VirtualAddress);
 
+    bool importTableMissing =
+        header->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_IMPORT].Size == 0;
+
+    if (importTableMissing) {
+        return;
+    }
+
     /* Ignore these compatibility shims.  */
     const pathchar* ms_dll = WSTR("api-ms-win-");
     const int len = wcslen(ms_dll);