Fix loading of dlls on 32bit windows
authorSergey Vinokurov <serg.foo@gmail.com>
Sun, 20 Aug 2017 21:40:08 +0000 (00:40 +0300)
committerTamar Christina <tamar@zhox.com>
Mon, 21 Aug 2017 16:22:49 +0000 (17:22 +0100)
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

rts/linker/PEi386.c

index 42e7008..011b0a8 100644 (file)
@@ -240,6 +240,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);